Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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')
def test_write_license():
with TemporaryDirectory() as td:
ib = init.IniterBase(td)
ib.write_license('mit', 'Thomas Kluyver')
assert_isfile(Path(td, 'LICENSE'))
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
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
)
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'))
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
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
def test_entry_points(copy_sample):
td = copy_sample('entrypoints_valid')
make_wheel_in(td / 'flit.ini', td)
assert_isfile(td / 'package1-0.1-py2.py3-none-any.whl')
with unpack(td / 'package1-0.1-py2.py3-none-any.whl') as td_unpack:
entry_points = Path(td_unpack, '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()
'1' # License (1 -> MIT)
]
with TemporaryDirectory() as td, \
patch_data_dir(), \
faking_input(responses):
ti = init.TerminalIniter(td)
ti.initialise()
generated = Path(td) / 'pyproject.toml'
assert_isfile(generated)
with generated.open() as f:
data = pytoml.load(f)
assert data['tool']['flit']['metadata'][
'author-email'] == "test@example.com"
license = Path(td) / 'LICENSE'
assert_isfile(license)
with license.open() as f:
license_text = f.read()
assert license_text.startswith("The MIT License (MIT)")
assert "{year}" not in license_text
assert "Test Author" in license_text