[diffoscope] 04/05: Provide a cleaner and more explicit solution to modifying the path to include /usr/sbin etc.

Chris Lamb chris at chris-lamb.co.uk
Tue Mar 28 21:40:19 CEST 2017


This is an automated email from the git hooks/post-receive script.

lamby pushed a commit to branch experimental
in repository diffoscope.

commit ea66004490cbb2a5d1f919bd54f76e893bb4fbfa
Author: Chris Lamb <lamby at debian.org>
Date:   Tue Mar 28 20:35:38 2017 +0100

    Provide a cleaner and more explicit solution to modifying the path to include /usr/sbin etc.
    
    Signed-off-by: Chris Lamb <lamby at debian.org>
---
 diffoscope/main.py                      |  3 +++
 tests/conftest.py => diffoscope/path.py | 24 ++++++++----------------
 diffoscope/tools.py                     | 11 +----------
 tests/conftest.py                       |  4 ++++
 4 files changed, 16 insertions(+), 26 deletions(-)

diff --git a/diffoscope/main.py b/diffoscope/main.py
index 4ed97d3..9de4926 100644
--- a/diffoscope/main.py
+++ b/diffoscope/main.py
@@ -5,6 +5,7 @@
 # diffoscope: in-depth comparison of files, archives, and directories
 #
 # Copyright © 2014-2015 Jérémy Bobbio <lunar at debian.org>
+# Copyright © 2017 Chris Lamb <lamby at debian.org>
 #
 # diffoscope is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -27,6 +28,7 @@ import argparse
 import traceback
 
 from . import VERSION
+from .path import set_path
 from .tools import tool_required, OS_NAMES, get_current_os
 from .config import Config
 from .locale import set_locale
@@ -252,6 +254,7 @@ def run_diffoscope(parsed_args):
     Config().fuzzy_threshold = parsed_args.fuzzy_threshold
     Config().new_file = parsed_args.new_file
     Config().excludes = parsed_args.excludes
+    set_path()
     set_locale()
     logger.debug('Starting comparison')
     ProgressManager().setup(parsed_args)
diff --git a/tests/conftest.py b/diffoscope/path.py
similarity index 55%
copy from tests/conftest.py
copy to diffoscope/path.py
index 063b2d9..cf2cc2b 100644
--- a/tests/conftest.py
+++ b/diffoscope/path.py
@@ -2,7 +2,7 @@
 #
 # diffoscope: in-depth comparison of files, archives, and directories
 #
-# Copyright © 2016 Brett Smith <debbug at brettcsmith.org>
+# Copyright © 2017 Chris Lamb <lamby at debian.org>
 #
 # diffoscope is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -17,22 +17,14 @@
 # You should have received a copy of the GNU General Public License
 # along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
 
-import pytest
+import os
 
-from diffoscope.locale import set_locale
-from diffoscope.progress import ProgressManager
-from diffoscope.comparators import ComparatorManager
 
+def set_path():
+    pathlist = os.environ['PATH'].split(os.pathsep)
 
-# Ensure set_locale fixture runs before each test.
-set_locale = pytest.fixture(autouse=True, scope='session')(set_locale)
+    for x in ('/sbin', '/usr/sbin', '/usr/local/sbin'):
+        if x not in pathlist:
+            pathlist.append(x)
 
- at pytest.fixture(autouse=True)
-def reload_comparators():
-    # Reload Comparators after every test so we are always in a consistent
-    # state
-    ComparatorManager().reload()
-
- at pytest.fixture(autouse=True)
-def reset_progress():
-    ProgressManager().reset()
+    os.environ['PATH'] = os.pathsep.join(pathlist)
diff --git a/diffoscope/tools.py b/diffoscope/tools.py
index 66a11d3..15d7a60 100644
--- a/diffoscope/tools.py
+++ b/diffoscope/tools.py
@@ -2,7 +2,7 @@
 #
 # diffoscope: in-depth comparison of files, archives, and directories
 #
-# Copyright © 2016 Chris Lamb <lamby at debian.org>
+# Copyright © 2016, 2017 Chris Lamb <lamby at debian.org>
 #
 # diffoscope is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -38,15 +38,6 @@ OS_NAMES = collections.OrderedDict([
     ('FreeBSD', 'FreeBSD'),
 ])
 
-# Ensure tests and the runtime environment can locate binaries in /usr/sbin
-# (eg. tcpdump). We must modify the path before the @tool_required decorator is
-# applied.
-pathlist = os.environ['PATH'].split(os.pathsep)
-for x in ('/sbin', '/usr/sbin', '/usr/local/sbin'):
-    if x not in pathlist:
-        pathlist.append(x)
-os.environ['PATH'] = os.pathsep.join(pathlist)
-
 
 def tool_required(command):
     """
diff --git a/tests/conftest.py b/tests/conftest.py
index 063b2d9..d696edb 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -3,6 +3,7 @@
 # diffoscope: in-depth comparison of files, archives, and directories
 #
 # Copyright © 2016 Brett Smith <debbug at brettcsmith.org>
+# Copyright © 2017 Chris Lamb <lamby at debian.org>
 #
 # diffoscope is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -19,10 +20,13 @@
 
 import pytest
 
+from diffoscope.path import set_path
 from diffoscope.locale import set_locale
 from diffoscope.progress import ProgressManager
 from diffoscope.comparators import ComparatorManager
 
+# Ensure set_path fixture runs before all tests.
+set_path()
 
 # Ensure set_locale fixture runs before each test.
 set_locale = pytest.fixture(autouse=True, scope='session')(set_locale)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list