def test_meta_append_bad(self): """ Test that the meta attribute "append" catches bad inputs. """ base = hammer_config.load_config_from_string(""" foo: bar: adc: "yes" dac: "no" dsl: "scala" """, is_yaml=True) meta = hammer_config.load_config_from_string(""" { "foo.bar.dsl": ["python"], "foo.bar.dsl_meta": "append", "foo.bar.dac": "current_weighted" } """, is_yaml=False) with self.assertRaises(ValueError): hammer_config.combine_configs([base, meta]) meta = hammer_config.load_config_from_string(""" { "foo.bar.dsl": "c++", "foo.bar.dsl_meta": "append", "foo.bar.dac": "current_weighted" } """, is_yaml=False) with self.assertRaises(ValueError): hammer_config.combine_configs([base, meta])
def test_no_json_yaml_precedence(self) -> None: """ Test that neither JSON nor YAML take precedence over each other. """ yfp, ypath = tempfile.mkstemp(".yml") with open(ypath, 'w') as fy: fy.write(""" foo.bar: "i'm yaml" """) jfp, jpath = tempfile.mkstemp(".json") with open(jpath, 'w') as fj: fj.write(""" { "foo.bar": "i'm json" } """) db1 = hammer_config.HammerDatabase() configs = hammer_config.load_config_from_paths([ypath, jpath]) db1.update_core([hammer_config.combine_configs(configs)]) self.assertEqual(db1.get_setting("foo.bar"), "i'm json") db2 = hammer_config.HammerDatabase() configs = hammer_config.load_config_from_paths([jpath, ypath]) db2.update_core([hammer_config.combine_configs(configs)]) self.assertEqual(db2.get_setting("foo.bar"), "i'm yaml")
def test_meta_append_bad(self) -> None: """ Test that the meta attribute "append" catches bad inputs. """ base = hammer_config.load_config_from_string(""" foo: bar: adc: "yes" dac: "no" dsl: "scala" """, is_yaml=True) meta = hammer_config.load_config_from_string(""" { "foo.bar.dsl": ["python"], "foo.bar.dsl_meta": "append", "foo.bar.dac": "current_weighted" } """, is_yaml=False) with self.assertRaises(ValueError): hammer_config.combine_configs([base, meta]) meta = hammer_config.load_config_from_string(""" { "foo.bar.dsl": "c++", "foo.bar.dsl_meta": "append", "foo.bar.dac": "current_weighted" } """, is_yaml=False) with self.assertRaises(ValueError): hammer_config.combine_configs([base, meta])
def project_config(self) -> dict: return hammer_config.combine_configs(self.project_configs)