Example #1
0
    def test_monkeypatch_shadow(self):
        before_table = Table([['blah'], ], [('foo', Text())])

        Table.monkeypatch(TryPatchShadow)

        after_table = Table([['blah'], ], [('foo', Text())])

        self.assertIsInstance(before_table.columns, MappedSequence)
        self.assertIsInstance(after_table.columns, MappedSequence)

        with self.assertRaises(AttributeError):
            after_table.foo == 'foo'
Example #2
0
    def test_monkeypatch_shadow(self):
        before_table = Table([['blah'], ], ['foo'], [Text()])

        Table.monkeypatch(TryPatchShadow)

        after_table = Table([['blah'], ], ['foo'], [Text()])

        self.assertIsInstance(before_table.columns, MappedSequence)
        self.assertIsInstance(after_table.columns, MappedSequence)

        with self.assertRaises(AttributeError):
            after_table.foo == 'foo'
Example #3
0
    def test_monkeypatch(self):
        before_table = Table([], [('foo', Text())])

        Table.monkeypatch(TryPatch)

        after_table = Table([], [('foo', Text())])

        self.assertSequenceEqual(Table.__bases__, [Patchable, TryPatch])

        self.assertIsNotNone(getattr(before_table, 'test'))
        self.assertIsNotNone(getattr(before_table, 'testcls'))

        self.assertIsNotNone(getattr(after_table, 'test'))
        self.assertIsNotNone(getattr(after_table, 'testcls'))

        self.assertEqual(before_table.test(5), 5)
        self.assertEqual(after_table.test(5), 5)
        self.assertEqual(Table.testcls(5), 5)
Example #4
0
    def test_monkeypatch(self):
        before_table = Table([], ['foo'], [Text()])

        Table.monkeypatch(TryPatch)

        after_table = Table([], ['foo'], [Text()])

        self.assertSequenceEqual(Table.__bases__, [Patchable, TryPatch])

        self.assertIsNotNone(getattr(before_table, 'test'))
        self.assertIsNotNone(getattr(before_table, 'testcls'))

        self.assertIsNotNone(getattr(after_table, 'test'))
        self.assertIsNotNone(getattr(after_table, 'testcls'))

        self.assertEqual(before_table.test(5), 5)
        self.assertEqual(after_table.test(5), 5)
        self.assertEqual(Table.testcls(5), 5)
Example #5
0
    def test_monkeypatch_double(self):
        Table.monkeypatch(TryPatch)
        Table.monkeypatch(TryPatch)
        Table.monkeypatch(TryPatch)

        self.assertSequenceEqual(Table.__bases__, [Patchable, TryPatch])
Example #6
0
    def test_monkeypatch_double(self):
        Table.monkeypatch(TryPatch)
        Table.monkeypatch(TryPatch)
        Table.monkeypatch(TryPatch)

        self.assertSequenceEqual(Table.__bases__, [Patchable, TryPatch])
Example #7
0
    def test_monkeypatch_deprecated(self):
        with warnings.catch_warnings():
            warnings.simplefilter('error')

            with self.assertRaises(DeprecationWarning):
                Table.monkeypatch(TryPatch)