Ejemplo n.º 1
0
def test_merge_dir_to():
    with TemporaryDirectory() as td1, TemporaryDirectory() as td2:
        td1 = Path(td1)
        td2 = Path(td2)
        with (td1 / 'ab').open('w') as f:
            f.write(u"original")
        with (td2 / 'ab').open('w') as f:
            f.write(u"alternate")

        (td1 / 'subdir').mkdir()
        with (td1 / 'subdir' / 'foo').open('w'): pass
        (td2 / 'subdir').mkdir()
        with (td2 / 'subdir' / 'bar').open('w'): pass

        merge_dir_to(td2, td1)

        assert_isfile(str(td1 / 'subdir' / 'foo'))
        assert_isfile(str(td1 / 'subdir' / 'bar'))
        with (td1 / 'ab').open() as f:
            assert_equal(f.read(), u"alternate")

        # Test with conflicts
        (td1 / 'conflict').mkdir()
        with (td2 / 'conflict').open('w'): pass

        with assert_raises(RuntimeError):
            merge_dir_to(td2, td1)
        with assert_raises(RuntimeError):
            merge_dir_to(td1, td2)
Ejemplo n.º 2
0
def test_copy_from_zipfile(tmpdir):
    tmpdir = str(tmpdir)
    copy_modules(['zippedmod2', 'zippedpkg2'],
                 tmpdir, running_python, sample_path)
#        assert_isfile(pjoin(tmpdir, 'zippedmod.py'))
#        assert_isdir(pjoin(tmpdir, 'zippedpkg'))
    assert_isfile(pjoin(tmpdir, 'zippedmod2.py'))
    assert_isdir(pjoin(tmpdir, 'zippedpkg2'))
Ejemplo n.º 3
0
def test_download():
    wd = WheelDownloader("astsearch==0.1.2", "3.5.1", 64)
    wheel = wd.fetch()
    assert_isfile(wheel)

    with TemporaryDirectory() as td:
        extract_wheel(wheel, target_dir=td)
        assert_isfile(pjoin(td, 'astsearch.py'))
Ejemplo n.º 4
0
def test_entry_points():
    clear_samples_dist()
    wheel_main(samples_dir / 'entrypoints_valid.ini')
    assert_isfile(samples_dir / 'dist/package1-0.1-py2.py3-none-any.whl')
    with unpack(samples_dir / 'dist/package1-0.1-py2.py3-none-any.whl') as td:
        entry_points = Path(td, 'package1-0.1.dist-info', 'entry_points.txt')
        assert_isfile(entry_points)
        cp = configparser.ConfigParser()
        cp.read(str(entry_points))
        assert 'console_scripts' in cp.sections()
        assert 'myplugins' in cp.sections()
Ejemplo n.º 5
0
def test_entry_points():
    clear_samples_dist()
    WheelBuilder(samples_dir / "entrypoints_valid.ini").build()
    assert_isfile(samples_dir / "dist/package1-0.1-py2.py3-none-any.whl")
    with unpack(samples_dir / "dist/package1-0.1-py2.py3-none-any.whl") as td:
        entry_points = Path(td, "package1-0.1.dist-info", "entry_points.txt")
        assert_isfile(entry_points)
        cp = configparser.ConfigParser()
        cp.read(str(entry_points))
        assert "console_scripts" in cp.sections()
        assert "myplugins" in cp.sections()
Ejemplo n.º 6
0
def test_copy_installer_nsi(tmpdir):
    tmpdir = str(tmpdir)
    files = [
        (pjoin(test_dir, 'data_files', 'dir1', 'installer.nsi'), None),
    ]
    ib = InstallerBuilder("Test App", "1.0", {}, extra_files=files,
                          build_dir=tmpdir)
    ib.copy_extra_files()

    assert_isfile(pjoin(tmpdir, 'installer.1.nsi'))
    assert ib.install_files == [('installer.1.nsi', '$INSTDIR')]
Ejemplo n.º 7
0
def test_extract_exclude_folder(tmpdir):
    whl_file = str(tmpdir / 'foo.whl')
    pkgs = tmpdir.mkdir('pkgs')

    with ZipFile(whl_file, 'w') as zf:
        zf.writestr('foo/bar.txt', b'blah')
        zf.writestr('foo/bar/abc.txt', b'blah')

    extract_wheel(whl_file, str(pkgs), exclude=['pkgs/foo/bar'])

    assert_isfile(str(pkgs / 'foo' / 'bar.txt'))
    assert_not_path_exists(str(pkgs / 'foo' / 'bar'))
Ejemplo n.º 8
0
    def test_invalid_db_file(self):
        invalid_sql_file = os.path.join(self.data_dir, 'invalid_db_file.db')
        with open(invalid_sql_file, 'w') as tempfile:
            tempfile.write(u'[invalid data]')

        invalid_notary = sign.NotebookNotary(
            db_file=invalid_sql_file,
            secret=b'secret',
        )
        invalid_notary.sign(self.nb)

        testpath.assert_isfile(os.path.join(self.data_dir, invalid_sql_file))
        testpath.assert_isfile(os.path.join(self.data_dir, invalid_sql_file + '.bak'))
Ejemplo n.º 9
0
def test_matching_one_pattern(tmpdir):
    td1 = str(tmpdir.mkdir('wheels'))
    td2 = str(tmpdir.mkdir('pkgs'))

    subprocess.call(['pip', 'wheel', 'requests==2.19.1', '-w', str(td1)])

    wg = WheelGetter([], [os.path.join(td1, '*.whl')], td2, platform.python_version(), 64)
    wg.get_globs()

    assert_isdir(os.path.join(td2, 'requests'))
    assert_isfile(os.path.join(td2, 'requests-2.19.1.dist-info', 'METADATA'))

    assert_isdir(os.path.join(td2, 'urllib3'))
    assert glob.glob(os.path.join(td2, 'urllib3*.dist-info'))
Ejemplo n.º 10
0
    def test_ensure_path_env(self):
        def mock_expanduser(p):
            return p.replace('~', self.td)

        with mock.patch('os.path.expanduser', mock_expanduser), \
             testpath.modified_env({'PATH': '/bin'}):

            self.installer.ensure_path_env()

        profile_file = pjoin(self.td, '.profile')
        testpath.assert_isfile(profile_file)

        with open(profile_file, 'r') as f:
            contents = f.read()
        assert self.installer.scheme['commands']+':$PATH' in contents
Ejemplo n.º 11
0
    def test_remove_files(self):
        files = [
            pjoin(self.td, 'applications', 'fooview.desktop'),
            pjoin(self.td, 'icons', 'hicolor', '48x48', 'apps', 'tango-calculator.png'),
            pjoin(self.td, 'mime', 'packages', 'example-diff.xml'),
        ]
        script = pjoin(self.td, 'bin', 'launch-sampleapp')

        for file in files:
            testpath.assert_isfile(file)
        testpath.assert_islink(script)

        self.uninstaller.remove_files()

        for path in files + [script]:
            testpath.assert_not_path_exists(path)
Ejemplo n.º 12
0
def test_prepare_bin_dir():
    with TemporaryDirectory() as td:
        td = Path(td)
        commands.prepare_bin_directory(td, cmds)
        assert_isfile(td / 'acommand.exe')
        script_file = td / 'acommand-script.py'
        assert_isfile(script_file)

        with script_file.open() as f:
            script_contents = f.read()
        assert script_contents.startswith("#!python")
        assert_in('import extra', script_contents)
        assert_in('somefunc()', script_contents)

        _rewrite_shebangs.main(['_rewrite_shebangs.py', str(td)])
        with script_file.open() as f:
            assert f.read().startswith('#!"')
Ejemplo n.º 13
0
    def test_install_desktop_files(self):
        self.installer.install_desktop_files()
        d = pjoin(self.td, 'applications')
        install_dir = pjoin(self.td, 'installed-applications', 'sampleapp')
        testpath.assert_isfile(pjoin(d, 'fooview.desktop'))
        testpath.assert_isfile(pjoin(d, 'script_in_install_dir.desktop'))

        with open(pjoin(d, 'script_in_install_dir.desktop')) as f:
            checked_lines = 0
            for line in f:
                if line.startswith('Exec='):
                    assert pjoin(install_dir, 'bin', 'fooview') in line
                    checked_lines += 1
                elif line.startswith('Icon='):
                    assert pjoin(install_dir, 'fooview.png') in line
                    checked_lines += 1

        assert checked_lines == 2
Ejemplo n.º 14
0
def test_prepare_shortcuts(tmpdir):
    tmpdir = str(tmpdir)
    shortcuts = {'sc1': {'entry_point': 'norwegian.blue:parrot',
                         'icon': DEFAULT_ICON,
                         'console': False,
                         'extra_preamble': sample_preamble}}
    ib = InstallerBuilder("Test App", "1.0", shortcuts, build_dir=tmpdir)
    ib.prepare_shortcuts()

    scfile = pjoin(tmpdir, 'sc1.launch.pyw')
    assert_isfile(scfile)

    with io.open(scfile, 'r', encoding='utf-8') as f:
        contents = f.read()

    last2lines = [l.strip() for l in contents.rstrip().splitlines()[-2:]]
    assert last2lines == ['from norwegian.blue import parrot', 'parrot()']

    with io.open(sample_preamble, 'r', encoding='utf-8') as f:
        preamble_contents = f.read().strip()

    assert preamble_contents in contents
Ejemplo n.º 15
0
def test_prepare_bin_dir(tmpdir):
    cmds = {
        'acommand': {
            'entry_point': 'somemod:somefunc',
            'extra_preamble': io.StringIO(u'import extra')
        }
    }
    commands.prepare_bin_directory(tmpdir, cmds)

    launcher_file = str(tmpdir / 'launcher_exe.dat')
    launcher_noconsole_file = str(tmpdir / 'launcher_noconsole_exe.dat')
    zip_file = str(tmpdir / 'acommand-append.zip')
    zip_file_invalid = str(tmpdir / 'acommand-append-noconsole.zip')
    exe_file = str(tmpdir / 'acommand.exe')

    assert_isfile(launcher_file)
    assert_isfile(launcher_noconsole_file)
    assert_isfile(zip_file)
    assert_not_path_exists(zip_file_invalid)
    assert_not_path_exists(exe_file)

    with open(launcher_file, 'rb') as lf:
        b_launcher = lf.read()
        assert b_launcher[:2] == b'MZ'
    with open(launcher_noconsole_file, 'rb') as lf:
        assert lf.read(2) == b'MZ'

    with ZipFile(zip_file) as zf:
        assert zf.testzip() is None
        script_contents = zf.read('__main__.py').decode('utf-8')
    assert 'import extra' in script_contents
    assert 'somefunc()' in script_contents

    _assemble_launchers.main(['_assemble_launchers.py', 'C:\\path\\to\\python', str(tmpdir)])

    assert_isfile(exe_file)

    with open(exe_file, 'rb') as ef, open(zip_file, 'rb') as zf:
        b_exe = ef.read()
        b_zip = zf.read()
        assert b_exe[:len(b_launcher)] == b_launcher
        assert b_exe[len(b_launcher):-len(b_zip)].decode('utf-8') == '#!"C:\\path\\to\\python.exe"\r\n'
        assert b_exe[-len(b_zip):] == b_zip

    with ZipFile(exe_file) as zf:
        assert zf.testzip() is None
        assert zf.read('__main__.py').decode('utf-8') == script_contents
Ejemplo n.º 16
0
def test_extract_data_lib_sitepkg(tmpdir):
    whl_file = str(tmpdir / 'foo.whl')
    pkgs = tmpdir.mkdir('pkgs')

    with ZipFile(whl_file, 'w') as zf:
        zf.writestr('osgeo/bar.txt', b'blah')
        # The case of 'Lib/site-packages' shouldn't matter
        zf.writestr('foo-1.0.data/data/Lib/siTE-packages/osgeo/abc.txt', b'a')
        zf.writestr('foo-1.0.data/data/lib/site-packages/osgeo/def.txt', b'd')

    extract_wheel(whl_file, str(pkgs), exclude=['pkgs/foo/bar'])

    assert_isfile(str(pkgs / 'osgeo' / 'bar.txt'))
    assert_isfile(str(pkgs / 'osgeo' / 'abc.txt'))
    assert_isfile(str(pkgs / 'osgeo' / 'def.txt'))
Ejemplo n.º 17
0
def test_console_example():
    responses.add_callback('GET', re.compile(r'https://www.python.org/ftp/.*'),
        callback=respond_python_zip, content_type='application/zip',
    )

    with TemporaryWorkingDirectory() as td:
        for src in example_dir.iterdir():
            copy(str(src), td)


        with modified_env({CACHE_ENV_VAR: td}), \
             MockCommand('makensis') as makensis:
            ec = main(['installer.cfg'])

        assert ec == 0
        assert makensis.get_calls()[0]['argv'][1].endswith('installer.nsi')

        build_dir = Path(td, 'build', 'nsis')
        assert_isdir(build_dir)
        assert_isfile(build_dir / 'Python' / 'python.exe')
        assert_isfile(build_dir / 'pkgs' / 'guessnumber.py')
        assert_isfile(build_dir / 'Guess_the_Number.launch.py')
Ejemplo n.º 18
0
 def test_entry_points(self):
     Installer(samples_dir / 'entrypoints_valid.ini').install_directly()
     assert_isfile(self.tmpdir / 'site-packages' /
                   'package1-0.1.dist-info' / 'entry_points.txt')
Ejemplo n.º 19
0
 def test_install_package(self):
     Installer(samples_dir / 'package1-pkg.ini').install_directly()
     assert_isdir(self.tmpdir / 'site-packages' / 'package1')
     assert_isdir(self.tmpdir / 'site-packages' / 'package1-0.1.dist-info')
     assert_isfile(self.tmpdir / 'scripts' / 'pkg_script')
Ejemplo n.º 20
0
def test_get_ipython_module_path():
    ipapp_path = paths.get_ipython_module_path('IPython.terminal.ipapp')
    assert_isfile(ipapp_path)
Ejemplo n.º 21
0
def test_sampledir():
    with TemporaryDirectory() as td:
        td = Path(td)
        html.convert_directory(sample_dir, td)

        assert_isfile(td / '01-introduction.html')
Ejemplo n.º 22
0
 def test_pth_package(self):
     Installer(samples_dir / 'package1-pkg.ini', pth=True).install()
     assert_isfile(self.tmpdir / 'site-packages' / 'package1.pth')
     with open(str(self.tmpdir / 'site-packages' / 'package1.pth')) as f:
         assert f.read() == str(samples_dir)
     assert_isfile(self.tmpdir / 'scripts' / 'pkg_script')
Ejemplo n.º 23
0
def test_dist_name():
    clear_samples_dist()
    WheelBuilder(samples_dir / 'altdistname.ini').build()
    assert_isfile(samples_dir / 'dist/packagedist1-0.1-py2.py3-none-any.whl')
Ejemplo n.º 24
0
 def test_copy_application(self):
     self.installer.copy_application()
     d = pjoin(self.td, 'installed-applications', 'sampleapp')
     testpath.assert_isdir(d)
     testpath.assert_isfile(pjoin(d, 'run.sh'))
Ejemplo n.º 25
0
def test_make_sdist_pep621(tmp_path):
    builder = sdist.SdistBuilder.from_ini_path(samples_dir / 'pep621' / 'pyproject.toml')
    path = builder.build(tmp_path)
    assert path == tmp_path / 'module1-0.1.tar.gz'
    assert_isfile(path)
Ejemplo n.º 26
0
def test_wheel_package():
    clear_samples_dist()
    wheel_main(samples_dir / 'package1-pkg.ini')
    assert_isfile(samples_dir / 'dist/package1-0.1-py2.py3-none-any.whl')
Ejemplo n.º 27
0
 def test_symlink_package(self):
     Installer(samples_dir / 'package1-pkg.ini', symlink=True).install()
     assert_islink(self.tmpdir / 'site-packages' / 'package1',
                   to=str(samples_dir / 'package1'))
     assert_isfile(self.tmpdir / 'scripts' / 'pkg_script')
Ejemplo n.º 28
0
 def test_install_package(self):
     Installer(samples_dir / 'package1-pkg.ini').install()
     assert_isdir(self.tmpdir / 'site-packages' / 'package1')
     assert_isdir(self.tmpdir / 'site-packages' / 'package1-0.1.dist-info')
     assert_isfile(self.tmpdir / 'scripts' / 'pkg_script')
Ejemplo n.º 29
0
 def test_install_module(self):
     Installer(samples_dir / 'module1-pkg.ini').install()
     assert_isfile(self.tmpdir / 'site-packages' / 'module1.py')
     assert_isdir(self.tmpdir / 'site-packages' / 'module1-0.1.dist-info')
Ejemplo n.º 30
0
def test_wheel_module(copy_sample):
    td = copy_sample('module1_toml')
    make_wheel_in(td / 'pyproject.toml', td)
    assert_isfile(td / 'module1-0.1-py2.py3-none-any.whl')
Ejemplo n.º 31
0
def test_build_wheel():
    with TemporaryDirectory() as td, cwd(osp.join(samples_dir, 'pep517')):
        filename = buildapi.build_wheel(td)
        assert filename.endswith('.whl'), filename
        assert_isfile(osp.join(td, filename))
        assert zipfile.is_zipfile(osp.join(td, filename))
Ejemplo n.º 32
0
def test_build_sdist():
    with TemporaryDirectory() as td, cwd(osp.join(samples_dir, 'pep517')):
        filename = buildapi.build_sdist(td)
        assert filename.endswith('.tar.gz'), filename
        assert_isfile(osp.join(td, filename))
        assert tarfile.is_tarfile(osp.join(td, filename))
Ejemplo n.º 33
0
def test_make_sdist(tmp_path):
    # Smoke test of making a complete sdist
    builder = sdist.SdistBuilder.from_ini_path(samples_dir / 'package1.toml')
    builder.build(tmp_path)
    assert_isfile(tmp_path / 'package1-0.1.tar.gz')
Ejemplo n.º 34
0
def test_dist_name():
    clear_samples_dist()
    WheelBuilder(samples_dir / "altdistname.ini").build()
    assert_isfile(samples_dir / "dist/packagedist1-0.1-py2.py3-none-any.whl")
Ejemplo n.º 35
0
def test_wheel_package():
    clear_samples_dist()
    WheelBuilder(samples_dir / 'package1-pkg.ini').build()
    assert_isfile(samples_dir / 'dist/package1-0.1-py2.py3-none-any.whl')
Ejemplo n.º 36
0
def test_licenses_dir(tmp_path):
    # Smoketest for https://github.com/takluyver/flit/issues/399
    info = make_wheel_in(samples_dir / 'inclusion' / 'pyproject.toml', tmp_path)
    assert_isfile(info.file)
Ejemplo n.º 37
0
def test_get_ipython_module_path():
    ipapp_path = paths.get_ipython_module_path('IPython.terminal.ipapp')
    assert_isfile(ipapp_path)
Ejemplo n.º 38
0
def test_wheel_package():
    clear_samples_dist()
    WheelBuilder(samples_dir / "package1-pkg.ini").build()
    assert_isfile(samples_dir / "dist/package1-0.1-py2.py3-none-any.whl")
Ejemplo n.º 39
0
def test_dist_name():
    clear_samples_dist()
    wheel_main(samples_dir / 'altdistname.ini')
    assert_isfile(samples_dir / 'dist/packagedist1-0.1-py2.py3-none-any.whl')
Ejemplo n.º 40
0
 def test_symlink_package(self):
     Installer(samples_dir / 'package1-pkg.ini', symlink=True).install()
     assert_islink(self.tmpdir / 'site-packages' / 'package1',
                   to=str(samples_dir / 'package1'))
     assert_isfile(self.tmpdir / 'scripts' / 'pkg_script')
Ejemplo n.º 41
0
def test_wheel_package(copy_sample):
    td = copy_sample('package1')
    wheel_main(td / 'flit.ini')
    assert_isfile(td / 'dist/package1-0.1-py2.py3-none-any.whl')
Ejemplo n.º 42
0
def test_sampledir():
    with TemporaryDirectory() as td:
        td = Path(td)
        latex.combine_and_convert(sample_dir, td / 'combined.pdf', pdf=True)

        assert_isfile(td / 'combined.pdf')
Ejemplo n.º 43
0
 def test_install_module(self):
     Installer(samples_dir / 'module1-pkg.ini').install_directly()
     assert_isfile(self.tmpdir / 'site-packages' / 'module1.py')
     assert_isdir(self.tmpdir / 'site-packages' / 'module1-0.1.dist-info')
Ejemplo n.º 44
0
 def test_entry_points(self):
     Installer(samples_dir / 'entrypoints_valid.ini').install()
     assert_isfile(self.tmpdir / 'site-packages' / 'package1-0.1.dist-info' / 'entry_points.txt')
Ejemplo n.º 45
0
def test_copy_windows(tmpdir):
    tmpdir = str(tmpdir)
    copy_modules(['win_extmod', 'win_extpkg'], tmpdir, running_python, sample_path)
    assert_isfile(pjoin(tmpdir, 'win_extmod.pyd'))
    assert_isdir(pjoin(tmpdir, 'win_extpkg'))
Ejemplo n.º 46
0
def test_dist_name():
    clear_samples_dist()
    wheel_main(samples_dir / 'altdistname.ini')
    assert_isfile(samples_dir / 'dist/packagedist1-0.1-py2.py3-none-any.whl')
Ejemplo n.º 47
0
def test_write_license():
    with TemporaryDirectory() as td:
        ib = init.IniterBase(td)
        ib.write_license('mit', 'Thomas Kluyver')
        assert_isfile(Path(td, 'LICENSE'))
Ejemplo n.º 48
0
def test_wheel_module(copy_sample):
    td = copy_sample('module1_ini')
    make_wheel_in(td / 'flit.ini', td)
    assert_isfile(td / 'module1-0.1-py2.py3-none-any.whl')
Ejemplo n.º 49
0
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')
Ejemplo n.º 50
0
def test_sampledir():
    with TemporaryDirectory() as td:
        td = Path(td)
        latex.combine_and_convert(sample_dir, td / 'combined.pdf', pdf=True)

        assert_isfile(td / 'combined.pdf')
Ejemplo n.º 51
0
def test_wheel_package():
    clear_samples_dist()
    wheel_main(samples_dir / 'package1-pkg.ini')
    assert_isfile(samples_dir / 'dist/package1-0.1-py2.py3-none-any.whl')