Пример #1
0
def test_from_local_tree_exclude_multilevel_name(local_tree_fs):
    assert Directory.from_local_tree(
        Path('/var/data'), exclude=['bar/__pycache__']) == Directory(
            path=None,
            entries={
                "data":
                Directory(
                    path='data/',
                    entries={
                        "foo.py":
                        File(('data', 'foo.py'), None, None),
                        "foo.pyc":
                        File(('data', 'foo.pyc'), None, None),
                        "bar":
                        Directory(
                            path='data/bar/',
                            entries={
                                "__init__.py":
                                File(
                                    ('data', 'bar', '__init__.py'),
                                    None,
                                    None,
                                ),
                            },
                        ),
                    },
                ),
            },
        )
Пример #2
0
def test_from_local_tree_directory_excluded(local_tree_fs):
    assert Directory.from_local_tree(
        Path('/var/data/bar'), exclude=['bar']) == Directory(
            path=None,
            entries={
                "bar":
                Directory(
                    path='bar/',
                    entries={
                        "__init__.py":
                        File(
                            ('bar', '__init__.py'),
                            None,
                            None,
                        ),
                        "__pycache__":
                        Directory(
                            path='bar/__pycache__/',
                            entries={
                                "__init__.cpython-36.pyc":
                                File(
                                    ('bar', '__pycache__',
                                     '__init__.cpython-36.pyc'),
                                    None,
                                    None,
                                ),
                            },
                        ),
                    },
                ),
            },
        )
Пример #3
0
def test_get_package_tree_package_path(mocker, package_omit, exclude):
    path = Path('foobar')
    cfg = Configuration(package_paths=[path], package_omit=package_omit)
    tree = Directory(
        path=None,
        entries={
            "foobar":
            Directory(
                path="foobar/",
                entries={
                    "__init__.py": File(
                        ('foobar', '__init__.py'),
                        None,
                        None,
                    ),
                    "foo.py": File(
                        ('foobar', 'foo.py'),
                        None,
                        None,
                    ),
                    "bar.py": File(
                        ('foobar', 'bar.py'),
                        None,
                        None,
                    ),
                },
            ),
        },
    )
    fltmock = mocker.patch.object(Directory,
                                  'from_local_tree',
                                  return_value=tree)
    assert cfg.get_package_tree() == tree
    fltmock.assert_called_once_with(path, exclude=exclude)
Пример #4
0
def test_trees_data_purelib():
    """
    Test the ``purelib_tree`` and ``platlib_tree`` attributes of a platlib
    wheel containing a nonempty purelib and an empty platlib
    """
    whlcon = WheelContents.from_wheel(
        WHEEL_DIR /
        'mxnet_coreml_converter-0.1.0a7-cp27-cp27m-macosx_10_7_x86_64.whl')
    assert whlcon.dist_info_dir == 'mxnet_coreml_converter-0.1.0a7.dist-info'
    assert whlcon.data_dir == 'mxnet_coreml_converter-0.1.0a7.data'
    assert whlcon.root_is_purelib is False
    assert whlcon.purelib_tree == Directory(
        path='mxnet_coreml_converter-0.1.0a7.data/purelib/',
        entries={
            "converter":
            Directory(
                path='mxnet_coreml_converter-0.1.0a7.data/purelib/converter/',
                entries={
                    "__init__.py":
                    File(
                        ('mxnet_coreml_converter-0.1.0a7.data', 'purelib',
                         'converter', '__init__.py'),
                        786,
                        'sha256=EWsEJdqMbVZOBLYEvcci5VgvFEul-nubLnmcMn5MJlI',
                    ),
                    "_add_pooling.py":
                    File(
                        ('mxnet_coreml_converter-0.1.0a7.data', 'purelib',
                         'converter', '_add_pooling.py'),
                        5499,
                        'sha256=2wyhzbR60jm1uoMqgb50o7QHb7k5S3qJx3Xh17musnE',
                    ),
                    "_layers.py":
                    File(
                        ('mxnet_coreml_converter-0.1.0a7.data', 'purelib',
                         'converter', '_layers.py'),
                        16133,
                        'sha256=5w5ddYvF9mJv0YFKKcg4AqQPae4dZDYwn2iNyihukhU',
                    ),
                    "_mxnet_converter.py":
                    File(
                        ('mxnet_coreml_converter-0.1.0a7.data', 'purelib',
                         'converter', '_mxnet_converter.py'),
                        8850,
                        'sha256=kPLQxZv_KpuwRO1_gaa8vxhSMoDgNDEVJ-ZVLK02L2E',
                    ),
                    "utils.py":
                    File(
                        ('mxnet_coreml_converter-0.1.0a7.data', 'purelib',
                         'converter', 'utils.py'),
                        2447,
                        'sha256=oa9WWamfXwfNVMcjD0MERh_GeiwFDP9n4gEockPDr7Y',
                    ),
                },
            ),
        },
    )
    assert whlcon.platlib_tree == Directory()
Пример #5
0
def test_by_signature_dup_files():
    whlcon = WheelContents(
        dist_info_dir='foo-1.0.dist-info',
        data_dir='foo-1.0.data',
        root_is_purelib=True,
    )
    whlcon.add_record_rows([
        [
            'foo-1.0.dist-info/METADATA',
            'sha256=NVefY26xjCmYCQCnZaKUTNc5WaqZHDKxVde8l72cVOk',
            '950',
        ],
        [
            'foo.py',
            'sha256=feFUDF3H45ZfOetuMteWVwEzHex4AH9o_1vuVTvl9g4',
            '995',
        ],
        [
            'foo/__init__.py',
            'sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU',
            '0',
        ],
        [
            'foo/duplicate.py',
            'sha256=feFUDF3H45ZfOetuMteWVwEzHex4AH9o_1vuVTvl9g4',
            '995',
        ],
    ])
    whlcon.validate_tree()
    assert whlcon.by_signature == {
        (950, 'sha256=NVefY26xjCmYCQCnZaKUTNc5WaqZHDKxVde8l72cVOk'): [
            File(
                ('foo-1.0.dist-info', 'METADATA'),
                950,
                'sha256=NVefY26xjCmYCQCnZaKUTNc5WaqZHDKxVde8l72cVOk',
            )
        ],
        (995, 'sha256=feFUDF3H45ZfOetuMteWVwEzHex4AH9o_1vuVTvl9g4'): [
            File(
                ('foo.py', ),
                995,
                'sha256=feFUDF3H45ZfOetuMteWVwEzHex4AH9o_1vuVTvl9g4',
            ),
            File(
                ('foo', 'duplicate.py'),
                995,
                'sha256=feFUDF3H45ZfOetuMteWVwEzHex4AH9o_1vuVTvl9g4',
            )
        ],
        (0, 'sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU'): [
            File(
                ('foo', '__init__.py'),
                0,
                'sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU',
            )
        ],
    }
def test_from_local_tree():
    assert Directory.from_local_tree(PROJECT_TREE) == Directory(
        path=None,
        entries={
            "project-tree":
            Directory(
                path='project-tree/',
                entries={
                    "foo.py":
                    File(('project-tree', 'foo.py'), None, None),
                    "foo.pyc":
                    File(('project-tree', 'foo.pyc'), None, None),
                    "bar":
                    Directory(
                        path='project-tree/bar/',
                        entries={
                            "__init__.py":
                            File(
                                ('project-tree', 'bar', '__init__.py'),
                                None,
                                None,
                            ),
                            "__pycache__":
                            Directory(
                                path='project-tree/bar/__pycache__/',
                                entries={
                                    "__init__.cpython-36.pyc":
                                    File(
                                        ('project-tree', 'bar', '__pycache__',
                                         '__init__.cpython-36.pyc'),
                                        None,
                                        None,
                                    ),
                                },
                            ),
                        },
                    ),
                    "src":
                    Directory(
                        path='project-tree/src/',
                        entries={
                            ".placeholder":
                            File(
                                ('project-tree', 'src', '.placeholder'),
                                None,
                                None,
                            ),
                        },
                    ),
                },
            ),
        },
    )
def test_trees_data_platlib():
    """
    Test the ``purelib_tree`` and ``platlib_tree`` attributes of a purelib
    wheel containing an empty purelib and a nonempty platlib
    """
    whlcon = WheelContents.from_wheel(WHEEL_DIR/'MPC2860-0.3-py3-none-any.whl')
    assert whlcon.dist_info_dir == 'MPC2860-0.3.dist-info'
    assert whlcon.data_dir == 'MPC2860-0.3.data'
    assert whlcon.root_is_purelib is True
    assert whlcon.purelib_tree == Directory()
    assert whlcon.platlib_tree == Directory(
        path='MPC2860-0.3.data/platlib/',
        entries={
            "_motion_2860.pyd": File(
                ('MPC2860-0.3.data', 'platlib', '_motion_2860.pyd'),
                23040,
                'sha256=kCCzhKz-ZujN2OI0gaeB1W1WHUaC_PdifaIwy4AG6uA',
            ),
            "MPC2860": Directory(
                path='MPC2860-0.3.data/platlib/MPC2860/',
                entries={
                    "MPC2860.dll": File(
                        ('MPC2860-0.3.data', 'platlib', 'MPC2860', 'MPC2860.dll'),
                        548974,
                        'sha256=kOatNp1OqMU-bSzDgNtl9fg-cbQROp2pfnC_dAkD7zw',
                    ),
                    "MPC2860.lib": File(
                        ('MPC2860-0.3.data', 'platlib', 'MPC2860', 'MPC2860.lib'),
                        29200,
                        'sha256=mW1wenQt2kDLZLZFNShxzTxI-lsFUvroi7nlOC-WnbA',
                    ),
                    "MPC2860CFG.txt": File(
                        ('MPC2860-0.3.data', 'platlib', 'MPC2860', 'MPC2860CFG.txt'),
                        56,
                        'sha256=HVDtq-6twa1_nOtCBmuyrGB24EsnJ8PmoRYdqqBqFDI',
                    ),
                    "__init__.py": File(
                        ('MPC2860-0.3.data', 'platlib', 'MPC2860', '__init__.py'),
                        27,
                        'sha256=PYXKN_qL7Q0aak8GkOsleT-8hAezfzcbRR3gxCSB7n8',
                    ),
                    "_motion_2860.pyd": File(
                        ('MPC2860-0.3.data', 'platlib', 'MPC2860', '_motion_2860.pyd'),
                        23040,
                        'sha256=kCCzhKz-ZujN2OI0gaeB1W1WHUaC_PdifaIwy4AG6uA',
                    ),
                    "motion_2860.i": File(
                        ('MPC2860-0.3.data', 'platlib', 'MPC2860', 'motion_2860.i'),
                        98,
                        'sha256=cwWUHTvpo_ZmeSg7pDcD0qUM4LJnuOH2gZS6Zz4f0p8',
                    ),
                    "motion_2860.py": File(
                        ('MPC2860-0.3.data', 'platlib', 'MPC2860', 'motion_2860.py'),
                        4283,
                        'sha256=gn_45lgJZ1MQqvaBkjSnBJSbZUKmWGMy-1G8cln5-78',
                    ),
                },
            ),
        },
    )
def test_validate_tree_dir_rows(purelib):
    whlcon = WheelContents(
        dist_info_dir='foo-1.0.dist-info',
        data_dir='foo-1.0.data',
        root_is_purelib=purelib,
    )
    whlcon.add_record_rows([
        [
            'foo-1.0.dist-info/METADATA',
            'sha256=NVefY26xjCmYCQCnZaKUTNc5WaqZHDKxVde8l72cVOk',
            '950',
        ],
        ['empty/', '', ''],
    ])
    whlcon.validate_tree()
    assert whlcon.filetree == Directory(
        path=None,
        entries={
            "empty": Directory('empty/'),
            "foo-1.0.dist-info": Directory(
                path="foo-1.0.dist-info/",
                entries={
                    "METADATA": File(
                        ('foo-1.0.dist-info', 'METADATA'),
                        950,
                        'sha256=NVefY26xjCmYCQCnZaKUTNc5WaqZHDKxVde8l72cVOk',
                    ),
                },
            ),
        },
    )
    assert whlcon.by_signature == {
        (950, 'sha256=NVefY26xjCmYCQCnZaKUTNc5WaqZHDKxVde8l72cVOk'):
            [whlcon.filetree["foo-1.0.dist-info"]["METADATA"]],
    }
def test_apply_config_toplevel_pkgtree_mismatch_warning(capsys, mocker):
    pkgtree = Directory(
        path=None,
        entries={
            "foo.py": File(('foo.py'), None, None),
            "bar": Directory(path='bar/'),
        },
    )
    cfg = mocker.Mock(
        **{
            "get_selected_checks.return_value": mocker.sentinel.SELECTED,
            "get_package_tree.return_value": pkgtree,
        }, )
    cfg.toplevel = ["bar.py", "foo"]
    checker = WheelChecker()
    checker.apply_config(cfg)
    assert attr.asdict(checker, recurse=False) == {
        "selected": mocker.sentinel.SELECTED,
        "toplevel": ["bar.py", "foo"],
        "pkgtree": pkgtree,
    }
    captured = capsys.readouterr()
    assert captured.out == ''
    assert captured.err == (
        'Warning: --toplevel value does not match top level of --package/'
        '--src-dir file tree\n')
def test_from_local_tree_no_include_root():
    assert Directory.from_local_tree(
        PROJECT_TREE, include_root=False) == Directory(
            path=None,
            entries={
                "foo.py":
                File(('foo.py', ), None, None),
                "foo.pyc":
                File(('foo.pyc', ), None, None),
                "bar":
                Directory(
                    path='bar/',
                    entries={
                        "__init__.py":
                        File(
                            ('bar', '__init__.py'),
                            None,
                            None,
                        ),
                        "__pycache__":
                        Directory(
                            path='bar/__pycache__/',
                            entries={
                                "__init__.cpython-36.pyc":
                                File(
                                    ('bar', '__pycache__',
                                     '__init__.cpython-36.pyc'),
                                    None,
                                    None,
                                ),
                            },
                        ),
                    },
                ),
                "src":
                Directory(
                    path='src/',
                    entries={
                        ".placeholder": File(('src', '.placeholder'), None,
                                             None),
                    },
                ),
            },
        )
Пример #11
0
def test_trees_platlib():
    """
    Test the ``purelib_tree`` and ``platlib_tree`` attributes of a platlib
    wheel containing an empty purelib and a nonempty platlib
    """
    whlcon = WheelContents.from_wheel(WHEEL_DIR /
                                      'bcrypt-3.1.7-cp38-cp38-win_amd64.whl')
    assert whlcon.dist_info_dir == 'bcrypt-3.1.7.dist-info'
    assert whlcon.data_dir == 'bcrypt-3.1.7.data'
    assert whlcon.root_is_purelib is False
    assert whlcon.purelib_tree == Directory(
        path='bcrypt-3.1.7.data/purelib/',
        entries={},
    )
    assert whlcon.platlib_tree == Directory(
        path=None,
        entries={
            "bcrypt":
            Directory(
                path="bcrypt/",
                entries={
                    "__about__.py":
                    File(
                        ('bcrypt', '__about__.py'),
                        1296,
                        'sha256=jDmr9vNGIReR9gvahrcAIvOGOFq6Zmo_afmjN1Beb5g',
                    ),
                    "__init__.py":
                    File(
                        ('bcrypt', '__init__.py'),
                        5497,
                        'sha256=sIAkb9VLIbn4fHq_8xO79ndQ1bZ5O8rDO8OSHa5-RYs',
                    ),
                    "_bcrypt.cp38-win_amd64.pyd":
                    File(
                        ('bcrypt', '_bcrypt.cp38-win_amd64.pyd'),
                        30208,
                        'sha256=ALdvcGdNK8O_Ux3njNosbQc_9_5W3zzvb1ShFQCPdDU',
                    ),
                },
            ),
        },
    )
Пример #12
0
def test_from_local_tree(local_tree_fs):
    assert Directory.from_local_tree(Path('/var/data')) == Directory(
        path=None,
        entries={
            "data":
            Directory(
                path='data/',
                entries={
                    "foo.py":
                    File(('data', 'foo.py'), None, None),
                    "foo.pyc":
                    File(('data', 'foo.pyc'), None, None),
                    "bar":
                    Directory(
                        path='data/bar/',
                        entries={
                            "__init__.py":
                            File(
                                ('data', 'bar', '__init__.py'),
                                None,
                                None,
                            ),
                            "__pycache__":
                            Directory(
                                path='data/bar/__pycache__/',
                                entries={
                                    "__init__.cpython-36.pyc":
                                    File(
                                        ('data', 'bar', '__pycache__',
                                         '__init__.cpython-36.pyc'),
                                        None,
                                        None,
                                    ),
                                },
                            ),
                        },
                    ),
                },
            ),
        },
    )
def test_from_local_tree_exclude_multilevel_name():
    assert Directory.from_local_tree(
        PROJECT_TREE, exclude=['bar/__pycache__']) == Directory(
            path=None,
            entries={
                "project-tree":
                Directory(
                    path='project-tree/',
                    entries={
                        "foo.py":
                        File(('project-tree', 'foo.py'), None, None),
                        "foo.pyc":
                        File(('project-tree', 'foo.pyc'), None, None),
                        "bar":
                        Directory(
                            path='project-tree/bar/',
                            entries={
                                "__init__.py":
                                File(
                                    ('project-tree', 'bar', '__init__.py'),
                                    None,
                                    None,
                                ),
                            },
                        ),
                        "src":
                        Directory(
                            path='project-tree/src/',
                            entries={
                                ".placeholder":
                                File(
                                    ('project-tree', 'src', '.placeholder'),
                                    None,
                                    None,
                                ),
                            },
                        ),
                    },
                ),
            },
        )
def test_get_package_tree_package_path_and_src_dir(monkeypatch, tmp_path):
    create_file(tmp_path / 'src/foo.py')
    create_file(tmp_path / 'bar/__init__.py')
    create_file(tmp_path / 'bar/quux.py')
    create_file(tmp_path / 'bar/glarch.py')
    monkeypatch.chdir(tmp_path)
    cfg = Configuration(package_paths=[Path('bar')], src_dirs=[Path('src')])
    assert cfg.get_package_tree() == Directory(
        path=None,
        entries={
            "foo.py":
            File(('foo.py', ), None, None),
            "bar":
            Directory(
                path='bar/',
                entries={
                    "__init__.py": File(('bar', '__init__.py'), None, None),
                    "quux.py": File(('bar', 'quux.py'), None, None),
                    "glarch.py": File(('bar', 'glarch.py'), None, None),
                },
            ),
        },
    )
Пример #15
0
def test_get_package_tree_package_path_and_src_dir(fs):
    fs.create_file('/usr/src/project/src/foo.py')
    fs.create_file('/usr/src/project/bar/__init__.py')
    fs.create_file('/usr/src/project/bar/quux.py')
    fs.create_file('/usr/src/project/bar/glarch.py')
    fs.cwd = '/usr/src/project'
    cfg = Configuration(package_paths=[Path('bar')], src_dirs=[Path('src')])
    assert cfg.get_package_tree() == Directory(
        path=None,
        entries={
            "foo.py":
            File(('foo.py', ), None, None),
            "bar":
            Directory(
                path='bar/',
                entries={
                    "__init__.py": File(('bar', '__init__.py'), None, None),
                    "quux.py": File(('bar', 'quux.py'), None, None),
                    "glarch.py": File(('bar', 'glarch.py'), None, None),
                },
            ),
        },
    )
def test_from_local_tree_exclude_glob():
    assert Directory.from_local_tree(
        PROJECT_TREE, exclude=['*.pyc', '.*']) == Directory(
            path=None,
            entries={
                "project-tree":
                Directory(
                    path='project-tree/',
                    entries={
                        "foo.py":
                        File(('project-tree', 'foo.py'), None, None),
                        "bar":
                        Directory(
                            path='project-tree/bar/',
                            entries={
                                "__init__.py":
                                File(
                                    ('project-tree', 'bar', '__init__.py'),
                                    None,
                                    None,
                                ),
                                "__pycache__":
                                Directory(
                                    path='project-tree/bar/__pycache__/',
                                    entries={},
                                ),
                            },
                        ),
                        "src":
                        Directory(
                            path='project-tree/src/',
                            entries={},
                        ),
                    },
                ),
            },
        )
Пример #17
0
def test_from_local_tree_no_include_root(local_tree_fs):
    assert Directory.from_local_tree(
        Path('/var/data'), include_root=False) == Directory(
            path=None,
            entries={
                "foo.py":
                File(('foo.py', ), None, None),
                "foo.pyc":
                File(('foo.pyc', ), None, None),
                "bar":
                Directory(
                    path='bar/',
                    entries={
                        "__init__.py":
                        File(
                            ('bar', '__init__.py'),
                            None,
                            None,
                        ),
                        "__pycache__":
                        Directory(
                            path='bar/__pycache__/',
                            entries={
                                "__init__.cpython-36.pyc":
                                File(
                                    ('bar', '__pycache__',
                                     '__init__.cpython-36.pyc'),
                                    None,
                                    None,
                                ),
                            },
                        ),
                    },
                ),
            },
        )
Пример #18
0
def test_from_local_tree_file(local_tree_fs):
    assert Directory.from_local_tree(Path('/var/data/foo.py')) == Directory(
        path=None,
        entries={"foo.py": File(('foo.py', ), None, None)},
    )
Пример #19
0
def test_from_wheel_purelib():
    whlcon = WheelContents.from_wheel(
        WHEEL_DIR / 'ttyrec2video-0.1.0.dev1-py3-none-any.whl')
    assert whlcon.dist_info_dir == 'ttyrec2video-0.1.0.dev1.dist-info'
    assert whlcon.data_dir == 'ttyrec2video-0.1.0.dev1.data'
    assert whlcon.root_is_purelib is True
    assert whlcon.filetree == Directory(
        path=None,
        entries={
            "ttyrec2video":
            Directory(
                path='ttyrec2video/',
                entries={
                    "__init__.py":
                    File(
                        ('ttyrec2video', '__init__.py'),
                        322,
                        'sha256=Hsh34fgmI71Le1sOCameXxLmc01bHIwLd1EczCvLPfk',
                    ),
                    "__main__.py":
                    File(
                        ('ttyrec2video', '__main__.py'),
                        5740,
                        'sha256=Twv8iXPtwJrGSlSnM4iF31heGfNtU0Wc9reUlSVebzE',
                    ),
                    "reader.py":
                    File(
                        ('ttyrec2video', 'reader.py'),
                        1440,
                        'sha256=F29z_79pvjQv3_EXDGqsm47SIsRvRzwr6YlISUSqQrI',
                    ),
                    "renderer.py":
                    File(
                        ('ttyrec2video', 'renderer.py'),
                        3873,
                        'sha256=OWBPDb5D2QXrOW77sCf3RU9BQoJAutMvEcbPuWfE96Q',
                    ),
                    "data":
                    Directory(
                        path="ttyrec2video/data/",
                        entries={
                            "ubuntu-font":
                            Directory(
                                path="ttyrec2video/data/ubuntu-font/",
                                entries={
                                    "LICENCE.txt":
                                    File(
                                        ('ttyrec2video', 'data', 'ubuntu-font',
                                         'LICENCE.txt'),
                                        4673,
                                        'sha256=LwAVEI1oYnvXiNMT9SnCH_TaLCxCpeHziDrMg0gPkAI',
                                    ),
                                    "UbuntuMono-B.ttf":
                                    File(
                                        ('ttyrec2video', 'data', 'ubuntu-font',
                                         'UbuntuMono-B.ttf'),
                                        191400,
                                        'sha256=EfFcOmu9mYqGlf3vs0dZMcN4mqA111RvLv546Ds1L2s',
                                    ),
                                    "UbuntuMono-R.ttf":
                                    File(
                                        ('ttyrec2video', 'data', 'ubuntu-font',
                                         'UbuntuMono-R.ttf'),
                                        205748,
                                        'sha256=s13Z0hMdXYOpuH_prSLGKI-j0XaI1DMCwU2imBJBfWM',
                                    ),
                                    "copyright.txt":
                                    File(
                                        ('ttyrec2video', 'data', 'ubuntu-font',
                                         'copyright.txt'),
                                        155,
                                        'sha256=cVepFSJyTOB53fpTOhsQJeMdOyJ-GUz42AFZO6aSkUc',
                                    ),
                                },
                            ),
                        },
                    ),
                },
            ),
            "ttyrec2video-0.1.0.dev1.dist-info":
            Directory(
                path="ttyrec2video-0.1.0.dev1.dist-info/",
                entries={
                    "LICENSE":
                    File(
                        ("ttyrec2video-0.1.0.dev1.dist-info", 'LICENSE'),
                        1090,
                        'sha256=SDaeT4Cm3ZeLgPOOL_f9BliMMHH_GVwqJa6czCztoS0',
                    ),
                    "METADATA":
                    File(
                        ("ttyrec2video-0.1.0.dev1.dist-info", "METADATA"),
                        6269,
                        'sha256=ygypUvb3Lxe6WESfxHSy4-io4OKIeX4vNFo9i-SHnCs',
                    ),
                    "WHEEL":
                    File(
                        ("ttyrec2video-0.1.0.dev1.dist-info", "WHEEL"),
                        92,
                        'sha256=p46_5Uhzqz6AzeSosiOnxK-zmFja1i22CrQCjmYe8ec',
                    ),
                    "entry_points.txt":
                    File(
                        ("ttyrec2video-0.1.0.dev1.dist-info",
                         "entry_points.txt"),
                        61,
                        'sha256=471F-9Jb_a39olsyfq1Dy9lLnXHzPrlbYFiJM6Z3UJU',
                    ),
                    "top_level.txt":
                    File(
                        ("ttyrec2video-0.1.0.dev1.dist-info", "top_level.txt"),
                        13,
                        'sha256=FPSSfqt5fY1q0yYG27bAcWDPnkWB528v1lZg9meePUw',
                    ),
                    "RECORD":
                    File(
                        ("ttyrec2video-0.1.0.dev1.dist-info", "RECORD"),
                        None,
                        None,
                    ),
                },
            ),
        })
    assert whlcon.by_signature == {
        (322, 'sha256=Hsh34fgmI71Le1sOCameXxLmc01bHIwLd1EczCvLPfk'):
        [whlcon.filetree["ttyrec2video"]["__init__.py"]],
        (5740, 'sha256=Twv8iXPtwJrGSlSnM4iF31heGfNtU0Wc9reUlSVebzE'):
        [whlcon.filetree["ttyrec2video"]["__main__.py"]],
        (1440, 'sha256=F29z_79pvjQv3_EXDGqsm47SIsRvRzwr6YlISUSqQrI'):
        [whlcon.filetree["ttyrec2video"]["reader.py"]],
        (3873, 'sha256=OWBPDb5D2QXrOW77sCf3RU9BQoJAutMvEcbPuWfE96Q'):
        [whlcon.filetree["ttyrec2video"]["renderer.py"]],
        (4673, 'sha256=LwAVEI1oYnvXiNMT9SnCH_TaLCxCpeHziDrMg0gPkAI'): [
            whlcon.filetree["ttyrec2video"]["data"]["ubuntu-font"]
            ["LICENCE.txt"]
        ],
        (191400, 'sha256=EfFcOmu9mYqGlf3vs0dZMcN4mqA111RvLv546Ds1L2s'): [
            whlcon.filetree["ttyrec2video"]["data"]["ubuntu-font"]
            ["UbuntuMono-B.ttf"]
        ],
        (205748, 'sha256=s13Z0hMdXYOpuH_prSLGKI-j0XaI1DMCwU2imBJBfWM'): [
            whlcon.filetree["ttyrec2video"]["data"]["ubuntu-font"]
            ["UbuntuMono-R.ttf"]
        ],
        (155, 'sha256=cVepFSJyTOB53fpTOhsQJeMdOyJ-GUz42AFZO6aSkUc'): [
            whlcon.filetree["ttyrec2video"]["data"]["ubuntu-font"]
            ["copyright.txt"]
        ],
        (1090, 'sha256=SDaeT4Cm3ZeLgPOOL_f9BliMMHH_GVwqJa6czCztoS0'):
        [whlcon.filetree["ttyrec2video-0.1.0.dev1.dist-info"]["LICENSE"]],
        (6269, 'sha256=ygypUvb3Lxe6WESfxHSy4-io4OKIeX4vNFo9i-SHnCs'):
        [whlcon.filetree["ttyrec2video-0.1.0.dev1.dist-info"]["METADATA"]],
        (92, 'sha256=p46_5Uhzqz6AzeSosiOnxK-zmFja1i22CrQCjmYe8ec'):
        [whlcon.filetree["ttyrec2video-0.1.0.dev1.dist-info"]["WHEEL"]],
        (61, 'sha256=471F-9Jb_a39olsyfq1Dy9lLnXHzPrlbYFiJM6Z3UJU'): [
            whlcon.filetree["ttyrec2video-0.1.0.dev1.dist-info"]
            ["entry_points.txt"]
        ],
        (13, 'sha256=FPSSfqt5fY1q0yYG27bAcWDPnkWB528v1lZg9meePUw'): [
            whlcon.filetree["ttyrec2video-0.1.0.dev1.dist-info"]
            ["top_level.txt"]
        ],
        (None, None):
        [whlcon.filetree["ttyrec2video-0.1.0.dev1.dist-info"]["RECORD"]],
    }
    assert whlcon.purelib_tree == Directory(
        path=None,
        entries={"ttyrec2video": whlcon.filetree["ttyrec2video"]},
    )
    assert whlcon.platlib_tree == Directory(
        path='ttyrec2video-0.1.0.dev1.data/platlib/',
        entries={},
    )
    captured = capsys.readouterr()
    assert captured.out == ''
    assert captured.err == (
        'Warning: --toplevel value does not match top level of --package/'
        '--src-dir file tree\n')


@pytest.mark.parametrize('toplevel,pkgtree', [
    (None, None),
    (["foo.py", "bar"], None),
    (
        None,
        Directory(
            path=None,
            entries={
                "foo.py": File(('foo.py'), None, None),
                "bar": Directory(path='bar/'),
            },
        ),
    ),
    (
        ["foo.py", "bar"],
        Directory(
            path=None,
            entries={
                "foo.py": File(('foo.py'), None, None),
                "bar": Directory(path='bar/'),
            },
        ),
    ),
])
def test_from_local_tree_file():
    assert Directory.from_local_tree(PROJECT_TREE / 'foo.py') == Directory(
        path=None,
        entries={"foo.py": File(('foo.py', ), None, None)},
    )
def test_from_wheel_normalized_dist_info():
    whlcon = WheelContents.from_wheel(
        WHEEL_DIR / 'NLPTriples-0.1.7-py3-none-any.whl'
    )
    assert whlcon.dist_info_dir == 'nlptriples-0.1.7.dist-info'
    assert whlcon.data_dir == 'NLPTriples-0.1.7.data'
    assert whlcon.root_is_purelib is True
    assert whlcon.filetree == Directory(
        path=None,
        entries={
            "nlptriples": Directory(
                path='nlptriples/',
                entries={
                    "__init__.py": File(
                        ('nlptriples', '__init__.py'),
                        22,
                        'sha256=ls1camlIoMxEZz9gSkZ1OJo-MXqHWwKPtdPbZJmwp7E',
                    ),
                    "parse_tree.py": File(
                        ('nlptriples', 'parse_tree.py'),
                        1344,
                        'sha256=EVaZLOTa-2K88oXy105KFitx1nrkxW5Kj7bNABp_JH4',
                    ),
                    "setup.py": File(
                        ('nlptriples', 'setup.py'),
                        58,
                        'sha256=vYdNPB1dWAxaP0dZzTxFxYHCaeZ2EICCJWsIY26UpOc',
                    ),
                    "triples.py": File(
                        ('nlptriples', 'triples.py'),
                        7765,
                        'sha256=dmwUnDeO9z0nuF3oDiFlKXTjj0XlH9gG3cfo0Z-ylrE',
                    ),
                },
            ),
            "nlptriples-0.1.7.dist-info": Directory(
                path="nlptriples-0.1.7.dist-info/",
                entries={
                    "LICENSE": File(
                        ("nlptriples-0.1.7.dist-info", 'LICENSE'),
                        1070,
                        'sha256=VC7YIze9O5Ts59woVlji8eLn1GDvQCbCAXhG66uWFrE',
                    ),
                    "WHEEL": File(
                        ("nlptriples-0.1.7.dist-info", "WHEEL"),
                        84,
                        'sha256=Q99itqWYDhV793oHzqzi24q7L7Kdiz6cb55YDfTXphE',
                    ),
                    "METADATA": File(
                        ("nlptriples-0.1.7.dist-info", "METADATA"),
                        1603,
                        'sha256=dZ2YtcY8Gx3QiUFNjxqfQ4KRJAydb6-vCb2V0QYGe2U',
                    ),
                    "RECORD": File(
                        ("nlptriples-0.1.7.dist-info", "RECORD"),
                        None,
                        None,
                    ),
                },
            ),
        }
    )
    assert whlcon.by_signature == {
        (22, 'sha256=ls1camlIoMxEZz9gSkZ1OJo-MXqHWwKPtdPbZJmwp7E'):
            [whlcon.filetree["nlptriples"]["__init__.py"]],
        (1344, 'sha256=EVaZLOTa-2K88oXy105KFitx1nrkxW5Kj7bNABp_JH4'):
            [whlcon.filetree["nlptriples"]["parse_tree.py"]],
        (58, 'sha256=vYdNPB1dWAxaP0dZzTxFxYHCaeZ2EICCJWsIY26UpOc'):
            [whlcon.filetree["nlptriples"]["setup.py"]],
        (7765, 'sha256=dmwUnDeO9z0nuF3oDiFlKXTjj0XlH9gG3cfo0Z-ylrE'):
            [whlcon.filetree["nlptriples"]["triples.py"]],
        (1070, 'sha256=VC7YIze9O5Ts59woVlji8eLn1GDvQCbCAXhG66uWFrE'):
            [whlcon.filetree["nlptriples-0.1.7.dist-info"]["LICENSE"]],
        (84, 'sha256=Q99itqWYDhV793oHzqzi24q7L7Kdiz6cb55YDfTXphE'):
            [whlcon.filetree["nlptriples-0.1.7.dist-info"]["WHEEL"]],
        (1603, 'sha256=dZ2YtcY8Gx3QiUFNjxqfQ4KRJAydb6-vCb2V0QYGe2U'):
            [whlcon.filetree["nlptriples-0.1.7.dist-info"]["METADATA"]],
        (None, None):
            [whlcon.filetree["nlptriples-0.1.7.dist-info"]["RECORD"]],
    }
    assert whlcon.purelib_tree == Directory(
        path=None,
        entries={"nlptriples": whlcon.filetree["nlptriples"]},
    )
    assert whlcon.platlib_tree == Directory(
        path='NLPTriples-0.1.7.data/platlib/',
        entries={},
    )
def test_from_local_tree_file_excluded():
    assert Directory.from_local_tree(
        PROJECT_TREE / 'foo.pyc', exclude=['*.pyc']) == Directory(
            path=None,
            entries={"foo.pyc": File(('foo.pyc', ), None, None)},
        )
Пример #24
0
def test_from_local_tree_file_excluded(local_tree_fs):
    assert Directory.from_local_tree(
        Path('/var/data/foo.pyc'), exclude=['*.pyc']) == Directory(
            path=None,
            entries={"foo.pyc": File(('foo.pyc', ), None, None)},
        )
Пример #25
0
import pytest
from   check_wheel_contents.errors   import WheelValidationError
from   check_wheel_contents.filetree import File

@pytest.mark.parametrize('row,expected', [
    (['foo.py', '', ''], File(parts=('foo.py',), size=None, hashsum=None)),
    (['foo.py', '', '42'], File(parts=('foo.py',), size=42, hashsum=None)),
    (
        ['foo.py', 'sha256=...', ''],
        File(parts=('foo.py',), size=None, hashsum='sha256=...'),
    ),
    (
        ['foo.py', 'sha256=...', '42'],
        File(parts=('foo.py',), size=42, hashsum='sha256=...'),
    ),
    (
        ['foo/bar.py', '', ''],
        File(parts=('foo', 'bar.py'), size=None, hashsum=None),
    ),
])
def test_from_record_row(row, expected):
    assert File.from_record_row(row) == expected

@pytest.mark.parametrize('row', [
    [],
    ['foo.py'],
    ['foo.py', 'sha256=...'],
    ['foo.py', 'sha256=...', '42', 'stuff'],
    ['foo.py', '42', 'sha256=...'],
    ['foo.py', 'sha256=...', '42a'],
])