diff options
Diffstat (limited to 'tests/test_utils.py')
-rw-r--r-- | tests/test_utils.py | 86 |
1 files changed, 44 insertions, 42 deletions
diff --git a/tests/test_utils.py b/tests/test_utils.py index 15b6c55..8cecb1b 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -30,7 +30,6 @@ from jinja2.utils import urlize @pytest.mark.utils @pytest.mark.lrucache class TestLRUCache(object): - def test_simple(self): d = LRUCache(3) d["a"] = 1 @@ -39,7 +38,7 @@ class TestLRUCache(object): d["a"] d["d"] = 4 assert len(d) == 3 - assert 'a' in d and 'c' in d and 'd' in d and 'b' not in d + assert "a" in d and "c" in d and "d" in d and "b" not in d def test_itervalue_deprecated(self): cache = LRUCache(3) @@ -77,13 +76,13 @@ class TestLRUCache(object): @pytest.mark.parametrize("copy_func", [LRUCache.copy, shallow_copy]) def test_copy(self, copy_func): cache = LRUCache(2) - cache['a'] = 1 - cache['b'] = 2 + cache["a"] = 1 + cache["b"] = 2 copy = copy_func(cache) assert copy._queue == cache._queue - copy['c'] = 3 + copy["c"] = 3 assert copy._queue != cache._queue - assert 'a' not in copy and 'b' in copy and 'c' in copy + assert "a" not in copy and "b" in copy and "c" in copy def test_clear(self): d = LRUCache(3) @@ -91,7 +90,7 @@ class TestLRUCache(object): d["b"] = 2 d["c"] = 3 d.clear() - assert d.__getstate__() == {'capacity': 3, '_mapping': {}, '_queue': deque([])} + assert d.__getstate__() == {"capacity": 3, "_mapping": {}, "_queue": deque([])} def test_repr(self): d = LRUCache(3) @@ -107,18 +106,18 @@ class TestLRUCache(object): d["a"] = 1 d["b"] = 2 d["c"] = 3 - assert d.items() == list(d.iteritems()) == [('c', 3), ('b', 2), ('a', 1)] - assert d.keys() == list(d.iterkeys()) == ['c', 'b', 'a'] + assert d.items() == list(d.iteritems()) == [("c", 3), ("b", 2), ("a", 1)] + assert d.keys() == list(d.iterkeys()) == ["c", "b", "a"] assert d.values() == list(d.itervalues()) == [3, 2, 1] - assert list(reversed(d)) == ['a', 'b', 'c'] + assert list(reversed(d)) == ["a", "b", "c"] # Change the cache a little d["b"] d["a"] = 4 - assert d.items() == list(d.iteritems()) == [('a', 4), ('b', 2), ('c', 3)] - assert d.keys() == list(d.iterkeys()) == ['a', 'b', 'c'] + assert d.items() == list(d.iteritems()) == [("a", 4), ("b", 2), ("c", 3)] + assert d.keys() == list(d.iterkeys()) == ["a", "b", "c"] assert d.values() == list(d.itervalues()) == [4, 2, 3] - assert list(reversed(d)) == ['c', 'b', 'a'] + assert list(reversed(d)) == ["c", "b", "a"] def test_setdefault(self): d = LRUCache(3) @@ -133,31 +132,31 @@ class TestLRUCache(object): @pytest.mark.utils @pytest.mark.helpers class TestHelpers(object): - def test_object_type_repr(self): class X(object): pass - assert object_type_repr(42) == 'int object' - assert object_type_repr([]) == 'list object' - assert object_type_repr(X()) == 'test_utils.X object' - assert object_type_repr(None) == 'None' - assert object_type_repr(Ellipsis) == 'Ellipsis' + + assert object_type_repr(42) == "int object" + assert object_type_repr([]) == "list object" + assert object_type_repr(X()) == "test_utils.X object" + assert object_type_repr(None) == "None" + assert object_type_repr(Ellipsis) == "Ellipsis" def test_autoescape_select(self): func = select_autoescape( - enabled_extensions=('html', '.htm'), - disabled_extensions=('txt',), - default_for_string='STRING', - default='NONE', + enabled_extensions=("html", ".htm"), + disabled_extensions=("txt",), + default_for_string="STRING", + default="NONE", ) - assert func(None) == 'STRING' - assert func('unknown.foo') == 'NONE' - assert func('foo.html') == True - assert func('foo.htm') == True - assert func('foo.txt') == False - assert func('FOO.HTML') == True - assert func('FOO.TXT') == False + assert func(None) == "STRING" + assert func("unknown.foo") == "NONE" + assert func("foo.html") == True + assert func("foo.htm") == True + assert func("foo.txt") == False + assert func("FOO.HTML") == True + assert func("FOO.TXT") == False @pytest.mark.utils @@ -166,9 +165,11 @@ class TestEscapeUrlizeTarget(object): def test_escape_urlize_target(self): url = "http://example.org" target = "<script>" - assert urlize(url, target=target) == ('<a href="http://example.org"' - ' target="<script>">' - 'http://example.org</a>') + assert urlize(url, target=target) == ( + '<a href="http://example.org"' + ' target="<script>">' + "http://example.org</a>" + ) @pytest.mark.utils @@ -184,28 +185,29 @@ class TestLoremIpsum(object): def test_lorem_ipsum_n(self): """Test that the n (number of lines) works as expected.""" - assert generate_lorem_ipsum(n=0, html=False) == u'' + assert generate_lorem_ipsum(n=0, html=False) == u"" for n in range_type(1, 50): - assert generate_lorem_ipsum(n=n, html=False).count('\n') == (n - 1) * 2 + assert generate_lorem_ipsum(n=n, html=False).count("\n") == (n - 1) * 2 def test_lorem_ipsum_min(self): """Test that at least min words are in the output of each line""" for _ in range_type(5): - m = random.randrange(20, 99) - for _ in range_type(10): - assert generate_lorem_ipsum(n=1, min=m, html=False).count(' ') >= m - 1 + m = random.randrange(20, 99) + for _ in range_type(10): + assert generate_lorem_ipsum(n=1, min=m, html=False).count(" ") >= m - 1 def test_lorem_ipsum_max(self): """Test that at least max words are in the output of each line""" for _ in range_type(5): - m = random.randrange(21, 100) - for _ in range_type(10): - assert generate_lorem_ipsum(n=1, max=m, html=False).count(' ') < m - 1 + m = random.randrange(21, 100) + for _ in range_type(10): + assert generate_lorem_ipsum(n=1, max=m, html=False).count(" ") < m - 1 def test_missing(): """Test the repr of missing.""" - assert repr(missing) == u'missing' + assert repr(missing) == u"missing" + def test_consume(): """Test that consume consumes an iterator.""" |