Exemple #1
0
def context(mocks):
    """Provides a mocked Context instance"""
    def fn(context):
        context.contents.value = 1234
        return yogi.ErrorCode.OK

    mocks.MOCK_ContextCreate(fn)
    return yogi.Context()
Exemple #2
0
    def test_format(self):
        obj = yogi.Context()

        s = obj.format()
        self.assertRegex(s, "Context \\[[1-9a-f][0-9a-f]+\\]")

        s = obj.format("$T-[$X]")
        self.assertRegex(s, "Context-\\[[1-9A-F][0-9A-F]+\\]")

        obj = FakeObject()
        s = yogi.Object.format(obj)
        self.assertTrue(s.startswith("INVALID"))

        s = yogi.Object.format(obj, nullstr="MOO")
        self.assertEqual(s, "MOO")
Exemple #3
0
def test_destroy(mocks: Mocks):
    """Verifies that objects can be destroyed"""
    def fn(context):
        context.contents.value = 1234
        return yogi.ErrorCode.OK

    mocks.MOCK_ContextCreate(fn)
    context = yogi.Context()

    called = False

    def fn2(obj):
        assert obj == 1234
        nonlocal called
        called = True
        return yogi.ErrorCode.OK

    mocks.MOCK_Destroy(fn2)
    del context
    assert called
Exemple #4
0
 def setUp(self):
     self.context = yogi.Context()
 def setUp(self):
     self.context = yogi.Context()
     self.json_view = yogi.JsonView("[1,2,3]")
     self.big_json_view = yogi.JsonView(self.make_big_json_data())
     self.msgpack_view = yogi.MsgpackView(bytes([0x93, 0x1, 0x2, 0x3]))
Exemple #6
0
 def test_str(self):
     obj = yogi.Context()
     self.assertRegex(str(obj), "Context \\[[1-9a-f][0-9a-f]+\\]")
Exemple #7
0
 def setUp(self):
     self.context = yogi.Context()
     self.timer = yogi.Timer(self.context)