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_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')
}
def test_init():
responses = ['foo', # Module name
'Test Author', # Author
'test@example.com', # Author email
'http://example.com/', # Home page
'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
def test_pip_install(self):
ins = Installer.from_ini_path(samples_dir / 'package1' / 'pyproject.toml', python='mock_python',
user=False)
with MockCommand('mock_python') as mock_py:
ins.install()
calls = mock_py.get_calls()
assert len(calls) == 1
cmd = calls[0]['argv']
assert cmd[1:4] == ['-m', 'pip', 'install']
assert cmd[4].endswith('package1')
def test_install_requires(self):
ins = Installer.from_ini_path(samples_dir / 'requires-requests.toml',
user=False, python='mock_python')
with MockCommand('mock_python') as mockpy:
ins.install_requirements()
calls = mockpy.get_calls()
assert len(calls) == 1
assert calls[0]['argv'][1:5] == ['-m', 'pip', 'install', '-r']
def test_install_module(self):
Installer.from_ini_path(samples_dir / 'module1_toml' / 'pyproject.toml').install_directly()
assert_isfile(self.tmpdir / 'site-packages' / 'module1.py')
assert_isdir(self.tmpdir / 'site-packages' / 'module1-0.1.dist-info')
self._assert_direct_url(
samples_dir / 'module1_toml', 'module1', '0.1', expected_editable=False
)
def test_entry_points(self):
Installer.from_ini_path(samples_dir / 'entrypoints_valid' / 'pyproject.toml').install_directly()
assert_isfile(self.tmpdir / 'site-packages' / 'package1-0.1.dist-info' / 'entry_points.txt')
def test_install_package(self):
oldcwd = os.getcwd()
os.chdir(str(samples_dir / 'package1'))
try:
Installer.from_ini_path(pathlib.Path('pyproject.toml')).install_directly()
finally:
os.chdir(oldcwd)
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')
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=False
)
def test_extras_error(self):
with pytest.raises(DependencyError):
Installer.from_ini_path(samples_dir / 'requires-requests.toml',
user=False, deps='none', extras='dev')
def test_dist_name(self):
Installer.from_ini_path(samples_dir / 'altdistname' / 'pyproject.toml').install_directly()
assert_isdir(self.tmpdir / 'site-packages' / 'package1')
assert_isdir(self.tmpdir / 'site-packages' / 'package_dist1-0.1.dist-info')
def test_pth_package(self):
Installer.from_ini_path(samples_dir / 'package1' / 'pyproject.toml', 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 / 'package1')
assert_isfile(self.tmpdir / 'scripts' / 'pkg_script')
self._assert_direct_url(
samples_dir / 'package1', 'package1', '0.1', expected_editable=True
)