Пример #1
0
    def test_CompileMultiPycAction_generic(self):
        package_info = AttrDict(package_metadata=AttrDict(noarch=AttrDict(
            type=NoarchType.generic)))
        noarch = package_info.package_metadata and package_info.package_metadata.noarch
        assert noarch.type == NoarchType.generic
        axns = CompileMultiPycAction.create_actions({}, package_info,
                                                    self.prefix, None, ())
        assert axns == ()

        package_info = AttrDict(package_metadata=None)
        axns = CompileMultiPycAction.create_actions({}, package_info,
                                                    self.prefix, None, ())
        assert axns == ()
Пример #2
0
    def test_CompileMultiPycAction_generic(self):
        package_info = AttrDict(
            package_metadata=AttrDict(
                noarch=AttrDict(
                    type=NoarchType.generic))
        )
        noarch = package_info.package_metadata and package_info.package_metadata.noarch
        assert noarch.type == NoarchType.generic
        axns = CompileMultiPycAction.create_actions({}, package_info, self.prefix, None, ())
        assert axns == ()

        package_info = AttrDict(package_metadata=None)
        axns = CompileMultiPycAction.create_actions({}, package_info, self.prefix, None, ())
        assert axns == ()
Пример #3
0
    def test_CompileMultiPycAction_noarch_python(self):
        if not softlink_supported(__file__, self.prefix) and on_win:
            pytest.skip("softlink not supported")
        target_python_version = '%d.%d' % sys.version_info[:2]
        sp_dir = get_python_site_packages_short_path(target_python_version)
        transaction_context = {
            'target_python_version': target_python_version,
            'target_site_packages_short_path': sp_dir,
        }
        package_info = AttrDict(package_metadata=AttrDict(noarch=AttrDict(type=NoarchType.python)))

        file_link_actions = [
            AttrDict(
                source_short_path='site-packages/something.py',
                target_short_path=get_python_noarch_target_path('site-packages/something.py', sp_dir),
            ),
            AttrDict(
                source_short_path='site-packages/another.py',
                target_short_path=get_python_noarch_target_path('site-packages/another.py', sp_dir),
            ),
            AttrDict(
                # this one shouldn't get compiled
                source_short_path='something.py',
                target_short_path=get_python_noarch_target_path('something.py', sp_dir),
            ),
            AttrDict(
                # this one shouldn't get compiled
                source_short_path='another.py',
                target_short_path=get_python_noarch_target_path('another.py', sp_dir),
            ),
        ]
        axns = CompileMultiPycAction.create_actions(transaction_context, package_info, self.prefix,
                                                    None, file_link_actions)

        assert len(axns) == 1
        axn = axns[0]
        source_full_paths = tuple(axn.source_full_paths)
        source_full_path0 = source_full_paths[0]
        source_full_path1 = source_full_paths[1]
        assert len(source_full_paths) == 2
        assert source_full_path0 == join(self.prefix, win_path_ok(get_python_noarch_target_path('site-packages/something.py', sp_dir)))
        assert source_full_path1 == join(self.prefix, win_path_ok(get_python_noarch_target_path('site-packages/another.py', sp_dir)))
        target_full_paths = tuple(axn.target_full_paths)
        target_full_path0 = target_full_paths[0]
        target_full_path1 = target_full_paths[1]
        assert len(target_full_paths) == 2
        assert target_full_path0 == join(self.prefix, win_path_ok(pyc_path(get_python_noarch_target_path('site-packages/something.py', sp_dir),
                     target_python_version)))
        assert target_full_path1 == join(self.prefix, win_path_ok(pyc_path(get_python_noarch_target_path('site-packages/another.py', sp_dir),
                     target_python_version)))

        # make .py file in prefix that will be compiled
        mkdir_p(dirname(source_full_path0))
        with open(source_full_path0, 'w') as fh:
            fh.write("value = 42\n")
        mkdir_p(dirname(source_full_path1))
        with open(source_full_path1, 'w') as fh:
            fh.write("value = 43\n")

        # symlink the current python
        python_full_path = join(self.prefix, get_python_short_path(target_python_version))
        mkdir_p(dirname(python_full_path))
        create_link(sys.executable, python_full_path, LinkType.softlink)

        axn.execute()
        assert isfile(target_full_path0)
        assert isfile(target_full_path1)

        # remove the source .py file so we're sure we're importing the pyc file below
        rm_rf(source_full_path0)
        assert not isfile(source_full_path0)
        rm_rf(source_full_path1)
        assert not isfile(source_full_path1)

        if (3,) > sys.version_info >= (3, 5):
            # we're probably dropping py34 support soon enough anyway
            imported_pyc_file = load_python_file(target_full_path0)
            assert imported_pyc_file.value == 42
            imported_pyc_file = load_python_file(target_full_path1)
            assert imported_pyc_file.value == 43

        axn.reverse()
        assert not isfile(target_full_path0)
        assert not isfile(target_full_path1)