def setUp(self): self.names = ["Bob", "Dylan", "Doesn't", "Like", "Spam"] self.count_display = ChromosomeCounts(self.names)
class ChromosomeCountTest(unittest.TestCase): """Test the display representation for simple counts on a chromosome. """ def setUp(self): self.names = ["Bob", "Dylan", "Doesn't", "Like", "Spam"] self.count_display = ChromosomeCounts(self.names) def test_add_count(self): """Add counts to specific chromosome segments. """ self.count_display.add_count(self.names[1]) self.count_display.add_count(self.names[2], 5) try: self.count_display.add_count("Non-existent") raise AssertionError("Didn't raise a KeyError on a fake key") except KeyError: pass def test_add_label(self): """Add labels to chromosome segments. """ self.count_display.add_label(self.names[1], "Rules") try: self.count_display.add_label("Non-existent", "Elephant") raise AssertionError("Didn't raise a KeyError on a fake key") except KeyError: pass def test_set_scale(self): """Set the scale for a chromosome segment. """ self.count_display.set_scale(self.names[1], 1.5) try: self.count_display.set_scale("Non-existant", 5) raise AssertionError("Didn't raise a KeyError on a fake key.") except KeyError: pass def test_color_from_count(self): """Retrieve a color from a count number with the default color scheme. """ test_color = self.count_display._color_from_count(3) assert test_color == colors.blue, "Unexpected color %s" % test_color test_color = self.count_display._color_from_count(9) assert test_color == colors.red, "Unexpected color %s" % test_color try: self.count_display._color_from_count(200) raise AssertionError("Didn't raise an error for bad count.") except ValueError: pass def test_fill_chromosome(self): """Test filling out the information on a chromosome. """ test_chr = BasicChromosome.Chromosome("1") self.count_display.add_count(self.names[2], 5) self.count_display.add_count(self.names[1], 2) self.count_display.add_label(self.names[3], "Test-Label") new_chr = self.count_display.fill_chromosome(test_chr) def test_get_segment_info(self): """Test retrieval of segment information. """ test_count_num = 1 test_count_value = 5 test_label_num = 3 test_label_value = "BigBird" self.count_display.add_count(self.names[test_count_num], test_count_value) self.count_display.add_label(self.names[test_label_num], test_label_value) seg_info = self.count_display.get_segment_info() assert seg_info[test_count_num][0] == test_count_value, \ "Did not set and retrieve counts correctly." assert seg_info[test_label_num][1] == test_label_value, \ "Did not set and retrieve label correctly."
class ChromosomeCountTest(unittest.TestCase): """Test the display representation for simple counts on a chromosome.""" def setUp(self): self.names = ["Bob", "Dylan", "Doesn't", "Like", "Spam"] self.count_display = ChromosomeCounts(self.names) def test_add_count(self): """Add counts to specific chromosome segments.""" self.count_display.add_count(self.names[1]) self.count_display.add_count(self.names[2], 5) self.assertRaises(KeyError, self.count_display.add_count, "Non-existent") def test_add_label(self): """Add labels to chromosome segments.""" self.count_display.add_label(self.names[1], "Rules") self.assertRaises(KeyError, self.count_display.add_label, "Non-existent", "elephant") def test_set_scale(self): """Set the scale for a chromosome segment.""" self.count_display.set_scale(self.names[1], 1.5) self.assertRaises(KeyError, self.count_display.set_scale, "Non-existent", 5) def test_color_from_count(self): """Retrieve a color from a count number with the default color scheme.""" test_color = self.count_display._color_from_count(3) self.assertEqual(test_color, colors.blue) test_color = self.count_display._color_from_count(9) self.assertEqual(test_color, colors.red) self.assertRaises(ValueError, self.count_display._color_from_count, 200) def test_fill_chromosome(self): """Test filling out the information on a chromosome.""" test_chr = BasicChromosome.Chromosome("1") self.count_display.add_count(self.names[2], 5) self.count_display.add_count(self.names[1], 2) self.count_display.add_label(self.names[3], "Test-Label") new_chr = self.count_display.fill_chromosome(test_chr) def test_get_segment_info(self): """Test retrieval of segment information.""" test_count_num = 1 test_count_value = 5 test_label_num = 3 test_label_value = "BigBird" self.count_display.add_count(self.names[test_count_num], test_count_value) self.count_display.add_label(self.names[test_label_num], test_label_value) seg_info = self.count_display.get_segment_info() self.assertEqual( seg_info[test_count_num][0], test_count_value, "Did not set and retrieve counts correctly.", ) self.assertEqual( seg_info[test_label_num][1], test_label_value, "Did not set and retrieve label correctly.", )