diff options
| author | Bert JW Regeer <bertjw@regeer.org> | 2016-04-15 01:25:14 -0600 |
|---|---|---|
| committer | Bert JW Regeer <bertjw@regeer.org> | 2016-04-15 02:20:46 -0600 |
| commit | 6b441fa23f01cb8bdbc56699bc9cd374c75621fe (patch) | |
| tree | aa4d65749fa8562ec0ab559a35d1d847876560cb /tests | |
| parent | 175230dbc05157279ea59cf6c830679d3a93bf16 (diff) | |
| download | webob-6b441fa23f01cb8bdbc56699bc9cd374c75621fe.tar.gz | |
test_misc.py convert to assert from nose
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_misc.py | 73 |
1 files changed, 36 insertions, 37 deletions
diff --git a/tests/test_misc.py b/tests/test_misc.py index 8840f9d..ad3ce25 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -1,7 +1,7 @@ -import cgi +import pytest + from webob.util import html_escape from webob.multidict import MultiDict -from nose.tools import eq_ as eq, assert_raises from webob.compat import ( text_, PY3 @@ -20,12 +20,12 @@ def test_html_escape(): # The apostrophe is *not* escaped, which some might consider to be # a serious bug (see, e.g. http://www.cvedetails.com/cve/CVE-2010-2480/) (text_('the majestic m\xf8ose'), 'the majestic møose'), - #("'", "'") + # ("'", "'") # 8-bit strings are passed through (text_('\xe9'), 'é'), - ## (text_(b'the majestic m\xf8ose').encode('utf-8'), - ## 'the majestic m\xc3\xb8ose'), + # (text_(b'the majestic m\xf8ose').encode('utf-8'), + # 'the majestic m\xc3\xb8ose'), # ``None`` is treated specially, and returns the empty string. (None, ''), @@ -43,7 +43,7 @@ def test_html_escape(): (t_esc_Unicode(), 'é'), (t_esc_UnsafeAttrs(), '<UnsafeAttrs>'), ]: - eq(html_escape(v), s) + assert html_escape(v) == s class t_esc_HTML(object): def __html__(self): @@ -67,35 +67,33 @@ class t_esc_SuperMoose(object): def __unicode__(self): return text_(b'm\xf8ose') - - - - - def test_multidict(): d = MultiDict(a=1, b=2) - eq(d['a'], 1) - eq(d.getall('c'), []) + assert d['a'] == 1 + assert d.getall('c') == [] d.add('a', 2) - eq(d['a'], 2) - eq(d.getall('a'), [1, 2]) + assert d['a'] == 2 + assert d.getall('a') == [1, 2] d['b'] = 4 - eq(d.getall('b'), [4]) - eq(list(d.keys()), ['a', 'a', 'b']) - eq(list(d.items()), [('a', 1), ('a', 2), ('b', 4)]) - eq(d.mixed(), {'a': [1, 2], 'b': 4}) + assert d.getall('b') == [4] + assert list(d.keys()) == ['a', 'a', 'b'] + assert list(d.items()) == [('a', 1), ('a', 2), ('b', 4)] + assert d.mixed() == {'a': [1, 2], 'b': 4} # test getone # KeyError: "Multiple values match 'a': [1, 2]" - assert_raises(KeyError, d.getone, 'a') - eq(d.getone('b'), 4) + with pytest.raises(KeyError): + d.getone('a') + + assert d.getone('b') == 4 # KeyError: "Key not found: 'g'" - assert_raises(KeyError, d.getone, 'g') + with pytest.raises(KeyError): + d.getone('g') - eq(d.dict_of_lists(), {'a': [1, 2], 'b': [4]}) + assert d.dict_of_lists() == {'a': [1, 2], 'b': [4]} assert 'b' in d assert 'e' not in d d.clear() @@ -107,28 +105,29 @@ def test_multidict(): e.clear() e['f'] = 42 d.update(e) - eq(d, MultiDict([('a', 4), ('a', 5), ('f', 42)])) + assert d == MultiDict([('a', 4), ('a', 5), ('f', 42)]) f = d.pop('a') - eq(f, 4) - eq(d['a'], 5) - + assert f == 4 + assert d['a'] == 5 - eq(d.pop('g', 42), 42) - assert_raises(KeyError, d.pop, 'n') + assert d.pop('g', 42) == 42 + with pytest.raises(KeyError): + d.pop('n') # TypeError: pop expected at most 2 arguments, got 3 - assert_raises(TypeError, d.pop, 4, 2, 3) + with pytest.raises(TypeError): + d.pop(4, 2, 3) d.setdefault('g', []).append(4) - eq(d, MultiDict([('a', 5), ('f', 42), ('g', [4])])) - - + assert d == MultiDict([('a', 5), ('f', 42), ('g', [4])]) def test_multidict_init(): d = MultiDict([('a', 'b')], c=2) - eq(repr(d), "MultiDict([('a', 'b'), ('c', 2)])") - eq(d, MultiDict([('a', 'b')], c=2)) + assert repr(d) == "MultiDict([('a', 'b'), ('c', 2)])" + assert d == MultiDict([('a', 'b')], c=2) # TypeError: MultiDict can only be called with one positional argument - assert_raises(TypeError, MultiDict, 1, 2, 3) + with pytest.raises(TypeError): + MultiDict(1, 2, 3) # TypeError: MultiDict.view_list(obj) takes only actual list objects, not None - assert_raises(TypeError, MultiDict.view_list, None) + with pytest.raises(TypeError): + MultiDict.view_list(None) |
