コード例 #1
0
 def test_StaticColorAssigner(self):
     with patch(
             'snipe.ttycolor.curses',
             mocks.Curses(colors=8, color_pairs=2)):
         assign = ttycolor.StaticColorAssigner()
         self.assertEqual(len(assign.map), len(ttycolor.colors_simple))
         pair = assign.next
         self.assertEqual(assign('white', 'blue'), pair)
         self.assertEqual(assign('white', 'blue'), pair)
         self.assertEqual(assign('black', 'white'), 0)
         self.assertEqual(assign.getcolor('nonexistent color'), -1)
         self.assertIs(assign.getcolor('#fff'), assign.getcolor('#fff'))
     with patch(
             'snipe.ttycolor.curses',
             mocks.Curses(colors=256, color_pairs=2)):
         assign = ttycolor.StaticColorAssigner()
         self.assertEqual(
             len(assign.map), len(ttycolor.colors_xterm_256color))
     with patch(
             'snipe.ttycolor.curses',
             mocks.Curses(colors=88, color_pairs=2)):
         assign = ttycolor.StaticColorAssigner()
         self.assertEqual(
             len(assign.map), len(ttycolor.colors_xterm_88color))
     with patch(
             'snipe.ttycolor.curses',
             mocks.Curses(colors=16, color_pairs=2)):
         assign = ttycolor.StaticColorAssigner()
         self.assertEqual(
             len(assign.map), len(ttycolor.colors_xterm))
コード例 #2
0
    def test_get_assigner(self):
        with unittest.mock.patch('snipe.ttycolor.curses', mocks.Curses()):
            self.assertIsInstance(ttycolor.get_assigner(),
                                  ttycolor.NoColorAssigner)

        with unittest.mock.patch('snipe.ttycolor.curses',
                                 mocks.Curses(colors=256, dynamic=True)):
            self.assertIsInstance(ttycolor.get_assigner(),
                                  ttycolor.DynamicColorAssigner)

        with unittest.mock.patch('snipe.ttycolor.curses',
                                 mocks.Curses(colors=256, dynamic=False)):
            self.assertIsInstance(ttycolor.get_assigner(),
                                  ttycolor.StaticColorAssigner)
コード例 #3
0
 def test_CleverColorAssigner(self):
     with unittest.mock.patch('snipe.ttycolor.curses',
                              mocks.Curses(colors=8, color_pairs=2)):
         assign = ttycolor.CleverColorAssigner()
         self.assertEqual(assign.strtorgb('#fff'), (255, 255, 255))
         self.assertEqual(assign.strtorgb('#ffffff'), (255, 255, 255))
         self.assertEqual(assign.strtorgb('231'), (255, 255, 255))
         self.assertIsNone(assign.strtorgb('nonexistent color'))
コード例 #4
0
 def test_SimpleColorAssigner(self):
     with unittest.mock.patch('snipe.ttycolor.curses',
                              mocks.Curses(colors=8, color_pairs=2)):
         assign = ttycolor.SimpleColorAssigner()
         pair = assign.next
         self.assertEqual(assign('white', 'blue'), pair)
         self.assertEqual(assign('white', 'blue'), pair)
         self.assertEqual(assign('black', 'white'), 0)
コード例 #5
0
 def test_DynamicColorAssigner(self):
     with unittest.mock.patch('snipe.ttycolor.curses',
                              mocks.Curses(colors=8, color_pairs=2)):
         assign = ttycolor.DynamicColorAssigner()
         pair = assign.next
         self.assertEqual(assign('white', 'blue'), pair)
         self.assertEqual(assign('white', 'blue'), pair)
         self.assertEqual(assign('black', 'white'), 0)
         self.assertEqual(assign.getcolor('nonexistent color'), -1)
         self.assertIs(assign.getcolor('#fff'), assign.getcolor('#fff'))
         self.assertEqual(assign.getcolor('#003'), 3)
         self.assertEqual(assign.getcolor('#004'), 4)
         self.assertEqual(assign.getcolor('#005'), 5)
         self.assertEqual(assign.getcolor('#006'), 6)
         self.assertEqual(assign.getcolor('#007'), 7)
         self.assertEqual(assign.getcolor('#008'), -1)
         assign.close()