Esempio n. 1
0
    def setUp(self):
        super(FakeDistsMixin, self).setUp()
        self.addCleanup(enable_cache)
        disable_cache()

        # make a copy that we can write into for our fake installed
        # distributions
        tmpdir = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, tmpdir)
        self.fake_dists_path = os.path.realpath(
            os.path.join(tmpdir, 'fake_dists'))
        fake_dists_src = os.path.abspath(
            os.path.join(os.path.dirname(__file__), 'fake_dists'))
        shutil.copytree(fake_dists_src, self.fake_dists_path)
        # XXX ugly workaround: revert copystat calls done by shutil behind our
        # back (to avoid getting a read-only copy of a read-only file).  we
        # could pass a custom copy_function to change the mode of files, but
        # shutil gives no control over the mode of directories :(
        # see http://bugs.python.org/issue1666318
        for root, dirs, files in os.walk(self.fake_dists_path):
            os.chmod(root, 0o755)
            for f in files:
                os.chmod(os.path.join(root, f), 0o644)
            for d in dirs:
                os.chmod(os.path.join(root, d), 0o755)
Esempio n. 2
0
 def setUp(self):
     super(DepGraphTestCase, self).setUp()
     path = os.path.join(os.path.dirname(__file__), 'fake_dists')
     path = os.path.abspath(path)
     sys.path.insert(0, path)
     self.addCleanup(sys.path.remove, path)
     self.addCleanup(enable_cache)
     disable_cache()
Esempio n. 3
0
 def setUp(self):
     super(DepGraphTestCase, self).setUp()
     path = os.path.join(os.path.dirname(__file__), 'fake_dists')
     path = os.path.abspath(path)
     sys.path.insert(0, path)
     self.addCleanup(sys.path.remove, path)
     self.addCleanup(enable_cache)
     disable_cache()
Esempio n. 4
0
    def test_get_file(self):
        # Create a fake dist
        temp_site_packages = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, temp_site_packages)

        dist_name = 'test'
        dist_info = os.path.join(temp_site_packages, 'test-0.1.dist-info')
        os.mkdir(dist_info)

        metadata_path = os.path.join(dist_info, 'METADATA')
        resources_path = os.path.join(dist_info, 'RESOURCES')

        with open(metadata_path, 'w') as fp:
            fp.write(
                dedent("""\
                Metadata-Version: 1.2
                Name: test
                Version: 0.1
                Summary: test
                Author: me
                """))

        test_path = 'test.cfg'

        fd, test_resource_path = tempfile.mkstemp()
        os.close(fd)
        self.addCleanup(os.remove, test_resource_path)

        with open(test_resource_path, 'w') as fp:
            fp.write('Config')

        with open(resources_path, 'w') as fp:
            fp.write('%s,%s' % (test_path, test_resource_path))

        # Add fake site-packages to sys.path to retrieve fake dist
        self.addCleanup(sys.path.remove, temp_site_packages)
        sys.path.insert(0, temp_site_packages)

        # Force distutils2.database to rescan the sys.path
        self.addCleanup(enable_cache)
        disable_cache()

        # Try to retrieve resources paths and files
        self.assertEqual(get_file_path(dist_name, test_path),
                         test_resource_path)
        self.assertRaises(KeyError, get_file_path, dist_name, 'i-dont-exist')

        with get_file(dist_name, test_path) as fp:
            self.assertEqual(fp.read(), 'Config')
        self.assertRaises(KeyError, get_file, dist_name, 'i-dont-exist')
Esempio n. 5
0
 def setUp(self):
     super(UninstallTestCase, self).setUp()
     self.addCleanup(enable_cache)
     self.addCleanup(distutils2.util._path_created.clear)
     disable_cache()
Esempio n. 6
0
 def setUp(self):
     super(UninstallTestCase, self).setUp()
     self.addCleanup(enable_cache)
     self.addCleanup(distutils2.util._path_created.clear)
     disable_cache()