def testValue(self):
     DataMiner().data_type = DataTypes.Value
     self.store_key()
     print(PersistentObjectStorage().storage_object)
     processor = DictProcessing(PersistentObjectStorage().storage_object)
     processor.simplify()
     self.assertIn(
         "'a': {'d': {'e': {'metadata'",
         str(PersistentObjectStorage().storage_object),
     )
예제 #2
0
 def testValue(self):
     self.cassette.data_miner.data_type = DataTypes.Value
     self.store_key()
     print(self.cassette.storage_object)
     processor = DictProcessing(self.cassette.storage_object)
     processor.simplify()
     self.assertIn(
         "'a': {'d': {'e': {'metadata'",
         str(self.cassette.storage_object),
     )
 def testDictWithList(self):
     DataMiner().data_type = DataTypes.DictWithList
     self.store_key()
     print(PersistentObjectStorage().storage_object)
     processor = DictProcessing(PersistentObjectStorage().storage_object)
     processor.simplify()
     self.assertIn(
         "'a': {'d': {'e': {'%s': [" % DataMiner().key,
         str(PersistentObjectStorage().storage_object),
     )
예제 #4
0
 def testDictWithList(self):
     self.cassette.data_miner.data_type = DataTypes.DictWithList
     self.store_key()
     print(self.cassette.storage_object)
     processor = DictProcessing(self.cassette.storage_object)
     processor.simplify()
     self.assertIn(
         "'a': {'d': {'e': {'%s': [" % self.cassette.data_miner.key,
         str(self.cassette.storage_object),
     )
예제 #5
0
def purge(replaces, files, dry_run, simplify):
    for one_file in files:
        click.echo(f"Processing file: {one_file.name}")
        object_representation = yaml.safe_load(one_file)
        processor = DictProcessing(object_representation)
        for item in replaces:
            click.echo(f"\tTry to apply: {item}")
            selector_str, key, type_of_value, value = item.split(":", 3)
            selector_list = [] if not selector_str else selector_str.split("%")
            # retype the output object to proper type ()
            value = getattr(builtins, type_of_value)(value)
            for matched in processor.match(selector=selector_list):
                click.echo(f"\t\tMatched {selector_list}")
                processor.replace(obj=matched, key=key, value=value)
        if simplify:
            processor.simplify()
        if not dry_run:
            click.echo(f"Writing content back to file: {one_file.name}")
            with open(one_file.name, mode="w") as outfile:
                outfile.write(yaml.safe_dump(object_representation))
 def setUp(self) -> None:
     self.testDict = {
         "a": {
             "b": {
                 "c": "ahoj"
             }
         },
         "int": 2,
         "str": "anystr",
         "bool": False,
         "list": [1, 2, {
             "a": "y"
         }],
         "list_inside": [{
             "m": {
                 "n": "o"
             }
         }],
         "dict": {
             "a": "x"
         },
     }
     self.dp = DictProcessing(self.testDict)
 def testDefault(self):
     self.store_key()
     processor = DictProcessing(PersistentObjectStorage().storage_object)
     processor.simplify()
     self.assertIn("'a': {'d': {'e': [",
                   str(PersistentObjectStorage().storage_object))
예제 #8
0
 def testDefault(self):
     self.store_key()
     processor = DictProcessing(self.cassette.storage_object)
     processor.simplify()
     self.assertIn("'a': {'d': {'e': [", str(self.cassette.storage_object))