def test_gc_dumps_garbage_ok(self): """Check that the garbage dump works.""" get_count = mock.Mock(return_value=0) self.patch(gc, 'get_count', get_count) garbage = iter(['foo', 666]) self.patch(gc, 'garbage', garbage) self.assertIn("2 garbage items written", gc_dump())
def test_gc_dump_error_generic(self): """Something bad happens when dumping gc.""" get_count = self.mocker.replace(gc.get_count) get_count() self.mocker.throw(ValueError) self.mocker.replay() self.assertIn("Error while trying to dump GC", gc_dump())
def test_gc_dumps_count_ok(self): """Check that the count dump works.""" get_count = mock.Mock(return_value=(400, 20, 3)) self.patch(gc, 'get_count', get_count) garbage = iter([]) self.patch(gc, 'garbage', garbage) self.assertIn("GC count is (400, 20, 3)", gc_dump())
def test_gc_dump_error_garbage(self): """Support something that breaks in repr.""" class Strange(object): """Weird object that breaks on repr.""" def __repr__(self): raise ValueError('foo') garbage = iter([Strange()]) self.patch(gc, 'garbage', garbage) self.assertIn("1 garbage items written", gc_dump())
def test_gc_dumps_garbage_ok(self): """Check that the garbage dump works.""" get_count = self.mocker.replace(gc.get_count) garbage = self.mocker.replace(gc.garbage) get_count() self.mocker.result(0) # we're exercising the mocker [x for x in garbage] self.mocker.result(iter(['foo', 666])) self.mocker.replay() self.assertIn("2 garbage items written", gc_dump())
def test_gc_dumps_count_ok(self): """Check that the count dump works.""" get_count = self.mocker.replace(gc.get_count) garbage = self.mocker.replace(gc.garbage) get_count() self.mocker.result((400, 20, 3)) # we're exercising the mocker [x for x in garbage] self.mocker.result(iter([])) self.mocker.replay() self.assertIn("GC count is (400, 20, 3)", gc_dump())
def test_gc_dump_error_garbage(self): """Support something that breaks in repr.""" class Strange(object): """Weird object that breaks on repr.""" def __repr__(self): raise ValueError('foo') garbage = self.mocker.replace(gc.garbage) # we're exercising the mocker [x for x in garbage] self.mocker.result(iter([Strange()])) self.mocker.replay() self.assertIn("1 garbage items written", gc_dump())
def render_GET(self, request): """Handle GET.""" return dump.gc_dump()
def test_gc_dump_error_generic(self): """Something bad happens when dumping gc.""" get_count = mock.Mock(side_effect=ValueError()) self.patch(gc, 'get_count', get_count) self.assertIn("Error while trying to dump GC", gc_dump())