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_guess_module_name():
with make_dir(['foo.py', 'foo-bar.py', 'test_foo.py', 'setup.py']) as td:
ib = init.IniterBase(td)
assert ib.guess_module_name() == 'foo'
with make_dir(['baz/__init__.py', 'tests/__init__.py'], ['baz', 'tests']) as td:
ib = init.IniterBase(td)
assert ib.guess_module_name() == 'baz'
with make_dir(['src/foo.py', 'src/foo-bar.py', 'test_foo.py', 'setup.py'],
['src',]) as td:
ib = init.IniterBase(td)
assert ib.guess_module_name() == 'foo'
with make_dir(['src/baz/__init__.py', 'tests/__init__.py'], ['src', 'src/baz', 'tests']) as td:
ib = init.IniterBase(td)
assert ib.guess_module_name() == 'baz'
with make_dir(['foo.py', 'bar.py']) as td:
ib = init.IniterBase(td)
assert ib.guess_module_name() is None
with make_dir(['src/foo.py', 'src/bar.py'], ['src']) as td:
ib = init.IniterBase(td)
assert ib.guess_module_name() is None
def test_write_license():
with TemporaryDirectory() as td:
ib = init.IniterBase(td)
ib.write_license('mit', 'Thomas Kluyver')
assert_isfile(Path(td, 'LICENSE'))
with make_dir(['src/foo.py', 'src/foo-bar.py', 'test_foo.py', 'setup.py'],
['src',]) as td:
ib = init.IniterBase(td)
assert ib.guess_module_name() == 'foo'
with make_dir(['src/baz/__init__.py', 'tests/__init__.py'], ['src', 'src/baz', 'tests']) as td:
ib = init.IniterBase(td)
assert ib.guess_module_name() == 'baz'
with make_dir(['foo.py', 'bar.py']) as td:
ib = init.IniterBase(td)
assert ib.guess_module_name() is None
with make_dir(['src/foo.py', 'src/bar.py'], ['src']) as td:
ib = init.IniterBase(td)
assert ib.guess_module_name() is None
if any(new_defaults[k] != self.defaults.get(k) for k in new_defaults):
self.defaults.update(new_defaults)
store_defaults(self.defaults)
def write_license(self, name, author):
if (self.directory / 'LICENSE').exists():
return
year = date.today().year
with (license_templates_dir / name).open(encoding='utf-8') as f:
license_text = f.read()
with (self.directory / 'LICENSE').open('w', encoding='utf-8') as f:
f.write(license_text.format(year=year, author=author))
class TerminalIniter(IniterBase):
def prompt_text(self, prompt, default, validator, retry_msg="Try again."):
if default is not None:
p = "{} [{}]: ".format(prompt, default)
else:
p = prompt + ': '
while True:
response = input(p)
if response == '' and default is not None:
response = default
if validator(response):
return response
print(retry_msg)
def prompt_options(self, prompt, options, default=None):
default_ix = None