Ejemplo n.º 1
0
 async def test_json_label(self):
     await Merge.cli(
         "dest=json",
         "src=json",
         "-source-dest-filename",
         self.temp_filename,
         "-source-dest-label",
         "somelabel",
         "-source-src-filename",
         self.temp_filename,
     )
     # Check the unlabeled source
     with self.subTest(labeled=None):
         async with JSONSource(
                 FileSourceConfig(filename=self.temp_filename)) as source:
             async with source() as sctx:
                 repos = [repo async for repo in sctx.repos()]
                 self.assertEqual(len(repos), len(self.repos))
     # Check the labeled source
     with self.subTest(labeled="somelabel"):
         async with JSONSource(
                 FileSourceConfig(filename=self.temp_filename,
                                  label="somelabel")) as source:
             async with source() as sctx:
                 repos = [repo async for repo in sctx.repos()]
                 self.assertEqual(len(repos), len(self.repos))
Ejemplo n.º 2
0
 async def test_json_tag(self):
     await Merge.cli(
         "src=json",
         "dest=json",
         "-source-src-filename",
         self.temp_filename,
         "-source-dest-filename",
         self.temp_filename,
         "-source-dest-tag",
         "sometag",
         "-source-src-allowempty",
         "-source-dest-allowempty",
         "-source-src-readwrite",
         "-source-dest-readwrite",
     )
     # Check the untagged source
     with self.subTest(tagged=None):
         async with JSONSource(
                 FileSourceConfig(filename=self.temp_filename)) as source:
             async with source() as sctx:
                 records = [record async for record in sctx.records()]
                 self.assertEqual(len(records), len(self.records))
     # Check the tagged source
     with self.subTest(tagged="sometag"):
         async with JSONSource(
                 FileSourceConfig(filename=self.temp_filename,
                                  tag="sometag")) as source:
             async with source() as sctx:
                 records = [record async for record in sctx.records()]
                 self.assertEqual(len(records), len(self.records))
Ejemplo n.º 3
0
 async def setUp(self):
     await super().setUp()
     self.repos = [Repo(str(random.random())) for _ in range(0, 10)]
     self.temp_filename = self.mktempfile()
     self.sconfig = FileSourceConfig(filename=self.temp_filename)
     async with JSONSource(self.sconfig) as source:
         async with source() as sctx:
             for repo in self.repos:
                 await sctx.update(repo)
     contents = json.loads(Path(self.sconfig.filename).read_text())
     # Ensure there are repos in the file
     self.assertEqual(
         len(contents.get(self.sconfig.label)),
         len(self.repos),
         "ReposTestCase JSON file erroneously initialized as empty",
     )
     # TODO(p3) For some reason patching Model.load doesn't work
     # self._stack.enter_context(patch("dffml.model.model.Model.load",
     #     new=model_load))
     self._stack.enter_context(
         patch.object(
             ModelCMD,
             "arg_model",
             new=ModelCMD.arg_model.modify(type=model_load),
         ))
     self._stack.enter_context(
         patch("dffml.feature.feature.Feature.load", new=feature_load))
     self._stack.enter_context(
         patch("dffml.df.base.OperationImplementation.load",
               new=opimp_load))
     self._stack.enter_context(
         patch("dffml.df.types.Operation.load", new=op_load))
Ejemplo n.º 4
0
 async def setUp(self):
     await super().setUp()
     self.records = [Record(str(random.random())) for _ in range(0, 10)]
     self.temp_filename = self.mktempfile()
     self.sconfig = FileSourceConfig(filename=self.temp_filename,
                                     readwrite=True,
                                     allowempty=True)
     async with JSONSource(self.sconfig) as source:
         async with source() as sctx:
             for record in self.records:
                 await sctx.update(record)
     contents = json.loads(Path(self.sconfig.filename).read_text())
     # Ensure there are records in the file
     self.assertEqual(
         len(contents.get(self.sconfig.tag)),
         len(self.records),
         "RecordsTestCase JSON file erroneously initialized as empty",
     )
     # TODO(p3) For some reason patching Model.load doesn't work
     self._stack.enter_context(
         patch("dffml.model.model.Model.load", new=model_load))
     self._stack.enter_context(
         patch("dffml.df.base.OperationImplementation.load",
               new=opimp_load))
     self._stack.enter_context(
         patch("dffml.df.types.Operation.load", new=op_load))
Ejemplo n.º 5
0
 def config(
     self, filename, tag="untagged", readwrite=True, allowempty=True
 ):
     return FileSourceConfig(
         filename=filename,
         readwrite=readwrite,
         tag=tag,
         allowempty=allowempty,
     )
Ejemplo n.º 6
0
 def config(
     self, filename, label="unlabeled", readwrite=True, allowempty=True
 ):
     return FileSourceConfig(
         filename=filename,
         readwrite=readwrite,
         label=label,
         allowempty=allowempty,
     )
Ejemplo n.º 7
0
 async def setUp(self):
     super().setUp()
     self.repos = [Repo(str(random.random())) for _ in range(0, 10)]
     self.__temp_filename = non_existant_tempfile()
     self.temp_filename = self.__temp_filename.__enter__()
     self.sconfig = FileSourceConfig(filename=self.temp_filename)
     async with JSONSource(self.sconfig) as source:
         async with source() as sctx:
             for repo in self.repos:
                 await sctx.update(repo)
 async def setUp(self):
     super().setUp()
     self.repos = [Repo(str(random.random())) for _ in range(0, 10)]
     self.__stack = ExitStack()
     self._stack = self.__stack.__enter__()
     self.temp_filename = self.mktempfile()
     self.sconfig = FileSourceConfig(filename=self.temp_filename)
     async with JSONSource(self.sconfig) as source:
         async with source() as sctx:
             for repo in self.repos:
                 await sctx.update(repo)
     contents = json.loads(Path(self.sconfig.filename).read_text())
     # Ensure there are repos in the file
     self.assertEqual(
         len(contents.get(self.sconfig.label)),
         len(self.repos),
         "ReposTestCase JSON file erroneously initialized as empty",
     )
Ejemplo n.º 9
0
 async def setUpSource(self):
     return JSONSource(FileSourceConfig(filename=self.testfile))
Ejemplo n.º 10
0
 def config(self, filename, label="unlabeled", readonly=False):
     return FileSourceConfig(filename=filename,
                             readonly=readonly,
                             label=label)