def test_length(self): media = RegionMedia() media.add_to_top('<style type="text/css"></style>') media.add_to_bottom('<script></script>') self.assertEqual(len(media), 2) self.assertEqual(len(media['top']), 1) self.assertEqual(len(media['bottom']), 1)
def test_asdict(self): media = RegionMedia() media.add_to_top('<style></style>') media.add_to_bottom('<script></script>') self.assertEqual(media._asdict(), { 'top': ['<style></style>'], 'bottom': ['<script></script>'] })
def test_deduplicate_on_add(self): media = RegionMedia() for x in range(0, 5): media.add_to_top('<style></style>') self.assertEqual(len(media.top), 1) self.assertEqual(media.top, ['<style></style>']) for x in range(0, 5): media.add_to_bottom('<script></script>') self.assertEqual(len(media.bottom), 1) self.assertEqual(media.bottom, ['<script></script>'])
def test_getitem(self): media = RegionMedia() media.add_to_top('<style></style>') media.add_to_top('<style type="text/css"></style>') media.add_to_top(' <style type="text/css"></style> ') only_top = media['top'] self.assertEqual(only_top.top, ['<style></style>', '<style type="text/css"></style>']) self.assertEqual(only_top.bottom, []) only_bottom = media['bottom'] self.assertEqual(only_bottom.top, []) self.assertEqual(only_bottom.bottom, [])
def test_magicadd(self): media = RegionMedia() media.add_to_top('<style type="text/css"></style>') media.add_to_top(2) media.add_to_bottom(4) media.add_to_bottom(3) other_media = RegionMedia() other_media.add_to_top(6) other_media.add_to_bottom(7) and_another_media = RegionMedia() and_another_media.add_to_top('x') and_another_media.add_to_top('x') new_media = media + other_media + and_another_media self.assertEqual(new_media.top, ['<style type="text/css"></style>', '2', '6', 'x']) self.assertEqual(new_media.bottom, ['4', '3', '7']) self.assertEqual(new_media._asdict(), { 'top': ['<style type="text/css"></style>', '2', '6', 'x'], 'bottom': ['4', '3', '7'] })
def test_truthiness(self): media = RegionMedia() media.add_to_top('<style type="text/css"></style>') self.assertTrue(media) self.assertFalse(RegionMedia())
def test_inequality(self): media = RegionMedia() media.add_to_top('<style type="text/css"></style>') media2 = RegionMedia() media2.add_to_top(2) self.assertNotEqual(media, media2)
def test_contains(self): media = RegionMedia() media.add_to_top('<style type="text/css"></style>') self.assertIn('<style type="text/css"></style>', media)
def test_remove(self): media = RegionMedia() for x in range(0, 5): media.add_to_top('<style></style>') media.remove_from_top('<style></style>') self.assertEqual(len(media.top), 0)