예제 #1
0
def test_only_binary(only_binary):
    """Packages without any python at all should have data_files installed."""

    package_dir, binary_file = only_binary
    build()
    dist_dir = verify_artifacts(package_dir)

    verify_wheel([binary_file], dist_dir)
    verify_source([binary_file, "MANIFEST.in"], dist_dir)
예제 #2
0
def test_only_binary(only_binary):
    """Packages without any python at all should have data_files installed."""

    package_dir, binary_file = only_binary
    build()
    dist_dir = verify_artifacts(package_dir)

    verify_wheel([binary_file], dist_dir)
    verify_source([binary_file, "MANIFEST.in"], dist_dir)
예제 #3
0
def test_simple_module(simple_module):
    """Test a single simple python module."""

    build()

    mod_dir, mod_name = simple_module
    dist_dir = verify_artifacts(mod_dir)

    mod_file = "{}.py".format(mod_name)
    verify_wheel([mod_file], dist_dir)
    verify_source([mod_file], dist_dir)
예제 #4
0
def test_simple_module(simple_module):
    """Test a single simple python module."""

    build()

    mod_dir, mod_name = simple_module
    dist_dir = verify_artifacts(mod_dir)

    mod_file = "{}.py".format(mod_name)
    verify_wheel([mod_file], dist_dir)
    verify_source([mod_file], dist_dir)
예제 #5
0
def test_simple_package(simple_package):
    """Ensure a simple normal python package is correctly built."""

    build()
    dist_dir = verify_artifacts(simple_package)

    package_name = os.path.basename(simple_package)
    expected_files = [
        "{}/__init__.py".format(package_name),
        "{}/my_module.py".format(package_name),
    ]

    verify_wheel(expected_files, dist_dir)
    verify_source(expected_files + [package_name], dist_dir)
예제 #6
0
def test_no_build(reset_sys_argv, flag):
    """Ensure build is not called if setup or metadata is requested."""

    sys.argv = ["py-build", "-{}".format(flag)]
    opts = mock.Mock()  # mock object attributes respond as True-ish
    with mock.patch.object(commands, "pypackage_setup") as patched_setup:
        with mock.patch.object(commands, "get_options", return_value=opts):
            commands.build()

    patched_setup.assert_called_once_with(
        None,
        additional=commands.build.__doc__,
        options=opts,
    )
예제 #7
0
def test_simple_package(simple_package):
    """Ensure a simple normal python package is correctly built."""

    build()
    dist_dir = verify_artifacts(simple_package)

    package_name = os.path.basename(simple_package)
    expected_files = [
        "{}/__init__.py".format(package_name),
        "{}/my_module.py".format(package_name),
    ]

    verify_wheel(expected_files, dist_dir)
    verify_source(expected_files + [package_name], dist_dir)
예제 #8
0
def test_no_build(reset_sys_argv, flag):
    """Ensure build is not called if setup or metadata is requested."""

    sys.argv = ["py-build", "-{}".format(flag)]
    opts = mock.Mock()  # mock object attributes respond as True-ish
    with mock.patch.object(commands, "pypackage_setup") as patched_setup:
        with mock.patch.object(commands, "get_options", return_value=opts):
            commands.build()

    patched_setup.assert_called_once_with(
        None,
        additional=commands.build.__doc__,
        options=opts,
    )
예제 #9
0
def test_only_binary__setup_output(only_binary, reset_sys_argv):

    package_dir, binary_file = only_binary
    sys.argv = ["py-build", "-sm"]
    build()
    with open(os.path.join(package_dir, "setup.py")) as opensetup:
        setup_contents = opensetup.read()

    assert 'data_files=' in setup_contents
    assert "['{}'])],".format(binary_file) in setup_contents

    with open(os.path.join(package_dir, "pypackage.meta")) as openmeta:
        meta_contents = openmeta.read()

    expected_banner = "# pypackage.meta generated by `py-build -sm` at "
    assert expected_banner in meta_contents.splitlines()[0]
예제 #10
0
def test_only_binary__setup_output(only_binary, reset_sys_argv):

    package_dir, binary_file = only_binary
    sys.argv = ["py-build", "-sm"]
    build()
    with open(os.path.join(package_dir, "setup.py")) as opensetup:
        setup_contents = opensetup.read()

    assert 'data_files=' in setup_contents
    assert "['{}'])],".format(binary_file) in setup_contents

    with open(os.path.join(package_dir, "pypackage.meta")) as openmeta:
        meta_contents = openmeta.read()

    expected_banner = "# pypackage.meta generated by `py-build -sm` at "
    assert expected_banner in meta_contents.splitlines()[0]
예제 #11
0
def test_with_data(with_data):
    """Ensure the non-python data files are being picked up."""

    build()
    root, pkg_root = with_data
    dist_dir = verify_artifacts(root)

    package_name = os.path.basename(pkg_root)
    expected_files = [
        "{}/data/data_1".format(package_name),
        "{}/__init__.py".format(package_name),
        "{}/my_module.py".format(package_name),
    ]
    expected_in_source = expected_files + [
        "{}/data".format(package_name),  # data folder
        "MANIFEST.in",
        package_name,  # base folder
    ]

    verify_wheel(expected_files, dist_dir)
    verify_source(expected_in_source, dist_dir)
예제 #12
0
def test_with_data(with_data):
    """Ensure the non-python data files are being picked up."""

    build()
    root, pkg_root = with_data
    dist_dir = verify_artifacts(root)

    package_name = os.path.basename(pkg_root)
    expected_files = [
        "{}/data/data_1".format(package_name),
        "{}/__init__.py".format(package_name),
        "{}/my_module.py".format(package_name),
    ]
    expected_in_source = expected_files + [
        "{}/data".format(package_name),  # data folder
        "MANIFEST.in",
        package_name,  # base folder
    ]

    verify_wheel(expected_files, dist_dir)
    verify_source(expected_in_source, dist_dir)
예제 #13
0
def test_with_scripts(with_scripts):
    """Ensure the executable scripts are being included."""

    package_dir, script_dir = with_scripts
    build()
    dist_dir = verify_artifacts(package_dir)

    package_name = os.path.basename(package_dir)
    expected_in_wheel = [
        "/scripts/my_script",
        "{}/__init__.py".format(package_name),
        "{}/my_module.py".format(package_name),
    ]
    expected_in_source = [
        package_name,  # base folder
        script_dir,
        "{}/my_script".format(script_dir),
        "{}/__init__.py".format(package_name),
        "{}/my_module.py".format(package_name),
    ]

    verify_wheel(expected_in_wheel, dist_dir)
    verify_source(expected_in_source, dist_dir)
예제 #14
0
def test_with_scripts(with_scripts):
    """Ensure the executable scripts are being included."""

    package_dir, script_dir = with_scripts
    build()
    dist_dir = verify_artifacts(package_dir)

    package_name = os.path.basename(package_dir)
    expected_in_wheel = [
        "/scripts/my_script",
        "{}/__init__.py".format(package_name),
        "{}/my_module.py".format(package_name),
    ]
    expected_in_source = [
        package_name,  # base folder
        script_dir,
        "{}/my_script".format(script_dir),
        "{}/__init__.py".format(package_name),
        "{}/my_module.py".format(package_name),
    ]

    verify_wheel(expected_in_wheel, dist_dir)
    verify_source(expected_in_source, dist_dir)
예제 #15
0
def test_manifest_mixin(with_data):
    """Ensure we can write a partial MANIFEST.in file."""

    root, pkg_root = with_data
    pkg_name = os.path.basename(pkg_root)
    with open(os.path.join(pkg_root, "data", "data_2"), "w") as opendata:
        opendata.write("some data")

    with open(os.path.join(root, "MANIFEST.in"), "w") as openmanifest:
        openmanifest.write("include {}/data/data_2\n".format(pkg_name))

    build()
    dist_dir = verify_artifacts(root)

    tar_fname = glob.glob(os.path.join(dist_dir, "*.tar.gz"))[0]
    with tarfile.open(tar_fname, "r:gz") as tar_file:
        tar_file.getnames()
        manifest = [f for f in tar_file.members if "MANIFEST.in" in f.name][0]
        content = tar_file.extractfile(manifest).read()

        assert [codecs.decode(l, "utf-8") for l in content.splitlines()] == [
            "include {}/data/data_2".format(pkg_name),
            "include {}/data/data_1".format(pkg_name),
        ]
예제 #16
0
def test_manifest_mixin(with_data):
    """Ensure we can write a partial MANIFEST.in file."""

    root, pkg_root = with_data
    pkg_name = os.path.basename(pkg_root)
    with open(os.path.join(pkg_root, "data", "data_2"), "w") as opendata:
        opendata.write("some data")

    with open(os.path.join(root, "MANIFEST.in"), "w") as openmanifest:
        openmanifest.write("include {}/data/data_2\n".format(pkg_name))

    build()
    dist_dir = verify_artifacts(root)

    tar_fname = glob.glob(os.path.join(dist_dir, "*.tar.gz"))[0]
    with tarfile.open(tar_fname, "r:gz") as tar_file:
        tar_file.getnames()
        manifest = [f for f in tar_file.members if "MANIFEST.in" in f.name][0]
        content = tar_file.extractfile(manifest).read()

        assert [codecs.decode(l, "utf-8") for l in content.splitlines()] == [
            "include {}/data/data_2".format(pkg_name),
            "include {}/data/data_1".format(pkg_name),
        ]