def test_medium_load_config_no_directory(mock_home): global_config_file = mock_home / GLOBAL_CONFIG global_config_file.parent.mkdir(parents=True) global_config_file.write_text( """ [general] allow_uninitiated_workspaces = true remote_root = "my-remotes" [[hosts]] host = "test-host.example.com" """ ) workspace = mock_home / "foo" / "bar" medium = TomlConfigurationMedium() config = medium.load_config(workspace) # The path is randomly generated so we need to replace it config.root = Path(str(config.root).replace(str(mock_home), "/root")) assert config == WorkspaceConfig( root=Path("/root/foo/bar"), configurations=[ RemoteConfig( host="test-host.example.com", directory=Path(f"my-remotes/bar_{hash_path(workspace)}"), shell="sh", shell_options="", ) ], default_configuration=0, ignores=SyncRules(pull=[], push=[], both=[".remote.toml"]), includes=SyncRules(pull=[], push=[], both=[]), )
def test_ignores_compilation(): # Each collection should extend from both when compiling ignores = SyncRules(push=["push_1", "push_2"], pull=["pull_1", "both_1"], both=["both_1", "both_2"]) assert ignores.compile_pull() == ["both_1", "both_2", "pull_1"] assert ignores.compile_push() == ["both_1", "both_2", "push_1", "push_2"]
def test_check_adding_patter_extends_both(): ignores = SyncRules(push=["push_1", "push_2"], pull=["pull_1", "both_1"], both=["both_1", "both_3"]) ignores.add(["both_2"]) assert ignores.pull == ["both_1", "pull_1"] assert ignores.push == ["push_1", "push_2"] assert ignores.both == ["both_1", "both_2", "both_3"]
def test_medium_load_config_picks_up_vsc_ignore_files(mock_home): text = """ [[hosts]] host = "test-host.example.com" port = 2022 directory = ".remotes/workspace" default = true [push] exclude = ["env", ".git"] [pull] include_vsc_ignore_patterns = true [both] exclude = ["build"] include_vcs_ignore_patterns = true """ workspace = mock_home / "foo" / "bar" local_config_file = workspace / WORKSPACE_CONFIG local_config_file.parent.mkdir(parents=True) local_config_file.write_text(text) ignore_file = workspace / ".gitignore" ignore_file.write_text(""" # comment # Comment *.pattern # comment pattern_two """) medium = TomlConfigurationMedium() config = medium.load_config(workspace) # The path is randomly generated so we need to replace it config.root = Path(str(config.root).replace(str(mock_home), "/root")) assert config == WorkspaceConfig( root=Path("/root/foo/bar"), configurations=[ RemoteConfig(host="test-host.example.com", directory=Path(".remotes/workspace"), port=2022) ], default_configuration=0, ignores=SyncRules( pull=["*.pattern", "pattern_two"], push=[".git", "env"], both=["build", ".remote.toml", "*.pattern", "pattern_two"], ), includes=SyncRules(pull=[], push=[], both=[]), )
def test_empty_ignore(): # new ignores object is created empty ignores = SyncRules.new() assert not ignores.pull assert not ignores.push assert not ignores.both assert ignores.is_empty() assert not ignores.compile_push() assert not ignores.compile_pull() # if we add something it is not empty anymore ignores.pull.append("my_pattern") assert not ignores.is_empty()
def test_medium_load_minimal_config(tmp_path): (tmp_path / CONFIG_FILE_NAME).write_text("test-host.example.com:remote/dir") medium = ClassicConfigurationMedium() config = medium.load_config(tmp_path) assert config.root == tmp_path assert config.default_configuration == 0 assert len(config.configurations) == 1 assert config.configurations[0] == RemoteConfig( host="test-host.example.com", directory=Path("remote/dir"), shell="sh", shell_options="" ) # Ignore is always pre-populated even if it's empy in FS assert config.ignores == SyncRules(pull=[], push=[], both=[CONFIG_FILE_NAME, IGNORE_FILE_NAME, INDEX_FILE_NAME])
def test_medium_load_extensive_config(tmp_path): (tmp_path / CONFIG_FILE_NAME).write_text( """\ # First host test-host.example.com:remote/dir # Second host other-host.example.com:other/dir RSHELL=bash RSHELL_OPTS=options # Third host third-host.example.com:.remote/dir RSHELL=zsh """ ) (tmp_path / INDEX_FILE_NAME).write_text("3") (tmp_path / IGNORE_FILE_NAME).write_text( f"""\ push: .git *.pyc __pycache__ pull: src/generated both: build {CONFIG_FILE_NAME} {IGNORE_FILE_NAME} """ ) medium = ClassicConfigurationMedium() config = medium.load_config(tmp_path) assert config.root == tmp_path assert config.default_configuration == 2 assert len(config.configurations) == 3 assert config.configurations == [ RemoteConfig(host="test-host.example.com", directory=Path("remote/dir"), shell="sh", shell_options=""), RemoteConfig(host="other-host.example.com", directory=Path("other/dir"), shell="bash", shell_options="options"), RemoteConfig(host="third-host.example.com", directory=Path(".remote/dir"), shell="zsh", shell_options=""), ] assert config.ignores == SyncRules( pull=["src/generated"], push=[".git", "*.pyc", "__pycache__"], both=["build", CONFIG_FILE_NAME, IGNORE_FILE_NAME, INDEX_FILE_NAME], )
[pull] exclude = ["src/generated"] [both] exclude = ["build"] """, None, WorkspaceConfig( root=Path("/root/foo/bar"), configurations=[ RemoteConfig(host="test-host.example.com", directory=Path("my-remotes/foo/bar",), label="bar"), RemoteConfig(host="other-host.example.com", directory=Path("my-remotes/foo/bar"), label="foo"), ], default_configuration=1, ignores=SyncRules(pull=["src/generated"], push=[".git", "env"], both=["build", ".remote.toml"]), includes=SyncRules(pull=[], push=["env"], both=[]), ), ), # Settings from local config overwrite global ones ( """\ [general] use_relative_remote_paths = true [[hosts]] host = "other-host.example.com" default = true label = "bar" [push]