Ejemplo n.º 1
0
    def declare(self, data, loop=None):
        super().declare(data, loop)
        events = (i for i in self._services.values()
                   if isinstance(i, Persistent.RSON))
        for each in events:
            path = Persistent.make_path(
                Persistent.recent_slot(each.path)._replace(file=each.path.file)
            )
            fP = os.path.join(*path)
            with Expert.declaration(fP) as output:
                for i in data.get(each.attr, []):
                    try:
                        Assembly.dump(i, output, indent=0)
                    except Exception as e:
                        self._log.error(". ".join(getattr(e, "args", e) or e))
                    finally:
                        output.write("\n")

        pickles = (i for i in self._services.values()
                   if isinstance(i, Persistent.Pickled)
                   and data.get(i.name, False))
        for p in pickles:
            fP = os.path.join(*p.path)
            with open(fP, "wb") as fObj:
                pickle.dump(data[p.name], fObj, 4)
Ejemplo n.º 2
0
    def test_tasks_for_queues(self):
        q, r = (asyncio.Queue(), asyncio.Queue())
        p = Expert(q, r)

        self.assertEqual(2, len(p._watchers))
        self.assertTrue(
            all(isinstance(i, asyncio.Task) for i in p._watchers)
        )
Ejemplo n.º 3
0
    def test_content_goes_to_file_object(self):
        fP = os.path.join(
            DeclarationTests.drcty, DeclarationTests.node)
        fObj = StringIO()
        self.assertFalse(os.path.isfile(fP))
        with Expert.declaration(fObj) as output:
            json.dump("Test string", output)

        self.assertFalse(os.path.isfile(fP))
        self.assertEqual('"Test string"', fObj.getvalue())
Ejemplo n.º 4
0
    def test_content_goes_to_named_file(self):
        fP = os.path.join(
            DeclarationTests.drcty, DeclarationTests.node)
        self.assertFalse(os.path.isfile(fP))
        with Expert.declaration(fP) as output:
            json.dump("Test string", output)

        self.assertTrue(os.path.isfile(fP))
        with open(fP, 'r') as check:
            self.assertEqual('"Test string"', check.read())
Ejemplo n.º 5
0
 def options():
     return OrderedDict([
         ("tick", Expert.Attribute("tick")),
         ("page", Expert.Attribute("page")),
     ])