diff options
| author | Victor Uriarte <victor.m.uriarte@intel.com> | 2016-06-19 14:20:25 -0700 |
|---|---|---|
| committer | Victor Uriarte <victor.m.uriarte@intel.com> | 2016-06-20 07:41:13 -0700 |
| commit | 8ebd43d8109c6ecaf4964634e3bd782e8bd769d5 (patch) | |
| tree | 892c56b4a2699ee790a66872d58a925acfd10bc7 /tests/test_parse.py | |
| parent | 5d50f349cda37986bb3704e8fe25d57c78e6047a (diff) | |
| download | sqlparse-8ebd43d8109c6ecaf4964634e3bd782e8bd769d5.tar.gz | |
Parametrize tests
Allows for tests to continue if the first assert had failed.
In particular useful when certain change is dealing with two
almost opposing edge cases.
Diffstat (limited to 'tests/test_parse.py')
| -rw-r--r-- | tests/test_parse.py | 57 |
1 files changed, 17 insertions, 40 deletions
diff --git a/tests/test_parse.py b/tests/test_parse.py index aa2cd15..2d23425 100644 --- a/tests/test_parse.py +++ b/tests/test_parse.py @@ -25,17 +25,11 @@ def test_parse_multistatement(): assert str(stmts[1]) == sql2 -def test_parse_newlines(): - s = 'select\n*from foo;' - p = sqlparse.parse(s)[0] - assert str(p) == s - s = 'select\r\n*from foo' - p = sqlparse.parse(s)[0] - assert str(p) == s - s = 'select\r*from foo' - p = sqlparse.parse(s)[0] - assert str(p) == s - s = 'select\r\n*from foo\n' +@pytest.mark.parametrize('s', ['select\n*from foo;', + 'select\r\n*from foo', + 'select\r*from foo', + 'select\r\n*from foo\n']) +def test_parse_newlines(s): p = sqlparse.parse(s)[0] assert str(p) == s @@ -66,40 +60,23 @@ def test_parse_has_ancestor(): assert baz.has_ancestor(p) -def test_parse_float(): - t = sqlparse.parse('.5')[0].tokens - assert len(t) == 1 - assert t[0].ttype is sqlparse.tokens.Number.Float - t = sqlparse.parse('.51')[0].tokens - assert len(t) == 1 - assert t[0].ttype is sqlparse.tokens.Number.Float - t = sqlparse.parse('1.5')[0].tokens - assert len(t) == 1 - assert t[0].ttype is sqlparse.tokens.Number.Float - t = sqlparse.parse('12.5')[0].tokens +@pytest.mark.parametrize('s', ['.5', '.51', '1.5', '12.5']) +def test_parse_float(s): + t = sqlparse.parse(s)[0].tokens assert len(t) == 1 assert t[0].ttype is sqlparse.tokens.Number.Float -def test_parse_placeholder(): - def _get_tokens(s): - return sqlparse.parse(s)[0].tokens[-1].tokens - - t = _get_tokens('select * from foo where user = ?') - assert t[-1].ttype is sqlparse.tokens.Name.Placeholder - assert t[-1].value == '?' - t = _get_tokens('select * from foo where user = :1') - assert t[-1].ttype is sqlparse.tokens.Name.Placeholder - assert t[-1].value == ':1' - t = _get_tokens('select * from foo where user = :name') - assert t[-1].ttype is sqlparse.tokens.Name.Placeholder - assert t[-1].value == ':name' - t = _get_tokens('select * from foo where user = %s') - assert t[-1].ttype is sqlparse.tokens.Name.Placeholder - assert t[-1].value == '%s' - t = _get_tokens('select * from foo where user = $a') +@pytest.mark.parametrize('s, holder', [ + ('select * from foo where user = ?', '?'), + ('select * from foo where user = :1', ':1'), + ('select * from foo where user = :name', ':name'), + ('select * from foo where user = %s', '%s'), + ('select * from foo where user = $a', '$a')]) +def test_parse_placeholder(s, holder): + t = sqlparse.parse(s)[0].tokens[-1].tokens assert t[-1].ttype is sqlparse.tokens.Name.Placeholder - assert t[-1].value == '$a' + assert t[-1].value == holder def test_parse_modulo_not_placeholder(): |
