test\unit\test_config.py
-- -- --- --- --- --- --- --- ------- ------- ------- | import os.path
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | import pytest
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | import wily.config
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 | def test_config_empty_defaults(tmpdir):
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | """
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | Test that an empty config path sets to defaults.
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | """
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | config = """
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | """
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | config_path = os.path.join(tmpdir, "wily.cfg")
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | with open(config_path, "w") as config_f:
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | config_f.write(config)
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | cfg = wily.config.load(config_path)
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | assert cfg.archiver == wily.config.DEFAULT_ARCHIVER
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | assert cfg.operators == wily.config.DEFAULT_OPERATORS
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | assert cfg.max_revisions == wily.config.DEFAULT_MAX_REVISIONS
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 | def test_config_archiver(tmpdir):
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | """
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | Test that an archiver can be configured
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | """
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | config = """
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | [wily]
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | archiver = foo
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | """
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | config_path = os.path.join(tmpdir, "wily.cfg")
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | with open(config_path, "w") as config_f:
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | config_f.write(config)
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | cfg = wily.config.load(config_path)
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | assert cfg.archiver == "foo"
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | assert cfg.operators == wily.config.DEFAULT_OPERATORS
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | assert cfg.max_revisions == wily.config.DEFAULT_MAX_REVISIONS
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | @pytest.mark.parametrize(
-- -- --- --- --- --- --- --- ------- ------- ------- | ("raw_operators", "expected_operators"),
-- -- --- --- --- --- --- --- ------- ------- ------- | [
-- -- --- --- --- --- --- --- ------- ------- ------- | ("foo,bar", ["foo", "bar"]),
-- -- --- --- --- --- --- --- ------- ------- ------- | ("foo, bar", ["foo", "bar"]),
-- -- --- --- --- --- --- --- ------- ------- ------- | ("foo, bar,", ["foo", "bar"]),
-- -- --- --- --- --- --- --- ------- ------- ------- | (" foo,bar , baz", ["foo", "bar", "baz"]),
-- -- --- --- --- --- --- --- ------- ------- ------- | ],
-- -- --- --- --- --- --- --- ------- ------- ------- | )
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 | def test_config_operators(tmpdir, raw_operators, expected_operators):
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | """
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | Test that operators can be configured
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | """
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | config = f"""
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | [wily]
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | operators = {raw_operators}
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | """
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | config_path = os.path.join(tmpdir, "wily.cfg")
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | with open(config_path, "w") as config_f:
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | config_f.write(config)
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | cfg = wily.config.load(config_path)
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | assert cfg.archiver == wily.config.DEFAULT_ARCHIVER
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | assert cfg.operators == expected_operators
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | assert cfg.max_revisions == wily.config.DEFAULT_MAX_REVISIONS
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 | def test_config_max_revisions(tmpdir):
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | """
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | Test that an max-revisions can be configured
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | """
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | config = """
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | [wily]
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | max_revisions = 14
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | """
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | config_path = os.path.join(tmpdir, "wily.cfg")
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | with open(config_path, "w") as config_f:
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | config_f.write(config)
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | cfg = wily.config.load(config_path)
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 |
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | assert cfg.archiver == wily.config.DEFAULT_ARCHIVER
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | assert cfg.operators == wily.config.DEFAULT_OPERATORS
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | assert cfg.max_revisions == 14
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 01 001 006 003 006 007 009 0025.27 0012.63 0000.50 | def test_config_cache_path(tmpdir):
-- -- 001 006 003 006 007 009 0025.27 0012.63 0000.50 | """
-- -- --- --- --- --- --- --- ------- ------- ------- | Test that a cache-path can be configured
-- -- --- --- --- --- --- --- ------- ------- ------- | """
-- -- --- --- --- --- --- --- ------- ------- ------- | config = """
-- -- --- --- --- --- --- --- ------- ------- ------- | [wily]
-- -- --- --- --- --- --- --- ------- ------- ------- | cache_path = .wily/
-- -- --- --- --- --- --- --- ------- ------- ------- | """
-- -- --- --- --- --- --- --- ------- ------- ------- | config_path = os.path.join(tmpdir, "wily.cfg")
-- -- --- --- --- --- --- --- ------- ------- ------- | with open(config_path, "w") as config_f:
-- -- --- --- --- --- --- --- ------- ------- ------- | config_f.write(config)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | cfg = wily.config.load(config_path)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | assert cfg.archiver == wily.config.DEFAULT_ARCHIVER
-- -- --- --- --- --- --- --- ------- ------- ------- | assert cfg.operators == wily.config.DEFAULT_OPERATORS
-- -- --- --- --- --- --- --- ------- ------- ------- | assert cfg.cache_path == ".wily/"