Exemplo n.º 1
0
 def test_contatenate_styled(self):
     s1 = Styled("This is the [[ 'end'|bold ]]!")
     s2 = Styled(" when this [[ 'ends'|bold ]]!")
     s3 = s1 + s2
     self.assertIsInstance(s3, Styled)
     self.assertEqual(s3, s1 + s2)
     self.assertEqual(len(s3), len(s1) + len(s2))
Exemplo n.º 2
0
 def test_find_tokens(self):
     s = """[[ 'a word'|fg-red ]]"""
     s = Styled(s)
     self.assertCountEqual(s._tokens, [(0, 21, u'a word', [u'fg-red'])])
     s = Styled("""[[ 'your {} is open'|fg-blue ]]""", 'bank')
     self.assertCountEqual(s._tokens,
                           [(0, 33, u'your bank is open', [u'fg-blue'])])
Exemplo n.º 3
0
 def test_no_end(self):
     # lacks end
     u_ = u"[[ 'gæsp'|fg-black:bg-deep_sky_blue_2:underlined:blink:no-end ]]"
     e = Styled(u_)
     self.assertNotEqual(e[-3:], u'[0m'.format(ESC, END))
     # has end
     u_ = u"[[ 'gæsp'|fg-black:bg-deep_sky_blue_2:underlined:blink ]]"
     e = Styled(u_)
     self.assertEqual(e[-3:], u'[0m'.format(ESC, END))
Exemplo n.º 4
0
 def test_quotes(self):
     sq = Styled("I have a [[ 'bold \"hair\"'|fg-red ]] face.")
     dq = Styled('I have a [[ "bold \'hair\'"|fg-red ]] face.')
     tq = Styled("""I have a [[ "bold 'hair'"|fg-red ]] face.""")
     self.assertCountEqual(sq._tokens,
                           [(9, 35, u'bold "hair"', [u'fg-red'])])
     self.assertCountEqual(dq._tokens,
                           [(9, 35, u"bold 'hair'", [u'fg-red'])])
     self.assertCountEqual(tq._tokens,
                           [(9, 35, u"bold 'hair'", [u'fg-red'])])
Exemplo n.º 5
0
 def test_concatenate_with_other(self):
     s1 = Styled("This is the [[ 'end'|bold ]]!")
     u1 = " And I will be finished."
     c1 = s1 + u1
     self.assertEqual(c1, s1 + u1)
     self.assertIsInstance(c1, Styled)
     u2 = "I will be finished..."
     s2 = Styled(" when this [[ 'ends'|bold ]]!")
     c2 = u2 + s2
     self.assertEqual(c2, u2 + s2)
     self.assertIsInstance(c2, Styled)
Exemplo n.º 6
0
 def test_length(self):
     u = 'I am the most handsome guy in the room.'
     u_list = u.split(' ')
     s = Styled(
         " ".join(u_list[:4] + ["[[ '{}'|bold ]]".format(u_list[4])] +
                  u_list[5:]))
     self.assertEqual(len(u), len(s))
Exemplo n.º 7
0
 def test_unicode(self):
     s = Styled("We wish we had [[ 'red'|fg-red ]] faces")
     if sys.version_info[0] > 2:
         u_s = str(s)
     else:
         u_s = unicode(s)
     s_s = str(s)
     u_ = u"Thërę are some folkß who [[ 'gæsp'|fg-black:bg-deep_sky_blue_2:underlined:blink ]] at the " \
          u"thœught of the military. "
     e = Styled(u_)
     if sys.version_info[0] > 2:
         self.assertIsInstance(u_s, str)
     else:
         self.assertIsInstance(u_s, unicode)
     self.assertIsInstance(s_s, str)
     self.assertIsInstance(s, Styled)
     self.assertIsInstance(e, Styled)
Exemplo n.º 8
0
 def test_concat_unicode(self):
     u_s = u"A unicode string"
     s = Styled("A [[ 'styled'|blink ]] string")
     c1 = u_s + s
     c2 = s + u_s
     if sys.version_info[0] > 2:
         self.assertIsInstance(u_s, str)
     else:
         self.assertIsInstance(u_s, unicode)
     self.assertIsInstance(c1, Styled)
     self.assertIsInstance(c2, Styled)
Exemplo n.º 9
0
 def test_format(self):
     u = "This is a very {} affair in which {count} people were involved."
     s = Styled(u, 'noble', count=38)
     self.assertEqual(s, u.format('noble', count=38))
Exemplo n.º 10
0
 def test_catch_multiple_bgs(self):
     with self.assertRaises(StyleError):
         s = Styled("[[ 'useless'|bg-red:bg-orange ]]")
Exemplo n.º 11
0
 def test_type(self):
     s = NonStringType(27)
     with self.assertRaises(ValueError):
         Styled(s)
Exemplo n.º 12
0
 def test_empty(self):
     s = Styled()
     self.assertEqual(len(s), 0)
Exemplo n.º 13
0
 def test_bg_colour(self):
     s = Styled(
         "[[ 'White bold text on a black background.'|fg-black:bg-white:bold ]]"
     )
     self.assertIsInstance(s, Styled)
Exemplo n.º 14
0
 def test_catch_multiple_no_ends(self):
     with self.assertRaises(StyleError):
         s = Styled("[[ 'useless'|bg-red:no-end:no-end ]]")
Exemplo n.º 15
0
 def test_style_error(self):
     with self.assertRaises(StyleError):
         Styled('I have a [[ "bold\'hair|fg-red ]] face')
Exemplo n.º 16
0
 def test_iteration(self):
     s = Styled(
         "There are some folks who [[ 'gasp'|fg-black:bg-deep_sky_blue_2:underlined:blink ]] at the thought "
         "of the military. ")
     s += 'Woe unto them!'
     self.assertIsInstance(s, Styled)
Exemplo n.º 17
0
 def test_clean_tokens(self):
     s = Styled("[[ 'some text'|bold:bold ]]")
     # self.assertItemsEqual(s._cleaned_tokens, [(0, 27, u"some text", [u'bold'])])
     self.assertCountEqual(s._cleaned_tokens,
                           [(0, 27, u"some text", [u'bold'])])
Exemplo n.º 18
0
 def test_invalid_style(self):
     with self.assertRaises(StyleError):
         Styled("I have a [[ 'good'|fg-sldjdlj ]]")
Exemplo n.º 19
0
 def test_yes_end(self):
     u_ = u"[[ 'wonder-woman'|fg-red:no-end ]] and this text will also be red [[ 'super-man'|fg-blue:yes-end ]]" \
          u"and this text will be normal"
     e = Styled(u_)
     # test that there is not styling at the end
     self.assertTrue(e[-1], u_[-1])
Exemplo n.º 20
0
 def test_default(self):
     string = 'this is a string'
     S = Styled(string)
     self.assertEqual(S, string)
     self.assertIsInstance(S, Styled)
Exemplo n.º 21
0
 def test_fg_colour(self):
     s = Styled("I have never seen a [[ 'white'|fg-white:bold ]] stallion.")
     self.assertIsInstance(s, Styled)