Пример #1
0
 async def test_dataflow_run_cli_example(self):
     # Write out override dataflow
     created = self.mktempfile() + ".yaml"
     with open(created, "w") as fileobj:
         with contextlib.redirect_stdout(fileobj):
             await CLI.cli(
                 "dataflow",
                 "create",
                 "dffml.mapping.create",
                 "print_output",
                 "-configloader",
                 "yaml",
             )
     # Load the generated dataflow
     async with ConfigLoaders() as cfgl:
         _, exported = await cfgl.load_file(created)
         dataflow = DataFlow._fromdict(**exported)
     # Modify the dataflow
     dataflow.flow["print_output"].inputs["data"] = [{
         "dffml.mapping.create":
         "mapping"
     }]
     # Write back modified dataflow
     async with BaseConfigLoader.load("yaml").withconfig(
         {}) as configloader:
         async with configloader() as loader:
             with open(created, "wb") as fileobj:
                 fileobj.write(await
                               loader.dumpb(dataflow.export(linked=True)))
     # Run the dataflow
     with contextlib.redirect_stdout(self.stdout):
         await CLI.cli(
             "dataflow",
             "run",
             "records",
             "all",
             "-no-echo",
             "-record-def",
             "value",
             "-inputs",
             "hello=key",
             "-dataflow",
             created,
             "-sources",
             "m=memory",
             "-source-records",
             "world",
             "user",
         )
     self.assertEqual(self.stdout.getvalue(),
                      "{'hello': 'world'}\n{'hello': 'user'}\n")
Пример #2
0
 def setUp(self):
     self.config_loader = ConfigLoaders()
Пример #3
0
 async def test_parse_unknown(self):
     self.required_plugins("dffml-config-yaml")
     async with ConfigLoaders() as configloaders:
         parsed = await parse_unknown(
             "-rchecker-memory-kvstore",
             "withargs",
             "-rchecker-memory-kvstore-withargs-filename",
             "somefile",
             "-model",
             "slr",
             "-model-network",
             "@" + str(pathlib.Path(__file__).parent / "model-config.yaml"),
             configloaders=configloaders,
         )
     self.assertEqual(
         parsed,
         {
             "rchecker": {
                 "plugin": None,
                 "config": {
                     "memory": {
                         "plugin": None,
                         "config": {
                             "kvstore": {
                                 "plugin": ["withargs"],
                                 "config": {
                                     "withargs": {
                                         "plugin": None,
                                         "config": {
                                             "filename": {
                                                 "plugin": ["somefile"],
                                                 "config": {},
                                             }
                                         },
                                     }
                                 },
                             }
                         },
                     }
                 },
             },
             "model": {
                 "plugin": ["slr"],
                 "config": {
                     "network": {
                         "plugin": [{
                             "model1": {
                                 "layer1": {
                                     "name": "feed",
                                     "config": "face",
                                 },
                                 "layer2": {
                                     "name": "dead",
                                     "config": "beef",
                                 },
                             }
                         }],
                         "config": {},
                     }
                 },
             },
         },
     )