diff options
author | sterni <sternenseemann@systemli.org> | 2021-07-06 21:44:55 +0200 |
---|---|---|
committer | Sören Tempel <soeren+git@soeren-tempel.net> | 2021-07-15 13:28:33 +0200 |
commit | e3849012cb9c564dd13b929fe9fcca94d1ba85bf (patch) | |
tree | af32c1a1eb9728792a7ce5c38e5ddc56527524fb | |
parent | a92e1fe912cd87ddb2150ba95407d2669577e418 (diff) |
Document tests and make them easier to run
* Add a shebang and make the tests.py skript executable * Document how to run the tests in the README * Add docstrings to the tests (which are displayed with -v)
-rw-r--r-- | README.md | 4 | ||||
-rwxr-xr-x[-rw-r--r--] | tests.py | 21 |
2 files changed, 20 insertions, 5 deletions
diff --git a/README.md b/README.md index 7d1dedb..42f9c65 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,10 @@ If these are installed run the following command to install `saneterm`: $ python3 setup.py install --optimize=1 +You can also run saneterm's tests (with limited coverage at the moment): + + $ python3 tests.py + For development setups just run `python3 -msaneterm`. ## Usage diff --git a/tests.py b/tests.py index aacdcdc..d712961 100644..100755 --- a/tests.py +++ b/tests.py @@ -1,4 +1,4 @@ -import copy +#!/usr/bin/env python3 import unittest from saneterm.color import Color, ColorType @@ -9,13 +9,18 @@ from gi.repository import Gdk TEST_STRING = 'foo;bar' class TestPositionedIterator(unittest.TestCase): + """Tests for saneterm.pty.PositionedIterator""" + def test_lossless(self): + """Test that the iterator doesn't loose any content""" + it = PositionedIterator(TEST_STRING) self.assertEqual([x for x in it], list(TEST_STRING)) self.assertEqual(it.wrapped, TEST_STRING) def test_indices(self): + """Test that the iterator's pos matches the string indices""" it = PositionedIterator(TEST_STRING) self.assertEqual(it.pos, -1) @@ -34,6 +39,7 @@ class TestPositionedIterator(unittest.TestCase): self.assertTrue(it.empty()) def test_backtracking(self): + """Test waypoint() and backtrack() methods""" it = PositionedIterator(TEST_STRING) semicolon_index = None @@ -55,7 +61,8 @@ class TestPositionedIterator(unittest.TestCase): self.assertEqual(it.next(), ';') self.assertEqual(it.pos, semicolon_index) - def test_takewhile(self): + def test_takewhile_greedy(self): + """Test takewhile_greedy() method""" it = PositionedIterator(TEST_STRING) s = it.takewhile_greedy(lambda x: x != ';') @@ -65,6 +72,7 @@ class TestPositionedIterator(unittest.TestCase): self.assertEqual(it.next(), ';') def test_empty(self): + """Test empty() predicate""" it = PositionedIterator(TEST_STRING) for x in it: @@ -77,6 +85,7 @@ class TestPositionedIterator(unittest.TestCase): _ = it.next() def test_take(self): + """Test take() method""" length = 3 it1 = PositionedIterator(TEST_STRING) it2 = PositionedIterator(TEST_STRING) @@ -96,11 +105,13 @@ class TestPositionedIterator(unittest.TestCase): self.assertEqual(it1.pos, length - 1) class TestColor(unittest.TestCase): + """Tests for saneterm.color""" + def test_256_colors(self): """ - Check divmod based RGB value calculation against - 256 color table generation as implemented in - XTerm's 256colres.pl. + Check divmod based RGB value calculation + against 256 color table generation as implemented + in XTerm's 256colres.pl. """ def channel_val(c): return (c * 40 + 55 if c > 0 else 0) / 255 |