def test_pretend_move_old_package(tmpfolder, caplog, isolated_logger): # Given a package is already created without namespace create_project(project="proj", package="my_pkg") opts = parse_args( ["proj", "-p", "my_pkg", "--namespace", "my.ns", "--pretend"]) opts = process_opts(opts) configure_logger(opts) struct = dict(proj={'src': {'my_pkg': {'file.py': ''}}}) # when 'pretend' option is passed, struct, opts = get_default_options(struct, opts) struct, opts = enforce_namespace_options(struct, opts) struct, opts = move_old_package(struct, opts) # then nothing should happen, assert tmpfolder.join("proj/src/my_pkg/__init__.py").check() assert not tmpfolder.join("proj/src/my/ns").check() # something should be logged, log = caplog.text expected_log = ('move', 'my_pkg', 'to', 'my/ns') for text in expected_log: assert text in log # but user should see no warning, unexpected_warnings = ('A folder', 'exists in the project directory', 'a namespace option was passed', 'Please make sure') for text in unexpected_warnings: assert text not in log
def test_pretend_move_old_package(tmpfolder, caplog, isolated_logger): # Given a package is already created without namespace create_project(project="proj", package="my_pkg") opts = parse_args( ["proj", "-p", "my_pkg", "--namespace", "my.ns", "--pretend"]) opts = process_opts(opts) configure_logger(opts) struct = dict(proj={'src': {'my_pkg': {'file.py': ''}}}) # when 'pretend' option is passed, struct, opts = get_default_options(struct, opts) struct, opts = enforce_namespace_options(struct, opts) struct, opts = move_old_package(struct, opts) # then nothing should happen, assert tmpfolder.join("proj/src/my_pkg/__init__.py").check() assert not tmpfolder.join("proj/src/my/ns").check() # something should be logged, log = caplog.text expected_log = ('move', 'my_pkg', 'to', 'my/ns') for text in expected_log: assert text in log # but user should see no warning, unexpected_warnings = ('A folder', 'exists in the project directory', 'a namespace option was passed', 'Please make sure') for text in unexpected_warnings: assert text not in log
def test_configure_logger(monkeypatch, caplog, reset_logger): # Given an environment that supports color, monkeypatch.setattr('pyscaffold.termui.supports_color', lambda *_: True) # when configure_logger in called, opts = dict(log_level=logging.INFO) configure_logger(opts) # then the formatter should be changed to use colors, logger.report('some', 'activity') out = caplog.text assert ansi_regex('some').search(out)
def test_configure_logger(monkeypatch, caplog, reset_logger): # Given an environment that supports color, monkeypatch.setattr('pyscaffold.termui.supports_color', lambda *_: True) # when configure_logger in called, opts = dict(log_level=logging.INFO) configure_logger(opts) # then the formatter should be changed to use colors, logger.report('some', 'activity') out = caplog.text assert ansi_regex('some').search(out)
def test_configure_logger(monkeypatch, caplog): # Given an environment that supports color, monkeypatch.setattr('pyscaffold.termui.supports_color', lambda *_: True) # when configure_logger in called, opts = dict(log_level=logging.INFO) configure_logger(opts) # then the formatter should be changed to use colors, name = uniqstr() logger.report('some', name) out = caplog.messages[-1] assert re.search(ansi_pattern('some') + '.+' + name, out)
def test_configure_logger(monkeypatch, caplog): # Given an environment that supports color, monkeypatch.setattr('pyscaffold.termui.supports_color', lambda *_: True) # when configure_logger in called, opts = dict(log_level=logging.INFO) configure_logger(opts) # then the formatter should be changed to use colors, name = uniqstr() logger.report('some', name) out = caplog.text assert re.search(ansi_pattern('some') + '.+' + name, out)