def test_warningWhenSettingSizeToZero(self): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") self.assertEqual(len(w), 0) # Set size to zero, triggering a warning m = Media(self.url, type=self.type) self.assertEqual(len(w), 1) assert issubclass(w[-1].category, UserWarning) # No warning when setting to an actual integer m.size = 253634535 self.assertEqual(len(w), 1) # Nor when using a string m.size = "15kB" self.assertEqual(len(w), 1) # Warning when setting to None m.size = None self.assertEqual(len(w), 2) assert issubclass(w[-1].category, UserWarning) # Or zero m.size = 0 self.assertEqual(len(w), 3) assert issubclass(w[-1].category, UserWarning)
def test_assigningSize(self): m = Media(self.url, self.size) another_size = 1234567 m.size = another_size assert m.size == another_size