def test_init_empty_context(self): context = { "task": mock.MagicMock() } ctx = fakes.FakeContext(context) self.assertEqual(ctx.config, {}) self.assertEqual(ctx.task, context["task"]) self.assertEqual(ctx.context, context)
def test_with_statement(self): context = {"task": mock.MagicMock()} ctx = fakes.FakeContext(context) ctx.setup = mock.MagicMock() ctx.cleanup = mock.MagicMock() with ctx as entered_ctx: self.assertEqual(ctx, entered_ctx) ctx.cleanup.assert_called_once_with()
def test_init(self): context = { "config": { "a": 1, "fake": mock.MagicMock() }, "task": mock.MagicMock() } ctx = fakes.FakeContext(context) self.assertEqual(ctx.config, context["config"]["fake"]) self.assertEqual(ctx.task, context["task"]) self.assertEqual(ctx.context, context)