mirror of https://github.com/yandex/gixy
Convert assertions with nose2pytest
parent
3bf5110983
commit
df9655e00d
|
@ -6,7 +6,7 @@ from gixy.core.regexp import Regexp
|
|||
|
||||
|
||||
def setup():
|
||||
assert_equals(len(CONTEXTS), 0)
|
||||
assert len(CONTEXTS) == 0
|
||||
|
||||
|
||||
def tear_down():
|
||||
|
@ -17,39 +17,39 @@ def tear_down():
|
|||
def test_push_pop_context():
|
||||
root_a = Root()
|
||||
push_context(root_a)
|
||||
assert_equals(len(CONTEXTS), 1)
|
||||
assert len(CONTEXTS) == 1
|
||||
root_b = Root()
|
||||
push_context(root_b)
|
||||
assert_equals(len(CONTEXTS), 2)
|
||||
assert len(CONTEXTS) == 2
|
||||
|
||||
poped = pop_context()
|
||||
assert_equals(len(CONTEXTS), 1)
|
||||
assert_equals(poped.block, root_b)
|
||||
assert len(CONTEXTS) == 1
|
||||
assert poped.block == root_b
|
||||
poped = pop_context()
|
||||
assert_equals(len(CONTEXTS), 0)
|
||||
assert_equals(poped.block, root_a)
|
||||
assert len(CONTEXTS) == 0
|
||||
assert poped.block == root_a
|
||||
|
||||
|
||||
@with_setup(setup, tear_down)
|
||||
def test_push_get_purge_context():
|
||||
root = Root()
|
||||
push_context(root)
|
||||
assert_equals(len(CONTEXTS), 1)
|
||||
assert_equals(get_context().block, root)
|
||||
assert len(CONTEXTS) == 1
|
||||
assert get_context().block == root
|
||||
root = Root()
|
||||
push_context(root)
|
||||
assert_equals(len(CONTEXTS), 2)
|
||||
assert_equals(get_context().block, root)
|
||||
assert len(CONTEXTS) == 2
|
||||
assert get_context().block == root
|
||||
|
||||
purge_context()
|
||||
assert_equals(len(CONTEXTS), 0)
|
||||
assert len(CONTEXTS) == 0
|
||||
|
||||
|
||||
@with_setup(setup, tear_down)
|
||||
def test_add_variables():
|
||||
context = push_context(Root())
|
||||
assert_equals(len(context.variables['index']), 0)
|
||||
assert_equals(len(context.variables['name']), 0)
|
||||
assert len(context.variables['index']) == 0
|
||||
assert len(context.variables['name']) == 0
|
||||
|
||||
one_str_var = Variable('1')
|
||||
context.add_var('1', one_str_var)
|
||||
|
@ -58,77 +58,77 @@ def test_add_variables():
|
|||
some_var = Variable('some')
|
||||
context.add_var('some', some_var)
|
||||
|
||||
assert_equals(len(context.variables['index']), 1)
|
||||
assert_equals(context.variables['index'][1], one_int_var)
|
||||
assert_equals(len(context.variables['name']), 1)
|
||||
assert_equals(context.variables['name']['some'], some_var)
|
||||
assert len(context.variables['index']) == 1
|
||||
assert context.variables['index'][1] == one_int_var
|
||||
assert len(context.variables['name']) == 1
|
||||
assert context.variables['name']['some'] == some_var
|
||||
context.clear_index_vars()
|
||||
assert_equals(len(context.variables['index']), 0)
|
||||
assert_equals(len(context.variables['name']), 1)
|
||||
assert_equals(context.variables['name']['some'], some_var)
|
||||
assert len(context.variables['index']) == 0
|
||||
assert len(context.variables['name']) == 1
|
||||
assert context.variables['name']['some'] == some_var
|
||||
|
||||
|
||||
@with_setup(setup, tear_down)
|
||||
def test_get_variables():
|
||||
context = push_context(Root())
|
||||
assert_equals(len(context.variables['index']), 0)
|
||||
assert_equals(len(context.variables['name']), 0)
|
||||
assert len(context.variables['index']) == 0
|
||||
assert len(context.variables['name']) == 0
|
||||
|
||||
one_var = Variable(1)
|
||||
context.add_var(1, one_var)
|
||||
some_var = Variable('some')
|
||||
context.add_var('some', some_var)
|
||||
|
||||
assert_equals(context.get_var(1), one_var)
|
||||
assert_equals(context.get_var('some'), some_var)
|
||||
assert context.get_var(1) == one_var
|
||||
assert context.get_var('some') == some_var
|
||||
# Checks not existed variables, for now context may return None
|
||||
assert_equals(context.get_var(0), None)
|
||||
assert_equals(context.get_var('not_existed'), None)
|
||||
assert context.get_var(0) == None
|
||||
assert context.get_var('not_existed') == None
|
||||
# Checks builtins variables
|
||||
assert_true(context.get_var('uri'))
|
||||
assert_true(context.get_var('document_uri'))
|
||||
assert_true(context.get_var('arg_asdsadasd'))
|
||||
assert_true(context.get_var('args'))
|
||||
assert context.get_var('uri')
|
||||
assert context.get_var('document_uri')
|
||||
assert context.get_var('arg_asdsadasd')
|
||||
assert context.get_var('args')
|
||||
|
||||
|
||||
@with_setup(setup, tear_down)
|
||||
def test_context_depend_variables():
|
||||
push_context(Root())
|
||||
assert_equals(len(get_context().variables['index']), 0)
|
||||
assert_equals(len(get_context().variables['name']), 0)
|
||||
assert len(get_context().variables['index']) == 0
|
||||
assert len(get_context().variables['name']) == 0
|
||||
|
||||
get_context().add_var(1, Variable(1, value='one'))
|
||||
get_context().add_var('some', Variable('some', value='some'))
|
||||
|
||||
assert_equals(get_context().get_var(1).value, 'one')
|
||||
assert_equals(get_context().get_var('some').value, 'some')
|
||||
assert get_context().get_var(1).value == 'one'
|
||||
assert get_context().get_var('some').value == 'some'
|
||||
|
||||
# Checks top context variables are still exists
|
||||
push_context(Root())
|
||||
assert_equals(get_context().get_var(1).value, 'one')
|
||||
assert_equals(get_context().get_var('some').value, 'some')
|
||||
assert get_context().get_var(1).value == 'one'
|
||||
assert get_context().get_var('some').value == 'some'
|
||||
|
||||
# Checks variable overriding
|
||||
get_context().add_var('some', Variable('some', value='some_new'))
|
||||
get_context().add_var('foo', Variable('foo', value='foo'))
|
||||
assert_not_equals(get_context().get_var('some').value, 'some')
|
||||
assert_equals(get_context().get_var('some').value, 'some_new')
|
||||
assert_equals(get_context().get_var('foo').value, 'foo')
|
||||
assert_equals(get_context().get_var(1).value, 'one')
|
||||
assert get_context().get_var('some').value == 'some_new'
|
||||
assert get_context().get_var('foo').value == 'foo'
|
||||
assert get_context().get_var(1).value == 'one'
|
||||
|
||||
# Checks variables after restore previous context
|
||||
pop_context()
|
||||
assert_not_equals(get_context().get_var('some').value, 'some_new')
|
||||
assert_equals(get_context().get_var('some').value, 'some')
|
||||
assert_equals(get_context().get_var('foo'), None)
|
||||
assert_equals(get_context().get_var(1).value, 'one')
|
||||
assert get_context().get_var('some').value == 'some'
|
||||
assert get_context().get_var('foo') == None
|
||||
assert get_context().get_var(1).value == 'one'
|
||||
|
||||
|
||||
@with_setup(setup, tear_down)
|
||||
def test_push_failed_with_regexp_py35_gixy_10():
|
||||
push_context(Root())
|
||||
assert_equals(len(get_context().variables['index']), 0)
|
||||
assert_equals(len(get_context().variables['name']), 0)
|
||||
assert len(get_context().variables['index']) == 0
|
||||
assert len(get_context().variables['name']) == 0
|
||||
|
||||
regexp = Regexp('^/some/(.*?)')
|
||||
for name, group in regexp.groups.items():
|
||||
|
|
|
@ -258,145 +258,124 @@ def test_generate():
|
|||
|
||||
def test_strict_generate():
|
||||
reg = Regexp('^foo|bar', strict=True)
|
||||
assert_equals(sorted(reg.generate('|', anchored=True)), sorted(['^foo', '^bar']))
|
||||
assert sorted(reg.generate('|', anchored=True)) == sorted(['^foo', '^bar'])
|
||||
|
||||
|
||||
def test_gen_anchor():
|
||||
|
||||
reg = Regexp('^some$')
|
||||
val = next(reg.generate('', anchored=False))
|
||||
assert_equals(val, 'some')
|
||||
assert val == 'some'
|
||||
|
||||
reg = Regexp('^some$')
|
||||
val = next(reg.generate('', anchored=True))
|
||||
assert_equals(val, '^some$')
|
||||
assert val == '^some$'
|
||||
|
||||
reg = Regexp('^some$', strict=True)
|
||||
val = next(reg.generate('', anchored=False))
|
||||
assert_equals(val, 'some')
|
||||
assert val == 'some'
|
||||
|
||||
reg = Regexp('^some$', strict=True)
|
||||
val = next(reg.generate('', anchored=True))
|
||||
assert_equals(val, '^some$')
|
||||
assert val == '^some$'
|
||||
|
||||
|
||||
def test_group_can_contains():
|
||||
source = '/some/(?P<action>[^/:.]+)/'
|
||||
reg = Regexp(source)
|
||||
assert_true(reg.can_contain('\n'),
|
||||
'Whole regex "{src}" can contains {sym!r}'.format(src=source, sym='\\n'))
|
||||
assert reg.can_contain('\n'), 'Whole regex "{src}" can contains {sym!r}'.format(src=source, sym='\\n')
|
||||
|
||||
assert_true(reg.group(0).can_contain('\n'),
|
||||
'Group 0 from regex "{src}" can contains {sym!r}'.format(src=source, sym='\\n'))
|
||||
assert reg.group(0).can_contain('\n'), 'Group 0 from regex "{src}" can contains {sym!r}'.format(src=source, sym='\\n')
|
||||
|
||||
assert_true(reg.group('action').can_contain('\n'),
|
||||
'Group "action" from regex "{src}" can contains {sym!r}'.format(src=source, sym='\\n'))
|
||||
assert reg.group('action').can_contain('\n'), 'Group "action" from regex "{src}" can contains {sym!r}'.format(src=source, sym='\\n')
|
||||
|
||||
assert_true(reg.group(1).can_contain('\n'),
|
||||
'Group 1 from regex "{src}" can contains {sym!r}'.format(src=source, sym='\\n'))
|
||||
assert reg.group(1).can_contain('\n'), 'Group 1 from regex "{src}" can contains {sym!r}'.format(src=source, sym='\\n')
|
||||
|
||||
assert_false(reg.group('action').can_contain('/'),
|
||||
'Group "action" from regex "{src}" CAN\'T (!) contain {sym!r}'.format(src=source, sym='/'))
|
||||
assert not reg.group('action').can_contain('/'), 'Group "action" from regex "{src}" CAN\'T (!) contain {sym!r}'.format(src=source, sym='/')
|
||||
|
||||
|
||||
def check_positive_contain(regexp, char):
|
||||
reg = Regexp(regexp, case_sensitive=True)
|
||||
assert_true(reg.can_contain(char),
|
||||
'{reg!r} should contain {chr!r}'.format(reg=regexp, chr=char))
|
||||
assert reg.can_contain(char), '{reg!r} should contain {chr!r}'.format(reg=regexp, chr=char)
|
||||
|
||||
reg = Regexp(regexp, case_sensitive=False)
|
||||
char = char.upper()
|
||||
assert_true(reg.can_contain(char),
|
||||
'{reg!r} (case insensitive) should contain {chr!r}'.format(reg=regexp, chr=char))
|
||||
assert reg.can_contain(char), '{reg!r} (case insensitive) should contain {chr!r}'.format(reg=regexp, chr=char)
|
||||
|
||||
|
||||
def check_negative_contain(regexp, char):
|
||||
reg = Regexp(regexp, case_sensitive=True)
|
||||
assert_false(reg.can_contain(char),
|
||||
'{reg!r} should not contain {chr!r}'.format(reg=regexp, chr=char))
|
||||
assert not reg.can_contain(char), '{reg!r} should not contain {chr!r}'.format(reg=regexp, chr=char)
|
||||
|
||||
reg = Regexp(regexp, case_sensitive=False)
|
||||
char = char.upper()
|
||||
assert_false(reg.can_contain(char),
|
||||
'{reg!r} (case insensitive) should not contain {chr!r}'.format(reg=regexp, chr=char))
|
||||
assert not reg.can_contain(char), '{reg!r} (case insensitive) should not contain {chr!r}'.format(reg=regexp, chr=char)
|
||||
|
||||
|
||||
def check_positive_startswith(regexp, char, strict):
|
||||
reg = Regexp(regexp, case_sensitive=True, strict=strict)
|
||||
assert_true(reg.can_startswith(char),
|
||||
'{reg!r} can start\'s with {chr!r}'.format(reg=regexp, chr=char))
|
||||
assert reg.can_startswith(char), '{reg!r} can start\'s with {chr!r}'.format(reg=regexp, chr=char)
|
||||
|
||||
reg = Regexp(regexp, case_sensitive=False, strict=strict)
|
||||
char = char.upper()
|
||||
assert_true(reg.can_startswith(char),
|
||||
'{reg!r} (case insensitive) can start\'s with {chr!r}'.format(reg=regexp, chr=char))
|
||||
assert reg.can_startswith(char), '{reg!r} (case insensitive) can start\'s with {chr!r}'.format(reg=regexp, chr=char)
|
||||
|
||||
|
||||
def check_negative_startswith(regexp, char, strict):
|
||||
reg = Regexp(regexp, case_sensitive=True, strict=strict)
|
||||
assert_false(reg.can_startswith(char),
|
||||
'{reg!r} can\'t start\'s with {chr!r}'.format(reg=regexp, chr=char))
|
||||
assert not reg.can_startswith(char), '{reg!r} can\'t start\'s with {chr!r}'.format(reg=regexp, chr=char)
|
||||
|
||||
reg = Regexp(regexp, case_sensitive=False, strict=strict)
|
||||
char = char.upper()
|
||||
assert_false(reg.can_startswith(char),
|
||||
'{reg!r} (case insensitive) can\'t start\'s with {chr!r}'.format(reg=regexp, chr=char))
|
||||
assert not reg.can_startswith(char), '{reg!r} (case insensitive) can\'t start\'s with {chr!r}'.format(reg=regexp, chr=char)
|
||||
|
||||
|
||||
def check_groups_names(regexp, groups):
|
||||
reg = Regexp(regexp)
|
||||
assert_equals(set(reg.groups.keys()), set(groups))
|
||||
assert set(reg.groups.keys()) == set(groups)
|
||||
|
||||
|
||||
def check_to_string(regexp, string):
|
||||
reg = Regexp(regexp)
|
||||
assert_equals(str(reg), string)
|
||||
assert str(reg) == string
|
||||
|
||||
|
||||
def check_positive_must_contain(regexp, char):
|
||||
reg = Regexp(regexp, case_sensitive=True)
|
||||
assert_true(reg.must_contain(char),
|
||||
'{reg!r} must contain with {chr!r}'.format(reg=regexp, chr=char))
|
||||
assert reg.must_contain(char), '{reg!r} must contain with {chr!r}'.format(reg=regexp, chr=char)
|
||||
|
||||
reg = Regexp(regexp, case_sensitive=False)
|
||||
char = char.upper()
|
||||
assert_true(reg.must_contain(char),
|
||||
'{reg!r} (case insensitive) must contain with {chr!r}'.format(reg=regexp, chr=char))
|
||||
assert reg.must_contain(char), '{reg!r} (case insensitive) must contain with {chr!r}'.format(reg=regexp, chr=char)
|
||||
|
||||
|
||||
def check_negative_must_contain(regexp, char):
|
||||
reg = Regexp(regexp, case_sensitive=True)
|
||||
assert_false(reg.must_contain(char),
|
||||
'{reg!r} must NOT contain with {chr!r}'.format(reg=regexp, chr=char))
|
||||
assert not reg.must_contain(char), '{reg!r} must NOT contain with {chr!r}'.format(reg=regexp, chr=char)
|
||||
|
||||
reg = Regexp(regexp, case_sensitive=False)
|
||||
char = char.upper()
|
||||
assert_false(reg.must_contain(char),
|
||||
'{reg!r} (case insensitive) must NOT contain with {chr!r}'.format(reg=regexp, chr=char))
|
||||
assert not reg.must_contain(char), '{reg!r} (case insensitive) must NOT contain with {chr!r}'.format(reg=regexp, chr=char)
|
||||
|
||||
|
||||
def check_positive_must_startswith(regexp, char, strict):
|
||||
reg = Regexp(regexp, case_sensitive=True, strict=strict)
|
||||
assert_true(reg.must_startswith(char),
|
||||
'{reg!r} MUST start\'s with {chr!r}'.format(reg=regexp, chr=char))
|
||||
assert reg.must_startswith(char), '{reg!r} MUST start\'s with {chr!r}'.format(reg=regexp, chr=char)
|
||||
|
||||
reg = Regexp(regexp, case_sensitive=False, strict=strict)
|
||||
char = char.upper()
|
||||
assert_true(reg.must_startswith(char),
|
||||
'{reg!r} (case insensitive) MUST start\'s with {chr!r}'.format(reg=regexp, chr=char))
|
||||
assert reg.must_startswith(char), '{reg!r} (case insensitive) MUST start\'s with {chr!r}'.format(reg=regexp, chr=char)
|
||||
|
||||
|
||||
def check_negative_must_startswith(regexp, char, strict):
|
||||
reg = Regexp(regexp, case_sensitive=True, strict=strict)
|
||||
assert_false(reg.must_startswith(char),
|
||||
'{reg!r} MUST NOT start\'s with {chr!r}'.format(reg=regexp, chr=char))
|
||||
assert not reg.must_startswith(char), '{reg!r} MUST NOT start\'s with {chr!r}'.format(reg=regexp, chr=char)
|
||||
|
||||
reg = Regexp(regexp, case_sensitive=False, strict=strict)
|
||||
char = char.upper()
|
||||
assert_false(reg.must_startswith(char),
|
||||
'{reg!r} (case insensitive) MUST NOT start\'s with {chr!r}'.format(reg=regexp, chr=char))
|
||||
assert not reg.must_startswith(char), '{reg!r} (case insensitive) MUST NOT start\'s with {chr!r}'.format(reg=regexp, chr=char)
|
||||
|
||||
|
||||
def check_generate(regexp, values):
|
||||
reg = Regexp(regexp)
|
||||
assert_equals(sorted(reg.generate('|', anchored=True)), sorted(values))
|
||||
assert sorted(reg.generate('|', anchored=True)) == sorted(values)
|
||||
|
|
|
@ -15,85 +15,85 @@ def tear_down():
|
|||
@with_setup(setup, tear_down)
|
||||
def test_literal():
|
||||
var = Variable(name='simple', value='$uri', have_script=False)
|
||||
assert_false(var.depends)
|
||||
assert_false(var.regexp)
|
||||
assert_equals(var.value, '$uri')
|
||||
assert not var.depends
|
||||
assert not var.regexp
|
||||
assert var.value == '$uri'
|
||||
|
||||
assert_false(var.can_startswith('$'))
|
||||
assert_false(var.can_contain('i'))
|
||||
assert_true(var.must_contain('$'))
|
||||
assert_true(var.must_contain('u'))
|
||||
assert_false(var.must_contain('a'))
|
||||
assert_true(var.must_startswith('$'))
|
||||
assert_false(var.must_startswith('u'))
|
||||
assert not var.can_startswith('$')
|
||||
assert not var.can_contain('i')
|
||||
assert var.must_contain('$')
|
||||
assert var.must_contain('u')
|
||||
assert not var.must_contain('a')
|
||||
assert var.must_startswith('$')
|
||||
assert not var.must_startswith('u')
|
||||
|
||||
|
||||
@with_setup(setup, tear_down)
|
||||
def test_regexp():
|
||||
var = Variable(name='simple', value=Regexp('^/.*'))
|
||||
assert_false(var.depends)
|
||||
assert_true(var.regexp)
|
||||
assert not var.depends
|
||||
assert var.regexp
|
||||
|
||||
assert_true(var.can_startswith('/'))
|
||||
assert_false(var.can_startswith('a'))
|
||||
assert_true(var.can_contain('a'))
|
||||
assert_false(var.can_contain('\n'))
|
||||
assert_true(var.must_contain('/'))
|
||||
assert_false(var.must_contain('a'))
|
||||
assert_true(var.must_startswith('/'))
|
||||
assert_false(var.must_startswith('a'))
|
||||
assert var.can_startswith('/')
|
||||
assert not var.can_startswith('a')
|
||||
assert var.can_contain('a')
|
||||
assert not var.can_contain('\n')
|
||||
assert var.must_contain('/')
|
||||
assert not var.must_contain('a')
|
||||
assert var.must_startswith('/')
|
||||
assert not var.must_startswith('a')
|
||||
|
||||
|
||||
@with_setup(setup, tear_down)
|
||||
def test_script():
|
||||
get_context().add_var('foo', Variable(name='foo', value=Regexp('.*')))
|
||||
var = Variable(name='simple', value='/$foo')
|
||||
assert_true(var.depends)
|
||||
assert_false(var.regexp)
|
||||
assert var.depends
|
||||
assert not var.regexp
|
||||
|
||||
assert_false(var.can_startswith('/'))
|
||||
assert_false(var.can_startswith('a'))
|
||||
assert_true(var.can_contain('/'))
|
||||
assert_true(var.can_contain('a'))
|
||||
assert_false(var.can_contain('\n'))
|
||||
assert_true(var.must_contain('/'))
|
||||
assert_false(var.must_contain('a'))
|
||||
assert_true(var.must_startswith('/'))
|
||||
assert_false(var.must_startswith('a'))
|
||||
assert not var.can_startswith('/')
|
||||
assert not var.can_startswith('a')
|
||||
assert var.can_contain('/')
|
||||
assert var.can_contain('a')
|
||||
assert not var.can_contain('\n')
|
||||
assert var.must_contain('/')
|
||||
assert not var.must_contain('a')
|
||||
assert var.must_startswith('/')
|
||||
assert not var.must_startswith('a')
|
||||
|
||||
|
||||
@with_setup(setup, tear_down)
|
||||
def test_regexp_boundary():
|
||||
var = Variable(name='simple', value=Regexp('.*'), boundary=Regexp('/[a-z]', strict=True))
|
||||
assert_false(var.depends)
|
||||
assert_true(var.regexp)
|
||||
assert not var.depends
|
||||
assert var.regexp
|
||||
|
||||
assert_true(var.can_startswith('/'))
|
||||
assert_false(var.can_startswith('a'))
|
||||
assert_false(var.can_contain('/'))
|
||||
assert_true(var.can_contain('a'))
|
||||
assert_false(var.can_contain('0'))
|
||||
assert_false(var.can_contain('\n'))
|
||||
assert_true(var.must_contain('/'))
|
||||
assert_false(var.must_contain('a'))
|
||||
assert_true(var.must_startswith('/'))
|
||||
assert_false(var.must_startswith('a'))
|
||||
assert var.can_startswith('/')
|
||||
assert not var.can_startswith('a')
|
||||
assert not var.can_contain('/')
|
||||
assert var.can_contain('a')
|
||||
assert not var.can_contain('0')
|
||||
assert not var.can_contain('\n')
|
||||
assert var.must_contain('/')
|
||||
assert not var.must_contain('a')
|
||||
assert var.must_startswith('/')
|
||||
assert not var.must_startswith('a')
|
||||
|
||||
|
||||
@with_setup(setup, tear_down)
|
||||
def test_script_boundary():
|
||||
get_context().add_var('foo', Variable(name='foo', value=Regexp('.*'), boundary=Regexp('[a-z]', strict=True)))
|
||||
var = Variable(name='simple', value='/$foo', boundary=Regexp('[/a-z0-9]', strict=True))
|
||||
assert_true(var.depends)
|
||||
assert_false(var.regexp)
|
||||
assert var.depends
|
||||
assert not var.regexp
|
||||
|
||||
assert_false(var.can_startswith('/'))
|
||||
assert_false(var.can_startswith('a'))
|
||||
assert_false(var.can_contain('/'))
|
||||
assert_true(var.can_contain('a'))
|
||||
assert_false(var.can_contain('\n'))
|
||||
assert_false(var.can_contain('0'))
|
||||
assert_true(var.must_contain('/'))
|
||||
assert_false(var.must_contain('a'))
|
||||
assert_true(var.must_startswith('/'))
|
||||
assert_false(var.must_startswith('a'))
|
||||
assert not var.can_startswith('/')
|
||||
assert not var.can_startswith('a')
|
||||
assert not var.can_contain('/')
|
||||
assert var.can_contain('a')
|
||||
assert not var.can_contain('\n')
|
||||
assert not var.can_contain('0')
|
||||
assert var.must_contain('/')
|
||||
assert not var.must_contain('a')
|
||||
assert var.must_startswith('/')
|
||||
assert not var.must_startswith('a')
|
||||
|
|
|
@ -14,10 +14,10 @@ def test_block():
|
|||
config = 'some {some;}'
|
||||
|
||||
directive = _get_parsed(config)
|
||||
assert_is_instance(directive, Block)
|
||||
assert_true(directive.is_block)
|
||||
assert_true(directive.self_context)
|
||||
assert_false(directive.provide_variables)
|
||||
assert isinstance(directive, Block)
|
||||
assert directive.is_block
|
||||
assert directive.self_context
|
||||
assert not directive.provide_variables
|
||||
|
||||
|
||||
def test_http():
|
||||
|
@ -30,10 +30,10 @@ http {
|
|||
'''
|
||||
|
||||
directive = _get_parsed(config)
|
||||
assert_is_instance(directive, HttpBlock)
|
||||
assert_true(directive.is_block)
|
||||
assert_true(directive.self_context)
|
||||
assert_false(directive.provide_variables)
|
||||
assert isinstance(directive, HttpBlock)
|
||||
assert directive.is_block
|
||||
assert directive.self_context
|
||||
assert not directive.provide_variables
|
||||
|
||||
|
||||
def test_server():
|
||||
|
@ -47,11 +47,11 @@ server {
|
|||
'''
|
||||
|
||||
directive = _get_parsed(config)
|
||||
assert_is_instance(directive, ServerBlock)
|
||||
assert_true(directive.is_block)
|
||||
assert_true(directive.self_context)
|
||||
assert_equals([d.args[0] for d in directive.get_names()], ['_', 'cool.io'])
|
||||
assert_false(directive.provide_variables)
|
||||
assert isinstance(directive, ServerBlock)
|
||||
assert directive.is_block
|
||||
assert directive.self_context
|
||||
assert [d.args[0] for d in directive.get_names()] == ['_', 'cool.io']
|
||||
assert not directive.provide_variables
|
||||
|
||||
|
||||
def test_location():
|
||||
|
@ -61,13 +61,13 @@ location / {
|
|||
'''
|
||||
|
||||
directive = _get_parsed(config)
|
||||
assert_is_instance(directive, LocationBlock)
|
||||
assert_true(directive.is_block)
|
||||
assert_true(directive.self_context)
|
||||
assert_true(directive.provide_variables)
|
||||
assert_is_none(directive.modifier)
|
||||
assert_equals(directive.path, '/')
|
||||
assert_false(directive.is_internal)
|
||||
assert isinstance(directive, LocationBlock)
|
||||
assert directive.is_block
|
||||
assert directive.self_context
|
||||
assert directive.provide_variables
|
||||
assert directive.modifier is None
|
||||
assert directive.path == '/'
|
||||
assert not directive.is_internal
|
||||
|
||||
|
||||
def test_location_internal():
|
||||
|
@ -78,8 +78,8 @@ location / {
|
|||
'''
|
||||
|
||||
directive = _get_parsed(config)
|
||||
assert_is_instance(directive, LocationBlock)
|
||||
assert_true(directive.is_internal)
|
||||
assert isinstance(directive, LocationBlock)
|
||||
assert directive.is_internal
|
||||
|
||||
|
||||
def test_location_modifier():
|
||||
|
@ -89,9 +89,9 @@ location = / {
|
|||
'''
|
||||
|
||||
directive = _get_parsed(config)
|
||||
assert_is_instance(directive, LocationBlock)
|
||||
assert_equals(directive.modifier, '=')
|
||||
assert_equals(directive.path, '/')
|
||||
assert isinstance(directive, LocationBlock)
|
||||
assert directive.modifier == '='
|
||||
assert directive.path == '/'
|
||||
|
||||
|
||||
def test_if():
|
||||
|
@ -101,13 +101,13 @@ if ($some) {
|
|||
'''
|
||||
|
||||
directive = _get_parsed(config)
|
||||
assert_is_instance(directive, IfBlock)
|
||||
assert_true(directive.is_block)
|
||||
assert_false(directive.self_context)
|
||||
assert_false(directive.provide_variables)
|
||||
assert_equals(directive.variable, '$some')
|
||||
assert_is_none(directive.operand)
|
||||
assert_is_none(directive.value)
|
||||
assert isinstance(directive, IfBlock)
|
||||
assert directive.is_block
|
||||
assert not directive.self_context
|
||||
assert not directive.provide_variables
|
||||
assert directive.variable == '$some'
|
||||
assert directive.operand is None
|
||||
assert directive.value is None
|
||||
|
||||
|
||||
def test_if_modifier():
|
||||
|
@ -117,10 +117,10 @@ if (-f /some) {
|
|||
'''
|
||||
|
||||
directive = _get_parsed(config)
|
||||
assert_is_instance(directive, IfBlock)
|
||||
assert_equals(directive.operand, '-f')
|
||||
assert_equals(directive.value, '/some')
|
||||
assert_is_none(directive.variable)
|
||||
assert isinstance(directive, IfBlock)
|
||||
assert directive.operand == '-f'
|
||||
assert directive.value == '/some'
|
||||
assert directive.variable is None
|
||||
|
||||
|
||||
def test_if_variable():
|
||||
|
@ -130,10 +130,10 @@ if ($http_some = '/some') {
|
|||
'''
|
||||
|
||||
directive = _get_parsed(config)
|
||||
assert_is_instance(directive, IfBlock)
|
||||
assert_equals(directive.variable, '$http_some')
|
||||
assert_equals(directive.operand, '=')
|
||||
assert_equals(directive.value, '/some')
|
||||
assert isinstance(directive, IfBlock)
|
||||
assert directive.variable == '$http_some'
|
||||
assert directive.operand == '='
|
||||
assert directive.value == '/some'
|
||||
|
||||
|
||||
def test_block_some_flat():
|
||||
|
@ -150,8 +150,8 @@ def test_block_some_flat():
|
|||
directive = _get_parsed(config)
|
||||
for d in ['default_type', 'sendfile', 'keepalive_timeout']:
|
||||
c = directive.some(d, flat=True)
|
||||
assert_is_not_none(c)
|
||||
assert_equals(c.name, d)
|
||||
assert c is not None
|
||||
assert c.name == d
|
||||
|
||||
|
||||
def test_block_some_not_flat():
|
||||
|
@ -167,7 +167,7 @@ def test_block_some_not_flat():
|
|||
|
||||
directive = _get_parsed(config)
|
||||
c = directive.some('keepalive_timeout', flat=False)
|
||||
assert_is_none(c)
|
||||
assert c is None
|
||||
|
||||
|
||||
def test_block_find_flat():
|
||||
|
@ -182,9 +182,9 @@ def test_block_find_flat():
|
|||
|
||||
directive = _get_parsed(config)
|
||||
finds = directive.find('directive', flat=True)
|
||||
assert_equals(len(finds), 2)
|
||||
assert_equals([x.name for x in finds], ['directive', 'directive'])
|
||||
assert_equals([x.args[0] for x in finds], ['1', '2'])
|
||||
assert len(finds) == 2
|
||||
assert [x.name for x in finds] == ['directive', 'directive']
|
||||
assert [x.args[0] for x in finds] == ['1', '2']
|
||||
|
||||
|
||||
def test_block_find_not_flat():
|
||||
|
@ -199,9 +199,9 @@ def test_block_find_not_flat():
|
|||
|
||||
directive = _get_parsed(config)
|
||||
finds = directive.find('directive', flat=False)
|
||||
assert_equals(len(finds), 1)
|
||||
assert_equals([x.name for x in finds], ['directive'])
|
||||
assert_equals([x.args[0] for x in finds], ['1'])
|
||||
assert len(finds) == 1
|
||||
assert [x.name for x in finds] == ['directive']
|
||||
assert [x.args[0] for x in finds] == ['1']
|
||||
|
||||
|
||||
def test_block_map():
|
||||
|
@ -213,11 +213,11 @@ map $some_var $some_other_var {
|
|||
'''
|
||||
|
||||
directive = _get_parsed(config)
|
||||
assert_is_instance(directive, MapBlock)
|
||||
assert_true(directive.is_block)
|
||||
assert_false(directive.self_context)
|
||||
assert_true(directive.provide_variables)
|
||||
assert_equals(directive.variable, 'some_other_var')
|
||||
assert isinstance(directive, MapBlock)
|
||||
assert directive.is_block
|
||||
assert not directive.self_context
|
||||
assert directive.provide_variables
|
||||
assert directive.variable == 'some_other_var'
|
||||
|
||||
|
||||
def test_block_geo_two_vars():
|
||||
|
@ -229,11 +229,11 @@ geo $some_var $some_other_var {
|
|||
'''
|
||||
|
||||
directive = _get_parsed(config)
|
||||
assert_is_instance(directive, GeoBlock)
|
||||
assert_true(directive.is_block)
|
||||
assert_false(directive.self_context)
|
||||
assert_true(directive.provide_variables)
|
||||
assert_equals(directive.variable, 'some_other_var')
|
||||
assert isinstance(directive, GeoBlock)
|
||||
assert directive.is_block
|
||||
assert not directive.self_context
|
||||
assert directive.provide_variables
|
||||
assert directive.variable == 'some_other_var'
|
||||
|
||||
|
||||
def test_block_geo_one_var():
|
||||
|
@ -245,8 +245,8 @@ geo $some_var {
|
|||
'''
|
||||
|
||||
directive = _get_parsed(config)
|
||||
assert_is_instance(directive, GeoBlock)
|
||||
assert_true(directive.is_block)
|
||||
assert_false(directive.self_context)
|
||||
assert_true(directive.provide_variables)
|
||||
assert_equals(directive.variable, 'some_var')
|
||||
assert isinstance(directive, GeoBlock)
|
||||
assert directive.is_block
|
||||
assert not directive.self_context
|
||||
assert directive.provide_variables
|
||||
assert directive.variable == 'some_var'
|
||||
|
|
|
@ -12,89 +12,89 @@ def test_directive():
|
|||
config = 'some "foo" "bar";'
|
||||
|
||||
directive = _get_parsed(config)
|
||||
assert_is_instance(directive, Directive)
|
||||
assert_equals(directive.name, 'some')
|
||||
assert_equals(directive.args, ['foo', 'bar'])
|
||||
assert_equals(str(directive), 'some foo bar;')
|
||||
assert isinstance(directive, Directive)
|
||||
assert directive.name == 'some'
|
||||
assert directive.args == ['foo', 'bar']
|
||||
assert str(directive) == 'some foo bar;'
|
||||
|
||||
|
||||
def test_add_header():
|
||||
config = 'add_header "X-Foo" "bar";'
|
||||
|
||||
directive = _get_parsed(config)
|
||||
assert_is_instance(directive, AddHeaderDirective)
|
||||
assert_equals(directive.name, 'add_header')
|
||||
assert_equals(directive.args, ['X-Foo', 'bar'])
|
||||
assert_equals(directive.header, 'x-foo')
|
||||
assert_equals(directive.value, 'bar')
|
||||
assert_false(directive.always)
|
||||
assert_equals(str(directive), 'add_header X-Foo bar;')
|
||||
assert isinstance(directive, AddHeaderDirective)
|
||||
assert directive.name == 'add_header'
|
||||
assert directive.args == ['X-Foo', 'bar']
|
||||
assert directive.header == 'x-foo'
|
||||
assert directive.value == 'bar'
|
||||
assert not directive.always
|
||||
assert str(directive) == 'add_header X-Foo bar;'
|
||||
|
||||
|
||||
def test_add_header_always():
|
||||
config = 'add_header "X-Foo" "bar" always;'
|
||||
|
||||
directive = _get_parsed(config)
|
||||
assert_is_instance(directive, AddHeaderDirective)
|
||||
assert_equals(directive.name, 'add_header')
|
||||
assert_equals(directive.args, ['X-Foo', 'bar', 'always'])
|
||||
assert_equals(directive.header, 'x-foo')
|
||||
assert_equals(directive.value, 'bar')
|
||||
assert_true(directive.always)
|
||||
assert_equals(str(directive), 'add_header X-Foo bar always;')
|
||||
assert isinstance(directive, AddHeaderDirective)
|
||||
assert directive.name == 'add_header'
|
||||
assert directive.args == ['X-Foo', 'bar', 'always']
|
||||
assert directive.header == 'x-foo'
|
||||
assert directive.value == 'bar'
|
||||
assert directive.always
|
||||
assert str(directive) == 'add_header X-Foo bar always;'
|
||||
|
||||
|
||||
def test_set():
|
||||
config = 'set $foo bar;'
|
||||
|
||||
directive = _get_parsed(config)
|
||||
assert_is_instance(directive, SetDirective)
|
||||
assert_equals(directive.name, 'set')
|
||||
assert_equals(directive.args, ['$foo', 'bar'])
|
||||
assert_equals(directive.variable, 'foo')
|
||||
assert_equals(directive.value, 'bar')
|
||||
assert_equals(str(directive), 'set $foo bar;')
|
||||
assert_true(directive.provide_variables)
|
||||
assert isinstance(directive, SetDirective)
|
||||
assert directive.name == 'set'
|
||||
assert directive.args == ['$foo', 'bar']
|
||||
assert directive.variable == 'foo'
|
||||
assert directive.value == 'bar'
|
||||
assert str(directive) == 'set $foo bar;'
|
||||
assert directive.provide_variables
|
||||
|
||||
|
||||
def test_rewrite():
|
||||
config = 'rewrite ^ http://some;'
|
||||
|
||||
directive = _get_parsed(config)
|
||||
assert_is_instance(directive, RewriteDirective)
|
||||
assert_equals(directive.name, 'rewrite')
|
||||
assert_equals(directive.args, ['^', 'http://some'])
|
||||
assert_equals(str(directive), 'rewrite ^ http://some;')
|
||||
assert_true(directive.provide_variables)
|
||||
assert isinstance(directive, RewriteDirective)
|
||||
assert directive.name == 'rewrite'
|
||||
assert directive.args == ['^', 'http://some']
|
||||
assert str(directive) == 'rewrite ^ http://some;'
|
||||
assert directive.provide_variables
|
||||
|
||||
assert_equals(directive.pattern, '^')
|
||||
assert_equals(directive.replace, 'http://some')
|
||||
assert_equals(directive.flag, None)
|
||||
assert directive.pattern == '^'
|
||||
assert directive.replace == 'http://some'
|
||||
assert directive.flag == None
|
||||
|
||||
|
||||
def test_rewrite_flags():
|
||||
config = 'rewrite ^/(.*)$ http://some/$1 redirect;'
|
||||
|
||||
directive = _get_parsed(config)
|
||||
assert_is_instance(directive, RewriteDirective)
|
||||
assert_equals(directive.name, 'rewrite')
|
||||
assert_equals(directive.args, ['^/(.*)$', 'http://some/$1', 'redirect'])
|
||||
assert_equals(str(directive), 'rewrite ^/(.*)$ http://some/$1 redirect;')
|
||||
assert_true(directive.provide_variables)
|
||||
assert isinstance(directive, RewriteDirective)
|
||||
assert directive.name == 'rewrite'
|
||||
assert directive.args == ['^/(.*)$', 'http://some/$1', 'redirect']
|
||||
assert str(directive) == 'rewrite ^/(.*)$ http://some/$1 redirect;'
|
||||
assert directive.provide_variables
|
||||
|
||||
assert_equals(directive.pattern, '^/(.*)$')
|
||||
assert_equals(directive.replace, 'http://some/$1')
|
||||
assert_equals(directive.flag, 'redirect')
|
||||
assert directive.pattern == '^/(.*)$'
|
||||
assert directive.replace == 'http://some/$1'
|
||||
assert directive.flag == 'redirect'
|
||||
|
||||
|
||||
def test_root():
|
||||
config = 'root /var/www/html;'
|
||||
|
||||
directive = _get_parsed(config)
|
||||
assert_is_instance(directive, RootDirective)
|
||||
assert_equals(directive.name, 'root')
|
||||
assert_equals(directive.args, ['/var/www/html'])
|
||||
assert_equals(str(directive), 'root /var/www/html;')
|
||||
assert_true(directive.provide_variables)
|
||||
assert isinstance(directive, RootDirective)
|
||||
assert directive.name == 'root'
|
||||
assert directive.args == ['/var/www/html']
|
||||
assert str(directive) == 'root /var/www/html;'
|
||||
assert directive.provide_variables
|
||||
|
||||
assert_equals(directive.path, '/var/www/html')
|
||||
assert directive.path == '/var/www/html'
|
||||
|
|
|
@ -64,38 +64,38 @@ server {
|
|||
'''
|
||||
|
||||
tree = _parse(config)
|
||||
assert_is_instance(tree, Directive)
|
||||
assert_is_instance(tree, Block)
|
||||
assert_is_instance(tree, Root)
|
||||
assert isinstance(tree, Directive)
|
||||
assert isinstance(tree, Block)
|
||||
assert isinstance(tree, Root)
|
||||
|
||||
assert_equal(len(tree.children), 1)
|
||||
assert len(tree.children) == 1
|
||||
http = tree.children[0]
|
||||
assert_is_instance(http, Directive)
|
||||
assert_is_instance(http, Block)
|
||||
assert_is_instance(http, HttpBlock)
|
||||
assert isinstance(http, Directive)
|
||||
assert isinstance(http, Block)
|
||||
assert isinstance(http, HttpBlock)
|
||||
|
||||
assert_equal(len(http.children), 1)
|
||||
assert len(http.children) == 1
|
||||
include_server = http.children[0]
|
||||
assert_is_instance(include_server, Directive)
|
||||
assert_is_instance(include_server, IncludeBlock)
|
||||
assert_equal(include_server.file_path, '/etc/nginx/sites/default.conf')
|
||||
assert isinstance(include_server, Directive)
|
||||
assert isinstance(include_server, IncludeBlock)
|
||||
assert include_server.file_path == '/etc/nginx/sites/default.conf'
|
||||
|
||||
assert_equal(len(include_server.children), 1)
|
||||
assert len(include_server.children) == 1
|
||||
server = include_server.children[0]
|
||||
assert_is_instance(server, Directive)
|
||||
assert_is_instance(server, Block)
|
||||
assert_is_instance(server, ServerBlock)
|
||||
assert isinstance(server, Directive)
|
||||
assert isinstance(server, Block)
|
||||
assert isinstance(server, ServerBlock)
|
||||
|
||||
assert_equal(len(server.children), 1)
|
||||
assert len(server.children) == 1
|
||||
include_listen = server.children[0]
|
||||
assert_is_instance(include_listen, Directive)
|
||||
assert_is_instance(include_listen, IncludeBlock)
|
||||
assert_equal(include_listen.file_path, '/etc/nginx/conf.d/listen')
|
||||
assert isinstance(include_listen, Directive)
|
||||
assert isinstance(include_listen, IncludeBlock)
|
||||
assert include_listen.file_path == '/etc/nginx/conf.d/listen'
|
||||
|
||||
assert_equal(len(include_listen.children), 1)
|
||||
assert len(include_listen.children) == 1
|
||||
listen = include_listen.children[0]
|
||||
assert_is_instance(listen, Directive)
|
||||
assert_equal(listen.args, ['80'])
|
||||
assert isinstance(listen, Directive)
|
||||
assert listen.args == ['80']
|
||||
|
||||
|
||||
def test_encoding():
|
||||
|
@ -109,10 +109,10 @@ def test_encoding():
|
|||
|
||||
def assert_config(config, expected):
|
||||
tree = _parse(config)
|
||||
assert_is_instance(tree, Directive)
|
||||
assert_is_instance(tree, Block)
|
||||
assert_is_instance(tree, Root)
|
||||
assert isinstance(tree, Directive)
|
||||
assert isinstance(tree, Block)
|
||||
assert isinstance(tree, Root)
|
||||
|
||||
child = tree.children[0]
|
||||
for ex in expected:
|
||||
assert_is_instance(child, ex)
|
||||
assert isinstance(child, ex)
|
||||
|
|
|
@ -556,9 +556,9 @@ add_header X-Test "Windows-1251";
|
|||
'''
|
||||
|
||||
actual = RawParser().parse(config)
|
||||
assert_equals(len(actual.asList()), 2)
|
||||
assert len(actual.asList()) == 2
|
||||
|
||||
|
||||
def assert_config(config, expected):
|
||||
actual = RawParser().parse(config)
|
||||
assert_equals(actual.asList(), expected)
|
||||
assert actual.asList() == expected
|
||||
|
|
|
@ -53,10 +53,8 @@ def test_from_config():
|
|||
manager = PluginsManager()
|
||||
for plugin in manager.plugins:
|
||||
plugin = plugin.name
|
||||
assert_true(plugin in tested_plugins,
|
||||
'Plugin {name!r} should have at least one simple test config'.format(name=plugin))
|
||||
assert_true(plugin in tested_fp_plugins,
|
||||
'Plugin {name!r} should have at least one simple test config with false positive'.format(name=plugin))
|
||||
assert plugin in tested_plugins, 'Plugin {name!r} should have at least one simple test config'.format(name=plugin)
|
||||
assert plugin in tested_fp_plugins, 'Plugin {name!r} should have at least one simple test config with false positive'.format(name=plugin)
|
||||
|
||||
|
||||
def parse_plugin_options(config_path):
|
||||
|
@ -85,24 +83,22 @@ def check_configuration(plugin, config_path, test_config):
|
|||
formatter.feed(config_path, yoda)
|
||||
_, results = formatter.reports.popitem()
|
||||
|
||||
assert_equals(len(results), 1, 'Should have one report')
|
||||
assert len(results) == 1, 'Should have one report'
|
||||
result = results[0]
|
||||
|
||||
if 'severity' in test_config:
|
||||
if not hasattr(test_config['severity'], '__iter__'):
|
||||
assert_equals(result['severity'], test_config['severity'])
|
||||
assert result['severity'] == test_config['severity']
|
||||
else:
|
||||
assert_in(result['severity'], test_config['severity'])
|
||||
assert_equals(result['plugin'], plugin)
|
||||
assert_true(result['summary'])
|
||||
assert_true(result['description'])
|
||||
assert_true(result['config'])
|
||||
assert_true(result['help_url'].startswith('https://'),
|
||||
'help_url must starts with https://. It\'is URL!')
|
||||
assert result['severity'] in test_config['severity']
|
||||
assert result['plugin'] == plugin
|
||||
assert result['summary']
|
||||
assert result['description']
|
||||
assert result['config']
|
||||
assert result['help_url'].startswith('https://'), 'help_url must starts with https://. It\'is URL!'
|
||||
|
||||
|
||||
def check_configuration_fp(plugin, config_path, test_config):
|
||||
with yoda_provider(plugin) as yoda:
|
||||
yoda.audit(config_path, open(config_path, mode='r'))
|
||||
assert_equals(len([x for x in yoda.results]), 0,
|
||||
'False positive configuration must not trigger any plugins')
|
||||
assert len([x for x in yoda.results]) == 0, 'False positive configuration must not trigger any plugins'
|
||||
|
|
Loading…
Reference in New Issue