How to use testpath - 10 common examples

To help you get started, we’ve selected a few testpath examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github takluyver / flit / tests / test_install.py View on Github external
def test_install_requires_extra(deps, extras, installed):
    it = InstallTests()
    try:
        it.setUp()
        ins = Installer.from_ini_path(samples_dir / 'extras' / 'pyproject.toml', python='mock_python',
                        user=False, deps=deps, extras=extras)

        cmd = MockCommand('mock_python')
        get_reqs = (
            "#!{python}\n"
            "import sys\n"
            "with open({recording_file!r}, 'wb') as w, open(sys.argv[-1], 'rb') as r:\n"
            "    w.write(r.read())"
        ).format(python=sys.executable, recording_file=cmd.recording_file)
        cmd.content = get_reqs

        with cmd as mock_py:
            ins.install_requirements()
        with open(mock_py.recording_file) as f:
            str_deps = f.read()
        deps = str_deps.split('\n') if str_deps else []

        assert set(deps) == installed
    finally:
github takluyver / flit / tests / test_sdist.py View on Github external
def test_get_files_list_git(copy_sample):
    td = copy_sample('module1_toml')
    (td / '.git').mkdir()

    builder = sdist.SdistBuilder.from_ini_path(td / 'pyproject.toml')
    with MockCommand('git', LIST_FILES_GIT):
        files = builder.select_files()

    assert set(files) == {
        'foo', pjoin('dir1', 'bar'), pjoin('dir1', 'subdir', 'qux'),
        pjoin('dir2', 'abc')
    }
github jupyter / testpath / testpath / commands.py View on Github external
def assert_calls(cmd, args=None):
    """Assert that a block of code runs the given command.
    
    If args is passed, also check that it was called at least once with the
    given arguments (not including the command name).
    
    Use as a context manager, e.g.::
    
        with assert_calls('git'):
            some_function_wrapping_git()
            
        with assert_calls('git', ['add', myfile]):
            some_other_function()
    """
    with MockCommand(cmd) as mc:
        yield
    
    calls = mc.get_calls()
    assert calls != [], "Command %r was not called" % cmd

    if args is not None:
        if not any(args == c['argv'][1:] for c in calls):
            msg = ["Command %r was not called with specified args (%r)" %
                            (cmd, args),
                   "It was called with these arguments: "]
            for c in calls:
                msg.append('  %r' % c['argv'][1:])
            raise AssertionError('\n'.join(msg))
github takluyver / flit / tests / test_wheel.py View on Github external
def test_wheel_package(copy_sample):
    td = copy_sample('package1')
    make_wheel_in(td / 'flit.ini', td)
    assert_isfile(td / 'package1-0.1-py2.py3-none-any.whl')
github takluyver / flit / tests / test_init.py View on Github external
def test_write_license():
    with TemporaryDirectory() as td:
        ib = init.IniterBase(td)
        ib.write_license('mit', 'Thomas Kluyver')
        assert_isfile(Path(td, 'LICENSE'))
github takluyver / flit / tests / test_wheel.py View on Github external
def test_compression(tmp_path):
    info = make_wheel_in(samples_dir / 'module1_ini' / 'flit.ini', tmp_path)
    assert_isfile(info.file)
    with zipfile.ZipFile(str(info.file)) as zf:
        for name in [
            'module1.py',
            'module1-0.1.dist-info/METADATA',
        ]:
            assert zf.getinfo(name).compress_type == zipfile.ZIP_DEFLATED
github takluyver / flit / tests / test_install.py View on Github external
def test_symlink_package(self):
        if os.name == 'nt':
            raise SkipTest("symlink")
        Installer.from_ini_path(samples_dir / 'package1' / 'pyproject.toml', symlink=True).install()
        assert_islink(self.tmpdir / 'site-packages' / 'package1',
                      to=samples_dir / 'package1' / 'package1')
        assert_isfile(self.tmpdir / 'scripts' / 'pkg_script')
        with (self.tmpdir / 'scripts' / 'pkg_script').open() as f:
            assert f.readline().strip() == "#!" + sys.executable
        self._assert_direct_url(
            samples_dir / 'package1', 'package1', '0.1', expected_editable=True
        )
github takluyver / flit / tests / test_wheel.py View on Github external
def test_wheel_src_module(copy_sample):
    td = copy_sample('module3')
    make_wheel_in(td / 'flit.ini', td)

    whl_file = td / 'module3-0.1-py2.py3-none-any.whl'
    assert_isfile(whl_file)
    with unpack(whl_file) as unpacked:
        assert_isfile(Path(unpacked, 'module3.py'))
        assert_isdir(Path(unpacked, 'module3-0.1.dist-info'))
        assert_isfile(Path(unpacked, 'module3-0.1.dist-info', 'LICENSE'))
github takluyver / flit / tests / test_install.py View on Github external
def _assert_direct_url(self, directory, package, version, expected_editable):
        direct_url_file = (
            self.tmpdir
            / 'site-packages'
            / '{}-{}.dist-info'.format(package, version)
            / 'direct_url.json'
        )
        assert_isfile(direct_url_file)
        with direct_url_file.open() as f:
            direct_url = json.load(f)
            assert direct_url['url'].startswith('file:///')
            assert direct_url['url'] == directory.as_uri()
            assert direct_url['dir_info'].get('editable') is expected_editable
github takluyver / flit / tests / test_tomlify.py View on Github external
def test_tomlify(copy_sample, monkeypatch):
    td = copy_sample('with_flit_ini')
    monkeypatch.chdir(td)

    tomlify.main(argv=[])

    pyproject_toml = (td / 'pyproject.toml')
    assert_isfile(pyproject_toml)

    with pyproject_toml.open(encoding='utf-8') as f:
        content = pytoml.load(f)

    assert 'build-system' in content
    assert 'tool' in content
    assert 'flit' in content['tool']
    flit_table = content['tool']['flit']
    assert 'metadata' in flit_table
    assert 'scripts' in flit_table
    assert 'entrypoints' in flit_table

testpath

Test utilities for code working with files and commands

BSD-3-Clause
Latest version published 3 years ago

Package Health Score

55 / 100
Full package analysis

Similar packages