Skip to content

Commit

Permalink
Merge pull request #9 from emilazy/push-upnrwkymxnut
Browse files Browse the repository at this point in the history
Migrate tests to pytest
  • Loading branch information
dvershinin authored Aug 17, 2024
2 parents ea9ae26 + e0944a2 commit b20bed7
Show file tree
Hide file tree
Showing 12 changed files with 559 additions and 708 deletions.
5 changes: 2 additions & 3 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
nose>=1.3.7
mock>=2.0.0
pytest>=7.0.0
coverage>=4.3
flake8>=3.2
tox>=2.7.0
tox>=2.7.0
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
entry_points={
'console_scripts': ['gixy=gixy.cli.main:main'],
},
test_suite='nose.collector',
packages=find_packages(exclude=['tests', 'tests.*']),
classifiers=[
'Development Status :: 3 - Alpha',
Expand Down
36 changes: 0 additions & 36 deletions tests/asserts.py

This file was deleted.

105 changes: 49 additions & 56 deletions tests/core/test_context.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,51 @@
from nose.tools import with_setup, assert_equals, assert_not_equals, assert_true
from gixy.core.context import get_context, pop_context, push_context, purge_context, CONTEXTS, Context
from gixy.directives.block import Root
from gixy.core.variable import Variable
from gixy.core.regexp import Regexp


def setup():
assert_equals(len(CONTEXTS), 0)
def setup_function():
assert len(CONTEXTS) == 0


def tear_down():
def teardown_function():
purge_context()


@with_setup(setup, 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)
Expand All @@ -58,77 +54,74 @@ 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'
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_new'
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():
Expand Down
Loading

0 comments on commit b20bed7

Please sign in to comment.