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) logger.reconfigure(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", str(Path("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_move_old_package_without_namespace(tmpfolder): # Given a package is already created without namespace create_project(project="proj", package="my_pkg") opts = dict(project="proj", package="my_pkg") struct = dict(proj={"src": {"my_pkg": {"file.py": ""}}}) # when no 'namespace' 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 the old package remains, assert tmpfolder.join("proj/src/my_pkg/__init__.py").check()
def test_move_old_package_without_namespace(tmpfolder): # Given a package is already created without namespace create_project(project="proj", package="my_pkg") opts = dict(project="proj", package="my_pkg") struct = dict(proj={'src': {'my_pkg': {'file.py': ''}}}) # when no 'namespace' 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 the old package remains, assert tmpfolder.join("proj/src/my_pkg/__init__.py").check()
def test_move_old_package(tmpfolder): # Given a package is already created without namespace create_project(project="proj", package="my_pkg") assert tmpfolder.join("proj/src/my_pkg/__init__.py").check() opts = dict(project="proj", package="my_pkg", namespace="my.ns") struct = dict(proj={'src': {'my_pkg': {'file.py': ''}}}) # when the 'namespace' 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 the old package should be moved assert not tmpfolder.join("proj/src/my_pkg/__init__.py").check() assert tmpfolder.join("proj/src/my/ns/my_pkg/__init__.py").check()