Tarek Ziadé avatar Tarek Ziadé committed 6c3d67e

fix pysetup tests

Comments (0)

Files changed (3)

distutils2/command/build_py.py

         self.check_package(package, package_dir)
         module_files = glob(os.path.join(package_dir, "*.py"))
         modules = []
-        setup_script = os.path.abspath(self.distribution.script_name)
+        if self.distribution.script_name is not None:
+            setup_script = os.path.abspath(self.distribution.script_name)
+        else:
+            setup_script = None
 
         for f in module_files:
             abs_f = os.path.abspath(f)

distutils2/tests/test_config.py

 import os
 import sys
 from StringIO import StringIO
+import tempfile
+import shutil
 
 from distutils2.tests import unittest, support, run_unittest
 from distutils2.command.sdist import sdist
         super(ConfigTestCase, self).setUp()
         self.addCleanup(setattr, sys, 'stdout', sys.stdout)
         self.addCleanup(setattr, sys, 'stderr', sys.stderr)
-        sys.stdout = sys.stderr = StringIO()
+        #sys.stdout = sys.stderr = StringIO()
 
         self.addCleanup(os.chdir, os.getcwd())
         tempdir = self.mkdtemp()
 
     def run_setup(self, *args):
         # run setup with args
-        args = ['', 'run'] + list(args)
+        args = ['run'] + list(args)
         from distutils2.run import main
         dist = main(args)
         return dist
 
+    def _get_metadata(self, name='version'):
+        from distutils2.dist import Distribution
+        dist = Distribution()
+        dist.parse_config_files()
+        return dist, dist.metadata[name]
+
     def test_config(self):
         self.write_setup()
         self.write_file('README', 'yeah')
         self.write_file('init_script', '')
 
         # try to load the metadata now
-        dist = self.run_setup('--version')
+        dist, version = self._get_metadata()
 
         # sanity check
-        self.assertEqual(sys.stdout.getvalue(), '0.6.4.dev1' + os.linesep)
+        self.assertEqual(version, '0.6.4.dev1')
 
         # check what was done
         self.assertEqual(dist.metadata['Author'], 'Carl Meyer')
         self.write_setup({'description-file': 'README  CHANGES'})
         self.write_file('README', 'yeah')
         self.write_file('CHANGES', 'changelog2')
-        dist = self.run_setup('--version')
+        dist, version = self._get_metadata()
         self.assertEqual(dist.metadata.requires_files, ['README', 'CHANGES'])
 
     def test_multiline_description_file(self):
         self.write_setup({'description-file': 'README\n  CHANGES'})
         self.write_file('README', 'yeah')
         self.write_file('CHANGES', 'changelog')
-        dist = self.run_setup('--version')
-        self.assertEqual(dist.metadata['description'], 'yeah\nchangelog')
+        dist, desc = self._get_metadata('description')
+        self.assertEqual(desc, 'yeah\nchangelog')
         self.assertEqual(dist.metadata.requires_files, ['README', 'CHANGES'])
 
     def test_parse_extensions_in_config(self):
         self.write_file('setup.cfg', EXT_SETUP_CFG)
-        dist = self.run_setup('--version')
-
+        dist, version = self._get_metadata()
         ext_modules = dict((mod.name, mod) for mod in dist.ext_modules)
         self.assertEqual(len(ext_modules), 2)
         ext = ext_modules.get('one.speed_coconuts')
             os.mkdir(pkg)
             self.write_file(os.path.join(pkg, '__init__.py'), '#')
 
-        dist = self.run_setup('--version')
+        dist, version = self._get_metadata()
         cmd = sdist(dist)
         cmd.finalize_options()
         cmd.get_file_list()
             os.mkdir(pkg)
             self.write_file(os.path.join(pkg, '__init__.py'), '#')
 
-        dist = self.run_setup('--description')
-        self.assertIn('yeah\nyeah\n', sys.stdout.getvalue())
+        dist, desc = self._get_metadata('description')
+        self.assertIn('yeah\nyeah', desc)
 
         cmd = sdist(dist)
         cmd.finalize_options()
 
         self.write_setup({'description-file': 'README\n  README2',
                           'extra-files': '\n  README2\n    README'})
-        dist = self.run_setup('--description')
+        dist, desc = self._get_metadata('description')
+
         cmd = sdist(dist)
         cmd.finalize_options()
         cmd.get_file_list()
             self.write_file(os.path.join(pkg, '__init__.py'), '#')
 
         # try to run the install command to see if foo is called
-        dist = self.run_setup('install_dist')
+        tmpdir = tempfile.mkdtemp()
+        try:
+            dist = self.run_setup('install_dist', '--root=%s' % tmpdir)
+        finally:
+            shutil.rmtree(tmpdir)
 
         self.assertEqual(dist.foo_was_here, 1)
 

distutils2/tests/test_uninstall.py

 
     def run_setup(self, *args):
         # run setup with args
-        args = ['', 'run'] + list(args)
+        args = ['run'] + list(args)
         from distutils2.run import main
         dist = main(args)
         return dist
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.