def test_repeated_defs_fail(self, monkeypatch): with monkeypatch.context() as m: m.setattr( sys, "argv", [""], ) with pytest.raises(_SpockInstantiationError): config = ConfigArgBuilder(RepeatedDefsFailConfig, NestedListStuff, desc="Test Builder") config.generate()
def arg_builder(monkeypatch): with monkeypatch.context() as m: m.setattr(sys, 'argv', ['', '--config', './tests/conf/json/test.json']) config = ConfigArgBuilder(TypeConfig, TypeOptConfig, TypeDefaultConfig, TypeDefaultOptConfig, desc='Test Builder') return config.generate()
def test_raises_missing_class(self, monkeypatch): with monkeypatch.context() as m: m.setattr(sys, "argv", ["", "--config", "./tests/conf/yaml/test.yaml"]) with pytest.raises(ValueError): config = ConfigArgBuilder(*all_configs[:-1]) return config.generate()
def arg_builder(monkeypatch): with monkeypatch.context() as m: m.setattr(sys, 'argv', [ '', '--config', './tests/conf/yaml/test_class.yaml', '--TypeConfig.bool_p', '--TypeConfig.int_p', '11', '--TypeConfig.float_p', '11.0', '--TypeConfig.string_p', 'Hooray', '--TypeConfig.list_p_float', '[11.0,21.0]', '--TypeConfig.list_p_int', '[11, 21]', '--TypeConfig.list_p_str', "['Hooray', 'Working']", '--TypeConfig.list_p_bool', '[False, True]', '--TypeConfig.tuple_p_float', '(11.0, 21.0)', '--TypeConfig.tuple_p_int', '(11, 21)', '--TypeConfig.tuple_p_str', "('Hooray', 'Working')", '--TypeConfig.tuple_p_bool', '(False, True)', '--TypeConfig.list_list_p_int', "[[11, 21], [11, 21]]", '--TypeConfig.choice_p_str', 'option_2', '--TypeConfig.choice_p_int', '20', '--TypeConfig.choice_p_float', '20.0', '--TypeConfig.list_choice_p_str', "['option_2']", '--TypeConfig.list_list_choice_p_str', "[['option_2'], ['option_2']]", '--TypeConfig.list_choice_p_int', '[20]', '--TypeConfig.list_choice_p_float', '[20.0]', '--NestedStuff.one', '12', '--NestedStuff.two', 'ancora', '--TypeConfig.nested_list.NestedListStuff.one', '[11, 21]', '--TypeConfig.nested_list.NestedListStuff.two', "['Hooray', 'Working']", ]) config = ConfigArgBuilder(TypeConfig, NestedStuff, NestedListStuff, desc='Test Builder') return config.generate()
def arg_builder(monkeypatch): with monkeypatch.context() as m: config = ConfigArgBuilder( *all_configs, no_cmd_line=True, configs=["./tests/conf/yaml/test.yaml"], ) return config.generate()
def test_callable_module(self, monkeypatch): with monkeypatch.context() as m: m.setattr( sys, "argv", ["", "--config", "./tests/conf/yaml/test_fail_callable.yaml"]) with pytest.raises(_SpockValueError): config = ConfigArgBuilder(*all_configs) return config.generate()
def arg_builder(monkeypatch): with monkeypatch.context() as m: m.setattr(sys, "argv", [""]) config = ConfigArgBuilder( *all_configs, desc="Test Builder", configs=["./tests/conf/yaml/test.yaml"], ) return config.generate()
def arg_builder(monkeypatch): with monkeypatch.context() as m: m.setattr(sys, 'argv', ['', '--config', './tests/conf/yaml/inherited.yaml']) config = ConfigArgBuilder(TypeInherited, NestedStuff, NestedListStuff, desc='Test Builder') return config.generate()
def test_cmd_line_kwarg_raise(self, monkeypatch): with monkeypatch.context() as m: with pytest.raises(TypeError): config = ConfigArgBuilder( *all_configs, no_cmd_line=True, configs="./tests/conf/yaml/test.yaml", ) return config.generate()
def arg_builder(monkeypatch): with monkeypatch.context() as m: config = ConfigArgBuilder(TypeConfig, NestedStuff, NestedListStuff, TypeOptConfig, no_cmd_line=True, configs=['./tests/conf/yaml/test.yaml']) return config.generate()
def arg_builder(monkeypatch): with monkeypatch.context() as m: m.setattr( sys, "argv", [ "", "--config", "./tests/conf/yaml/test_class.yaml", "--TypeConfig.bool_p", "--TypeConfig.int_p", "11", "--TypeConfig.float_p", "11.0", "--TypeConfig.string_p", "Hooray", "--TypeConfig.list_p_float", "[11.0,21.0]", "--TypeConfig.list_p_int", "[11, 21]", "--TypeConfig.list_p_str", "['Hooray', 'Working']", "--TypeConfig.list_p_bool", "[False, True]", "--TypeConfig.tuple_p_float", "(11.0, 21.0)", "--TypeConfig.tuple_p_int", "(11, 21)", "--TypeConfig.tuple_p_str", "('Hooray', 'Working')", "--TypeConfig.tuple_p_bool", "(False, True)", "--TypeConfig.tuple_p_mixed", "(5, 11.5)", "--TypeConfig.list_list_p_int", "[[11, 21], [11, 21]]", "--TypeConfig.choice_p_str", "option_2", "--TypeConfig.choice_p_int", "20", "--TypeConfig.choice_p_float", "20.0", "--TypeConfig.list_choice_p_str", "['option_2']", "--TypeConfig.list_list_choice_p_str", "[['option_2'], ['option_2']]", "--TypeConfig.list_choice_p_int", "[20]", "--TypeConfig.list_choice_p_float", "[20.0]", "--TypeConfig.class_enum", "NestedStuff", "--NestedStuff.one", "12", "--NestedStuff.two", "ancora", "--TypeConfig.nested_list.NestedListStuff.one", "[11, 21]", "--TypeConfig.nested_list.NestedListStuff.two", "['Hooray', 'Working']", "--TypeConfig.high_config", "SingleNestedConfig", "--SingleNestedConfig.double_nested_config", "SecondDoubleNestedConfig", "--SecondDoubleNestedConfig.morph_tolerance", "0.2", "--TypeConfig.call_me", 'tests.base.attr_configs_test.bar', "--TypeConfig.call_us", "['tests.base.attr_configs_test.bar', 'tests.base.attr_configs_test.bar']", "--TypeConfig.str_dict", "{'key_1': 2.5, 'key_2': 3.5}", "--TypeConfig.int_list_str_dict", "{'1': ['again', 'test'], '2': ['test', 'me']}", "--TypeConfig.float_tuple_callable_dict", '{"1.0": ("tests.base.attr_configs_test.bar", "tests.base.attr_configs_test.foo"), "2.0": ("tests.base.attr_configs_test.bar", "tests.base.attr_configs_test.foo")}', "--TypeConfig.hardest", '[{"key_1": ("tests.base.attr_configs_test.bar", "tests.base.attr_configs_test.foo"), "key_2": ("tests.base.attr_configs_test.bar", "tests.base.attr_configs_test.foo")}, {"key_3": ("tests.base.attr_configs_test.bar", "tests.base.attr_configs_test.foo"), "key_4": ("tests.base.attr_configs_test.bar", "tests.base.attr_configs_test.foo")}]' ], ) config = ConfigArgBuilder(TypeConfig, NestedStuff, NestedListStuff, SingleNestedConfig, FirstDoubleNestedConfig, SecondDoubleNestedConfig, desc="Test Builder") return config.generate()
def test_wrong_input_raise(self, monkeypatch): with monkeypatch.context() as m: m.setattr(sys, "argv", ["", "--config", "./tests/conf/yaml/test.foo"]) with pytest.raises(TypeError): config = ConfigArgBuilder( *all_configs, desc="Test Builder", ) return config.generate()
def arg_builder(monkeypatch): with monkeypatch.context() as m: m.setattr(sys, 'argv', ['', '--config', './tests/conf/toml/test.toml']) config = ConfigArgBuilder(TypeConfig, NestedStuff, NestedListStuff, TypeOptConfig, desc='Test Builder') return config.generate()
def test_wrong_input_raise(self, monkeypatch): with monkeypatch.context() as m: m.setattr(sys, 'argv', ['', '--config', './tests/conf/yaml/test.foo']) with pytest.raises(ValueError): config = ConfigArgBuilder(TypeConfig, NestedStuff, NestedListStuff, TypeOptConfig, desc='Test Builder') return config.generate()
def test_repr(self, monkeypatch, capsys): with monkeypatch.context() as m: m.setattr(sys, "argv", ["", "--config", "./tests/conf/yaml/test.yaml"]) config = ConfigArgBuilder( *all_configs, desc="Test Builder", ) print(config.generate()) out, _ = capsys.readouterr() assert ("NestedListStuff" in out) and "TypeConfig" in out
def test_help(self, monkeypatch): with monkeypatch.context() as m: m.setattr( sys, "argv", ["", "--config", "./tests/conf/yaml/test.yaml", "--help"]) with pytest.raises(SystemExit): config = ConfigArgBuilder( *all_configs, desc="Test Builder", ) return config.generate()
def test_cmd_line_kwarg_raise(self, monkeypatch): with monkeypatch.context() as m: with pytest.raises(ValueError): config = ConfigArgBuilder( TypeConfig, NestedStuff, NestedListStuff, TypeOptConfig, no_cmd_line=True, configs='./tests/conf/yaml/test.yaml') return config.generate()
def test_repr(self, monkeypatch, capsys): with monkeypatch.context() as m: m.setattr(sys, 'argv', ['', '--config', './tests/conf/yaml/test.yaml']) config = ConfigArgBuilder(TypeConfig, NestedStuff, NestedListStuff, TypeOptConfig, desc='Test Builder') print(config.generate()) out, _ = capsys.readouterr() assert ('NestedListStuff' in out) and 'TypeConfig' in out
def test_cmd_line_no_key(self, monkeypatch): with monkeypatch.context() as m: m.setattr(sys, 'argv', [ '', '--config', './tests/conf/yaml/test.yaml', '--TypeConfig.foo_bar_stuff', '11' ]) with pytest.raises(SystemExit): config = ConfigArgBuilder(TypeConfig, NestedStuff, NestedListStuff, desc='Test Builder') return config.generate()
def test_help(self, monkeypatch): with monkeypatch.context() as m: m.setattr( sys, 'argv', ['', '--config', './tests/conf/yaml/test.yaml', '--help']) with pytest.raises(SystemExit): config = ConfigArgBuilder(TypeConfig, NestedStuff, NestedListStuff, TypeOptConfig, desc='Test Builder') return config.generate()
def test_cmd_line_list_len(self, monkeypatch): with monkeypatch.context() as m: m.setattr(sys, 'argv', [ '', '--config', './tests/conf/yaml/test.yaml', '--TypeConfig.nested_list.NestedListStuff.one', '[11]' ]) with pytest.raises(ValueError): config = ConfigArgBuilder(TypeConfig, NestedStuff, NestedListStuff, desc='Test Builder') return config.generate()
def test_non_attrs_fail(self, monkeypatch): with monkeypatch.context() as m: with pytest.raises(TypeError): class AttrFail: failed_attr: int config = ConfigArgBuilder( *all_configs, AttrFail, configs=["./tests/conf/yaml/test.yaml"], ) return config.generate()
def test_dynamic_raise(self, monkeypatch): with monkeypatch.context() as m: m.setattr(sys, "argv", [""]) with pytest.raises(_SpockUndecoratedClass): @spock class TestConfigDefaultsFail(Foo, Bar): x: int = 235 y: str = 'yarghhh' z: List[int] = [10, 20] config = ConfigArgBuilder(TestConfigDefaultsFail) return config.generate()
def test_raises_missing_class(self, monkeypatch): with monkeypatch.context() as m: m.setattr( sys, "argv", ["", "--config", "./tests/conf/yaml/test_fail_dict_key.yaml"]) with pytest.raises(TypeError): @spock class FailDictKey: # Dict w/ int keys -- List of strings int_list_str_dict: Dict[int, List[str]] config = ConfigArgBuilder(FailDictKey) return config.generate()
def test_non_attrs_fail(self, monkeypatch): with monkeypatch.context() as m: with pytest.raises(TypeError): class AttrFail: failed_attr: int config = ConfigArgBuilder( TypeConfig, NestedStuff, NestedListStuff, TypeOptConfig, AttrFail, configs=['./tests/conf/yaml/test.yaml']) return config.generate()
def arg_builder(monkeypatch, s3): with monkeypatch.context() as m: aws_session, s3_client = s3 # Mock a S3 bucket and object mock_s3_bucket = "spock-test" mock_s3_object = "fake/test/bucket/pytest.s3load.yaml" s3_client.create_bucket(Bucket=mock_s3_bucket) s3_client.upload_file("./tests/conf/yaml/test.yaml", mock_s3_bucket, mock_s3_object) m.setattr( sys, "argv", ["", "--config", f"s3://{mock_s3_bucket}/{mock_s3_object}"]) config = ConfigArgBuilder( *all_configs, s3_config=S3Config(session=aws_session, s3_session=s3_client), desc="Test Builder", ) return config.generate()
def test_cmd_line_no_key(self, monkeypatch): with monkeypatch.context() as m: m.setattr( sys, "argv", [ "", "--config", "./tests/conf/yaml/test.yaml", "--TypeConfig.foo_bar_stuff", "11", ], ) with pytest.raises(SystemExit): config = ConfigArgBuilder(TypeConfig, NestedStuff, NestedListStuff, SingleNestedConfig, FirstDoubleNestedConfig, SecondDoubleNestedConfig, desc="Test Builder") return config.generate()
def test_cmd_line_list_len(self, monkeypatch): with monkeypatch.context() as m: m.setattr( sys, "argv", [ "", "--config", "./tests/conf/yaml/test.yaml", "--TypeConfig.nested_list.NestedListStuff.one", "[11]", ], ) with pytest.raises(ValueError): config = ConfigArgBuilder(TypeConfig, NestedStuff, NestedListStuff, SingleNestedConfig, FirstDoubleNestedConfig, SecondDoubleNestedConfig, desc="Test Builder") return config.generate()
def arg_builder(monkeypatch): with monkeypatch.context() as m: m.setattr(sys, "argv", [""]) config = ConfigArgBuilder(ConfigDynamicDefaults) return config.generate()
def test_lazy_raise(self, monkeypatch): with monkeypatch.context() as m: m.setattr(sys, "argv", [""]) with pytest.raises(_SpockNotOptionalError): config = ConfigArgBuilder(RaiseNotDecorated, lazy=False) config.generate()