Beispiel #1
0
    def test_setup(self):
        old_sys_path = sys.path
        mock_sys_path = list(sys.path)
        sys.path = mock_sys_path
        # `import pip` can cause arbitrary sys.path changes,
        # especially if using the Debian `python-pip` package or
        # similar.  Do it first to get those changes out of the
        # way.
        try:
            import pip  # noqa
        except ImportError:
            pass
        finally:
            sys.path = old_sys_path

        # Run setup()
        old_sys_path = sys.path
        try:
            mock_sys_path = list(sys.path)
            sys.path = mock_sys_path
            support.setup(import_roots=['some_root', 'another_root'])
        finally:
            sys.path = old_sys_path

        # Check results
        self.assertTrue(mock_sys_path[1].endswith('subpar/runtime/some_root'),
                        mock_sys_path)
        self.assertTrue(
            mock_sys_path[2].endswith('subpar/runtime/another_root'),
            mock_sys_path)
        self.assertEqual(mock_sys_path[0], sys.path[0])
        self.assertEqual(mock_sys_path[3:], sys.path[1:])
Beispiel #2
0
    def test_setup(self):
        # Run setup() without file extraction
        old_sys_path = sys.path
        try:
            mock_sys_path = list(sys.path)
            mock_sys_path[0] = self.zipfile_name
            sys.path = mock_sys_path
            success = support.setup(import_roots=['some_root', 'another_root'],
                                    zip_safe=True)
            self.assertTrue(success)
        finally:
            sys.path = old_sys_path

        # Check results
        self.assertTrue(
            mock_sys_path[1].endswith('some_root'),
            mock_sys_path)
        self.assertTrue(
            mock_sys_path[2].endswith('another_root'),
            mock_sys_path)
        # If we have no pkg_resources, or a really old version of
        # pkg_resources, setup skips some things
        module = sys.modules.get('pkg_resources', None)
        if module and support._version_check_pkg_resources(module):
            self.assertEqual(mock_sys_path[3:], sys.path[1:])
Beispiel #3
0
    def test_setup(self):
        # Run setup() without file extraction
        old_sys_path = sys.path
        try:
            mock_sys_path = list(sys.path)
            mock_sys_path[0] = self.zipfile_name
            sys.path = mock_sys_path
            success = support.setup(import_roots=['some_root', 'another_root'],
                                    zip_safe=True)
            self.assertTrue(success)
        finally:
            sys.path = old_sys_path

        # Check results
        self.assertTrue(
            mock_sys_path[1].endswith('some_root'),
            mock_sys_path)
        self.assertTrue(
            mock_sys_path[2].endswith('another_root'),
            mock_sys_path)
        # If we have no pkg_resources, or a really old version of
        # pkg_resources, setup skips some things
        module = sys.modules.get('pkg_resources', None)
        if module and support._version_check_pkg_resources(module):
            self.assertEqual(mock_sys_path[3:], sys.path[1:])
Beispiel #4
0
    def test_setup(self):
        # mock out finding the archive to some other archive
        archive_path = self._make_archive(
            ['some_root/main.py', 'another_root/main.py'])

        def mock_find_archive():
            return archive_path

        old_find_archive = support._find_archive
        support._find_archive = mock_find_archive

        # mock out sys path
        old_sys_path = sys.path
        mock_sys_path = list(sys.path)
        sys.path = mock_sys_path

        # `import pip` can cause arbitrary sys.path changes,
        # especially if using the Debian `python-pip` package or
        # similar.  Do it first to get those changes out of the
        # way.
        try:
            import pip  # noqa
        except ImportError:
            pass
        finally:
            sys.path = old_sys_path

        # Run setup()
        old_sys_path = sys.path
        try:
            mock_sys_path = list(sys.path)
            sys.path = mock_sys_path
            support.setup(import_roots=['some_root', 'another_root'])
        finally:
            support._find_archive = old_find_archive
            sys.path = old_sys_path

        # Check results
        self.assertTrue(
            mock_sys_path[1].endswith('{}/some_root'.format(archive_path)),
            mock_sys_path)
        self.assertTrue(
            mock_sys_path[2].endswith('{}/another_root'.format(archive_path)),
            mock_sys_path)
        self.assertEqual(mock_sys_path[0], sys.path[0])
        self.assertEqual(mock_sys_path[3:], sys.path[1:])
Beispiel #5
0
    def test_setup__extract(self):
        # Run setup() with file extraction
        old_sys_path = sys.path
        try:
            mock_sys_path = list(sys.path)
            mock_sys_path[0] = self.zipfile_name
            sys.path = mock_sys_path
            success = support.setup(import_roots=['some_root'], zip_safe=False)
            self.assertTrue(success)
        finally:
            sys.path = old_sys_path

        # Check results
        self.assertNotEqual(mock_sys_path[0], self.zipfile_name)
        self.assertTrue(os.path.isdir(mock_sys_path[0]), mock_sys_path)
Beispiel #6
0
    def test_setup__extract(self):
        # Run setup() with file extraction
        old_sys_path = sys.path
        try:
            mock_sys_path = list(sys.path)
            mock_sys_path[0] = self.zipfile_name
            sys.path = mock_sys_path
            success = support.setup(import_roots=['some_root'], zip_safe=False)
            self.assertTrue(success)
        finally:
            sys.path = old_sys_path

        # Check results
        self.assertNotEqual(mock_sys_path[0], self.zipfile_name)
        self.assertTrue(
            os.path.isdir(mock_sys_path[0]),
            mock_sys_path)
Beispiel #7
0
 def test_setup(self):
     support.setup(import_roots=['some_root', 'another_root'])
     self.assertTrue(sys.path[1].endswith('subpar/runtime/some_root'), sys.path)
     self.assertTrue(sys.path[2].endswith('subpar/runtime/another_root'), sys.path)
Beispiel #8
0
    def test_setup_with_shared_objects(self):
        # mock out finding the archive to some other archive
        archive_path = self._make_archive(
            ['some_root/main.py', 'some_root/file.so', 'another_root/main.py'])

        def mock_find_archive():
            return archive_path

        old_find_archive = support._find_archive
        support._find_archive = mock_find_archive

        # mock out creating a tmp dir to a predictable tmp dir
        tempdir = tempfile.mkdtemp()

        def mock_mkdtemp():
            return tempdir

        old_mkdtemp = tempfile.mkdtemp
        tempfile.mkdtemp = mock_mkdtemp

        # mock out the sys path
        old_sys_path = sys.path
        mock_sys_path = list(sys.path)
        sys.path = mock_sys_path

        # `import pip` can cause arbitrary sys.path changes,
        # especially if using the Debian `python-pip` package or
        # similar.  Do it first to get those changes out of the
        # way.
        try:
            import pip  # noqa
        except ImportError:
            pass
        finally:
            sys.path = old_sys_path

        # Run setup()
        old_sys_path = sys.path
        try:
            mock_sys_path = list(sys.path)
            sys.path = mock_sys_path
            support.setup(import_roots=['some_root', 'another_root'])
        finally:
            support._find_archive = old_find_archive
            tempfile.mkdtemp = old_mkdtemp
            sys.path = old_sys_path

        # Check results
        # some_root should be extracted to the tmp dir since
        # it has shared object files
        self.assertEqual(mock_sys_path[1], '{}/some_root'.format(tempdir))
        files_in_tmp_dir = os.listdir('{}/some_root'.format(tempdir))
        self.assertIn('main.py', files_in_tmp_dir)
        self.assertIn('file.so', files_in_tmp_dir)

        # another_root should just be added to sys.path since
        # there is no reason to extract it
        self.assertTrue(
            mock_sys_path[2].endswith('{}/another_root'.format(archive_path)),
            mock_sys_path)
        self.assertEqual(mock_sys_path[0], sys.path[0])
        self.assertEqual(mock_sys_path[3:], sys.path[1:])
Beispiel #9
0
 def test_setup(self):
     support.setup(import_roots=['some_root', 'another_root'])
     self.assertTrue(sys.path[1].endswith('subpar/runtime/some_root'),
                     sys.path)
     self.assertTrue(sys.path[2].endswith('subpar/runtime/another_root'),
                     sys.path)