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

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



commit b4faa8230304a331babf9cd539121ce57096087c
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sat Nov 28 17:54:30 2015 -0800

    Test that we install all files
    
    Few times now we've had bugs (and even releases!) where installation misses
    files. This is because in our setup.py we need to enumerate all modules and
    non-source files. This is damn easy to forget.
    
    Renaming stem/settings.cfg hit this again so adding a test to ensure it stops
    happening in the future.
---
 setup.py                   |    2 +-
 test/integ/installation.py |   78 +++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 70 insertions(+), 10 deletions(-)

diff --git a/setup.py b/setup.py
index 002e982..8fb47e6 100644
--- a/setup.py
+++ b/setup.py
@@ -17,6 +17,6 @@ distutils.core.setup(
   packages = ['stem', 'stem.descriptor', 'stem.interpreter', 'stem.response', 'stem.util'],
   keywords = 'tor onion controller',
   scripts = ['tor-prompt'],
-  package_data = {'stem': ['manual.cfg'], 'stem.interpreter': ['settings.cfg'], 'stem.util': ['ports.cfg']},
+  package_data = {'stem': ['settings.cfg'], 'stem.interpreter': ['settings.cfg'], 'stem.util': ['ports.cfg']},
 )
 
diff --git a/test/integ/installation.py b/test/integ/installation.py
index 70a8ad9..6b0f759 100644
--- a/test/integ/installation.py
+++ b/test/integ/installation.py
@@ -9,27 +9,87 @@ import stem.util.system
 
 import test.runner
 
+BASE_DIRECTORY = os.path.sep.join(__file__.split(os.path.sep)[:-3])
+
 
 class TestInstallation(unittest.TestCase):
-  @test.runner.only_run_once
-  def test_installing_stem(self):
-    base_directory = os.path.sep.join(__file__.split(os.path.sep)[:-3])
+  @classmethod
+  def setUpClass(self):
+    self.site_packages_path = None
+    self.skip_reason = None
+    self.installation_error = None
 
-    if not os.path.exists(os.path.sep.join([base_directory, 'setup.py'])):
-      test.runner.skip(self, '(only for git checkout)')
+    if not os.path.exists(os.path.join(BASE_DIRECTORY, 'setup.py')):
+      self.skip_reason = '(only for git checkout)'
 
     original_cwd = os.getcwd()
 
     try:
-      os.chdir(base_directory)
+      os.chdir(BASE_DIRECTORY)
       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')
 
       if len(site_packages_paths) != 1:
-        self.fail('We should only have a single site-packages directory, but instead had: %s' % site_packages_paths)
+        self.installation_error = 'We should only have a single site-packages directory, but instead had: %s' % site_packages_paths
 
-      self.assertEqual(stem.__version__, stem.util.system.call([sys.executable, '-c', "import sys;sys.path.insert(0, '%s');import stem;print(stem.__version__)" % site_packages_paths[0]])[0])
+      self.site_packages_path = site_packages_paths[0]
+    except Exception as exc:
+      self.installation_error = 'Unable to download the man page: %s' % exc
     finally:
-      shutil.rmtree('/tmp/stem_test')
       os.chdir(original_cwd)
+
+  @classmethod
+  def tearDownClass(self):
+    if os.path.exists('/tmp/stem_test'):
+      shutil.rmtree('/tmp/stem_test')
+
+  def requires_installation(self):
+    if self.skip_reason:
+      test.runner.skip(self, self.skip_reason)
+      return True
+    elif self.installation_error:
+      self.fail(self.installation_error)
+
+    return False
+
+  @test.runner.only_run_once
+  def test_installing_stem(self):
+    """
+    Attempt to use the package we install.
+    """
+
+    if self.requires_installation():
+      return
+
+    self.assertEqual(stem.__version__, stem.util.system.call([sys.executable, '-c', "import sys;sys.path.insert(0, '%s');import stem;print(stem.__version__)" % self.site_packages_path])[0])
+
+  def test_installs_all_files(self):
+    """
+    Check that all the files in the stem directory are present in the
+    installatnion. This is a very common gotcha since our setup.py
+    requires us to remember to add new modules and non-source files.
+    """
+
+    if self.requires_installation():
+      return
+
+    expected, installed = set(), set()
+
+    for root, dirnames, filenames in os.walk(os.path.join(BASE_DIRECTORY, 'stem')):
+      for filename in filenames:
+        if not filename.endswith('.pyc'):
+          expected.add(os.path.join(root, filename)[len(BASE_DIRECTORY) + 1:])
+
+    for root, dirnames, filenames in os.walk(self.site_packages_path):
+      for filename in filenames:
+        if not filename.endswith('.pyc') and not filename.endswith('egg-info'):
+          installed.add(os.path.join(root, filename)[len(self.site_packages_path) + 1:])
+
+    missing = expected.difference(installed)
+    extra = installed.difference(expected)
+
+    if missing:
+      self.fail("The following files were expected to be in our installation but weren't. Maybe our setup.py needs to be updated?\n\n%s" % '\n'.join(missing))
+    elif extra:
+      self.fail("The following files weren't expected to be in our installation.\n\n%s" % '\n'.join(extra))



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