Coding style.

- More import tidying.
- Fix line lengths.
- Dead code in tests.
- lambdas.
- Tests pass regardless of term type.
This commit is contained in:
Andrew Hamilton 2021-11-22 19:53:37 +10:00
parent 2d9a475833
commit d1e538f5f3
11 changed files with 177 additions and 43 deletions

View file

@ -1,6 +1,7 @@
#!/usr/bin/env python3.9
import os
import pickle
import unittest
@ -8,6 +9,7 @@ import unittest
import termstr
os.environ["TERM"] = "xterm-256color"
ESC = "\x1b"
@ -105,14 +107,16 @@ class TermStrTests(unittest.TestCase):
self.assertEqual(termstr.TermStr("FOO").lower(), foo)
self.assertEqual(termstr.TermStr("FOO", bold_style).lower(), foo_bold)
self.assertEqual(termstr.TermStr("FOO").swapcase(), foo)
self.assertEqual(termstr.TermStr("FOO", bold_style).swapcase(), foo_bold)
self.assertEqual(termstr.TermStr("FOO", bold_style).swapcase(),
foo_bold)
phrase = termstr.TermStr("foo bar")
self.assertEqual(phrase.title(), termstr.TermStr("Foo Bar"))
self.assertEqual(phrase.capitalize(), termstr.TermStr("Foo bar"))
self.assertEqual(foo.upper(), termstr.TermStr("FOO"))
self.assertEqual(foo_bold.center(0), foo_bold)
self.assertEqual(foo_bold.center(7),
termstr.TermStr(" ") + foo_bold + termstr.TermStr(" "))
termstr.TermStr(" ") + foo_bold +
termstr.TermStr(" "))
self.assertEqual(foo_bold.ljust(0), foo_bold)
self.assertEqual(foo_bold.ljust(5), foo_bold + termstr.TermStr(" "))
self.assertEqual(foo_bold.rjust(0), foo_bold)
@ -125,14 +129,15 @@ class TermStrTests(unittest.TestCase):
def test_from_term(self):
def test_round_trip(term_str):
self.assertEqual(termstr.TermStr.from_term(str(term_str)), term_str)
self.assertEqual(termstr.TermStr.from_term(str(term_str)),
term_str)
test_round_trip(termstr.TermStr("foo"))
test_round_trip(termstr.TermStr("foo").bold())
test_round_trip(termstr.TermStr("foo").underline())
test_round_trip(termstr.TermStr("foo").italic())
test_round_trip(termstr.TermStr("foo").fg_color(termstr.Color.red))
test_round_trip(termstr.TermStr("foo").fg_color(termstr.Color.red).\
test_round_trip(termstr.TermStr("foo").fg_color(termstr.Color.red).
bg_color(termstr.Color.green))
test_round_trip(termstr.TermStr("foo").fg_color(1))
test_round_trip(termstr.TermStr("foo").bg_color(10))