Пример #1
0
    def test_colorscheme(self):
        cs = ColorScheme(
            [
                SymbolColor("G", "orange"),
                SymbolColor("TU", "red"),
                SymbolColor("C", "blue"),
                SymbolColor("A", "green"),
            ],
            title="title",
            description="description",
        )

        self.assertEqual(cs.symbol_color(1, "G", 1), Color.by_name("orange"))
        self.assertEqual(cs.symbol_color(1, "T", 1), Color.by_name("red"))
        self.assertEqual(cs.symbol_color(1, "C", 1), Color.by_name("blue"))
        self.assertEqual(cs.symbol_color(1, "A", 1), Color.by_name("green"))
        self.assertEqual(cs.symbol_color(1, "X", 1), cs.default_color)

        cs = ColorScheme(
            [
                SymbolColor("G", "orange"),
                SymbolColor("TU", "red"),
                SymbolColor("C", "blue"),
                SymbolColor("A", "green"),
            ],
            title="title",
            description="description",
            alphabet="GTUCA",
        )
        self.assertRaises(KeyError, cs.symbol_color, 1, "X", 1)
Пример #2
0
    def test_color_from_string(self):
        Color(128, 0, 128)  # purple
        red = Color(255, 0, 0)
        skyblue = Color(135, 206, 235)

        red_strings = (
            "red",
            "ReD",
            "RED",
            "   Red \t",
            "#F00",
            "#FF0000",
            "rgb(255, 0, 0)",
            "rgb(100%, 0%, 0%)",
            "hsl(0, 100%, 50%)",
        )
        for s in red_strings:
            self.assertEqual(red, Color.from_string(s))

        skyblue_strings = (
            "skyblue",
            "SKYBLUE",
            "  \t\n SkyBlue  \t",
            "#87ceeb",
            "rgb(135,206,235)",
        )
        for s in skyblue_strings:
            self.assertEqual(skyblue, Color.from_string(s))

        self.assertRaises(ValueError, Color.from_string, "#not_a_color")
        self.assertRaises(ValueError, Color.from_string, "rgb(not_a_color)")
        self.assertRaises(ValueError, Color.from_string, "hsl(not_a_color)")
        self.assertRaises(ValueError, Color.from_string, "not_a_color")
Пример #3
0
 def test_color_by_name(self):
     white = Color.by_name("white")
     self.assertEqual(white, Color.by_name("white"))
     self.assertEqual(white, Color.by_name("WHITE"))
     self.assertEqual(white, Color.by_name(" wHiTe \t\n\t"))
     self.assertEqual(Color(255, 255, 240), Color.by_name("ivory"))
     self.assertEqual(Color(70, 130, 180), Color.by_name("steelblue"))
     self.assertEqual(Color(0, 128, 0), Color.by_name("green"))
Пример #4
0
 def test_color_clipping(self):
     red = Color.by_name("red")
     self.assertEqual(red, Color(255, 0, 0))
     self.assertEqual(red, Color(260, -10, 0))
     self.assertEqual(red, Color(1.1, -0.0, -1.0))
     self.assertEqual(Color(1.0001, 213.0, 1.2).red, 1.0)
     self.assertEqual(Color(-0.001, -2183.0, -1.0).red, 0.0)
     self.assertEqual(Color(1.0001, 213.0, 1.2).green, 1.0)
     self.assertEqual(Color(-0.001, -2183.0, -1.0).green, 0.0)
     self.assertEqual(Color(1.0001, 213.0, 1.2).blue, 1.0)
     self.assertEqual(Color(-0.001, -2183.0, -1.0).blue, 0.0)
Пример #5
0
    def test_color_components(self):
        white = Color.by_name("white")
        self.assertEqual(1.0, white.red)
        self.assertEqual(1.0, white.green)
        self.assertEqual(1.0, white.blue)

        c = Color(0.3, 0.4, 0.2)
        self.assertEqual(0.3, c.red)
        self.assertEqual(0.4, c.green)
        self.assertEqual(0.2, c.blue)

        c = Color(0, 128, 0)
        self.assertEqual(0.0, c.red)
        self.assertEqual(128.0 / 255.0, c.green)
        self.assertEqual(0.0, c.blue)
Пример #6
0
    def test_ref_seq_color(self):
        rc = RefSeqColor("abc", "black", "Because")
        self.assertEqual(rc.description, "Because")

        self.assertEqual(rc.symbol_color(0, "A", 0), Color.by_name("black"))
        self.assertEqual(rc.symbol_color(1, "A", 0), None)
        self.assertEqual(rc.symbol_color(2, "A", 0), None)

        self.assertEqual(rc.symbol_color(0, "B", 0), None)
        self.assertEqual(rc.symbol_color(1, "B", 0), Color.by_name("black"))
        self.assertEqual(rc.symbol_color(2, "B", 0), None)

        self.assertEqual(rc.symbol_color(0, "C", 0), None)
        self.assertEqual(rc.symbol_color(1, "C", 0), None)
        self.assertEqual(rc.symbol_color(2, "C", 0), Color.by_name("black"))
Пример #7
0
 def test_color_equality(self):
     c1 = Color(123, 99, 12)
     c2 = Color(123, 99, 12)
     self.assertEqual(c1, c2)
     self.assertNotEqual(c1, "not_a_color")
Пример #8
0
 def test_color_red(self):
     # Check Usage comment in Color
     red = Color.by_name("red")
     self.assertEqual(red, Color(255, 0, 0))
     self.assertEqual(red, Color(1.0, 0.0, 0.0))
     self.assertEqual(red, Color.from_rgb(1.0, 0.0, 0.0))
     self.assertEqual(red, Color.from_rgb(255, 0, 0))
     self.assertEqual(red, Color.from_hsl(0.0, 1.0, 0.5))
     self.assertEqual(red, Color.from_string("red"))
     self.assertEqual(red, Color.from_string("RED"))
     self.assertEqual(red, Color.from_string("#F00"))
     self.assertEqual(red, Color.from_string("#FF0000"))
     self.assertEqual(red, Color.from_string("rgb(255, 0, 0)"))
     self.assertEqual(red, Color.from_string("rgb(100%, 0%, 0%)"))
     self.assertEqual(red, Color.from_string("hsl(0, 100%, 50%)"))
Пример #9
0
 def test_color_from_hsl(self):
     red = Color.by_name("red")
     lime = Color.by_name("lime")
     saddlebrown = Color.by_name("saddlebrown")
     darkgreen = Color.by_name("darkgreen")
     blue = Color.by_name("blue")
     Color.by_name("green")
     self.assertEqual(red, Color.from_hsl(0, 1.0, 0.5))
     self.assertEqual(lime, Color.from_hsl(120, 1.0, 0.5))
     self.assertEqual(blue, Color.from_hsl(240, 1.0, 0.5))
     self.assertEqual(Color.by_name("gray"), Color.from_hsl(0, 0, 0.5))
     self.assertEqual(saddlebrown, Color.from_hsl(25, 0.76, 0.31))
     self.assertEqual(darkgreen, Color.from_hsl(120, 1.0, 0.197))
Пример #10
0
 def test_color_from_rgb(self):
     white = Color.by_name("white")
     self.assertEqual(white, Color(1.0, 1.0, 1.0))
     self.assertEqual(white, Color(255, 255, 255))
     self.assertEqual(white, Color.from_rgb(1.0, 1.0, 1.0))
     self.assertEqual(white, Color.from_rgb(255, 255, 255))
Пример #11
0
 def test_color_names(self):
     names = Color.names()
     self.assertEqual(len(names), 147)
     for n in names:
         c = Color.by_name(n)
         self.assertTrue(c is not None)
Пример #12
0
 def test_index_color(self):
     ic = IndexColor([1, 3], "black", "Because")
     self.assertEqual(ic.description, "Because")
     self.assertEqual(ic.symbol_color(0, "A", 0), None)
     self.assertEqual(ic.symbol_color(1, "A", 0), Color.by_name("black"))
Пример #13
0
 def test_symbol_color(self):
     sc = SymbolColor("abc", "black", "Because")
     self.assertEqual(sc.description, "Because")
     self.assertEqual(sc.symbol_color(0, "A", 0), Color.by_name("black"))
     self.assertEqual(sc.symbol_color(1, "D", 0), None)
Пример #14
0
 def __init__(self, symbols, indices, color, description=None):
     self.symbols = symbols.upper()
     self.indices = indices
     self.color = Color.from_string(color)
     self.description = description