[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Test that we install all modules



commit ff6afbc7732ef321b261d649c470838d472a1e8f
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Thu Nov 3 19:11:20 2016 -0700

    Test that we install all modules
    
    I've screwed up on this enough times that we might as well have a test
    for it. :P
---
 test/integ/installation.py | 15 +++++++--------
 test/settings.cfg          |  1 +
 test/unit/installation.py  | 47 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 55 insertions(+), 8 deletions(-)

diff --git a/test/integ/installation.py b/test/integ/installation.py
index 50c0339..007b911 100644
--- a/test/integ/installation.py
+++ b/test/integ/installation.py
@@ -8,8 +8,7 @@ import stem
 import stem.util.system
 
 import test.runner
-
-BASE_DIRECTORY = os.path.sep.join(__file__.split(os.path.sep)[:-3])
+import test.util
 
 
 class TestInstallation(unittest.TestCase):
@@ -22,13 +21,13 @@ class TestInstallation(unittest.TestCase):
     self.skip_reason = None
     self.installation_error = None
 
-    if not os.path.exists(os.path.join(BASE_DIRECTORY, 'setup.py')):
+    if not os.path.exists(os.path.join(test.util.STEM_BASE, 'setup.py')):
       self.skip_reason = '(only for git checkout)'
 
     original_cwd = os.getcwd()
 
     try:
-      os.chdir(BASE_DIRECTORY)
+      os.chdir(test.util.STEM_BASE)
       stem.util.system.call(sys.executable + ' setup.py install --prefix /tmp/stem_test')
       stem.util.system.call(sys.executable + ' setup.py clean --all')  # tidy up the build directory
       site_packages_paths = glob.glob('/tmp/stem_test/lib*/*/site-packages')
@@ -79,12 +78,12 @@ class TestInstallation(unittest.TestCase):
 
     expected, installed = set(), set()
 
-    for root, dirnames, filenames in os.walk(os.path.join(BASE_DIRECTORY, 'stem')):
+    for root, dirnames, filenames in os.walk(os.path.join(test.util.STEM_BASE, 'stem')):
       for filename in filenames:
-          file_format = filename.split('.')[-1]
+        file_format = filename.split('.')[-1]
 
-          if file_format not in ('pyc', 'swp', 'swo'):
-            expected.add(os.path.join(root, filename)[len(BASE_DIRECTORY) + 1:])
+        if file_format not in ('pyc', 'swp', 'swo'):
+          expected.add(os.path.join(root, filename)[len(test.util.STEM_BASE) + 1:])
 
     for root, dirnames, filenames in os.walk(self.site_packages_path):
       for filename in filenames:
diff --git a/test/settings.cfg b/test/settings.cfg
index 4579f09..e5174d2 100644
--- a/test/settings.cfg
+++ b/test/settings.cfg
@@ -170,6 +170,7 @@ test.unit_tests
 |test.unit.util.term.TestTerminal
 |test.unit.util.tor_tools.TestTorTools
 |test.unit.util.__init__.TestBaseUtil
+|test.unit.installation.TestInstallation
 |test.unit.descriptor.export.TestExport
 |test.unit.descriptor.reader.TestDescriptorReader
 |test.unit.descriptor.remote.TestDescriptorDownloader
diff --git a/test/unit/installation.py b/test/unit/installation.py
new file mode 100644
index 0000000..6d36b7e
--- /dev/null
+++ b/test/unit/installation.py
@@ -0,0 +1,47 @@
+import os
+import re
+import unittest
+
+import test.runner
+import test.util
+
+
+class TestInstallation(unittest.TestCase):
+  # TODO: remove when dropping support for python 2.6
+  skip_reason = 'setUpClass() unsupported in python 2.6'
+
+  @classmethod
+  def setUpClass(self):
+    setup_path = os.path.join(test.util.STEM_BASE, 'setup.py')
+    self.skip_reason = None
+    self.setup_contents = False
+
+    if os.path.exists(setup_path):
+      with open(setup_path) as setup_file:
+        self.setup_contents = setup_file.read()
+    else:
+      self.skip_reason = '(only for git checkout)'
+
+  def test_installation_has_all_modules(self):
+    if self.skip_reason:
+      test.runner.skip(self, self.skip_reason)
+      return True
+
+    # Modules cited my our setup.py looks like...
+    #
+    #   packages = ['stem', 'stem.descriptor', 'stem.util'],
+
+    modules = re.search('packages = \[(.*)\]', self.setup_contents).group(1).replace("'", '').replace(',', '').split()
+    module_paths = dict([(m, os.path.join(test.util.STEM_BASE, m.replace('.', os.path.sep))) for m in modules])
+
+    for module, path in module_paths.items():
+      if not os.path.exists(path):
+        self.fail("module %s from our setup.py doesn't exit at %s" % (module, path))
+
+    for entry in os.walk(os.path.join(test.util.STEM_BASE, 'stem')):
+      path = entry[0]
+
+      if path.endswith('__pycache__'):
+        continue
+      elif path not in module_paths.values():
+        self.fail("%s isn't installed by our setup.py" % path)



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits