Skip to content

Commit

Permalink
Merge pull request #392 from dshulyak/allow_random_seed
Browse files Browse the repository at this point in the history
Allow random PYTHONHASHSEED
  • Loading branch information
pigmej committed Nov 30, 2015
2 parents b96661f + 4c37224 commit 4f2154e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 57 deletions.
11 changes: 11 additions & 0 deletions solar/dblayer/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,15 @@ def pytest_runtest_call(item):
ModelMeta.session_start()


def dicts_to_hashable(list_of_dics):
rst = []
for item in list_of_dics:
rst.append(tuple(item.items()))
return tuple(rst)


def pytest_namespace():
return {'dicts_to_hashable': dicts_to_hashable}


Model.get_bucket_name = classmethod(patched_get_bucket_name)
12 changes: 7 additions & 5 deletions solar/dblayer/test/test_real.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,13 @@ def test_simple_to_listdict_inputs(rk):
r3.save()
r4.save()

assert r2.inputs['input'] == [{u'input2': 1115,
u'input1': 110}, {u'input2': 115,
u'input1': 1110},
{u'input2': 15,
u'input1': 10}]
inputs = set(pytest.dicts_to_hashable(r2.inputs['input']))
expected_inputs = set(pytest.dicts_to_hashable(
[{u'input2': 1115, u'input1': 110},
{u'input2': 115, u'input1': 1110},
{u'input2': 15, u'input1': 10}]))

assert inputs == expected_inputs


def test_dict_to_list_inputs(rk):
Expand Down
76 changes: 25 additions & 51 deletions solar/test/test_diff_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,14 @@

@fixture
def staged():
return {'id': 'res.1',
'tags': ['res', 'node.1'],
'input': {'ip': {'value': '10.0.0.2'},
'list_val': {'value': [1, 2]}},
'metadata': {},
'connections': [
['node.1', 'res.1', ['ip', 'ip']],
['node.1', 'res.1', ['key', 'key']]
]}
return {'ip': {'value': '10.0.0.2'},
'list_val': {'value': [1, 2]}}


@fixture
def commited():
return {'id': 'res.1',
'tags': ['res', 'node.1'],
'input': {'ip': '10.0.0.2',
'list_val': [1]},
'metadata': {},
'connections': [
['node.1', 'res.1', ['ip', 'ip']]
]}
return {'ip': '10.0.0.2',
'list_val': [1]}


@fixture
Expand All @@ -55,25 +42,30 @@ def diff_for_update(staged, commited):


def test_create_diff_with_empty_commited(full_diff):
# add will be executed
expected = [('add', '',
[('connections', [['node.1', 'res.1', ['ip', 'ip']],
['node.1', 'res.1', ['key', 'key']]]),
('input', {
'ip': {'value': '10.0.0.2'},
'list_val': {'value': [1, 2]}
}), ('metadata', {}), ('id', 'res.1'),
('tags', ['res', 'node.1'])])]
assert full_diff == expected
operations = set()
vals = {}
for item in full_diff:
operations.add(item[0])
for val in item[2]:
vals[val[0]] = val[1]

assert len(full_diff) == 1
assert set(['add']) == operations
assert vals['ip'] == {'value': '10.0.0.2'}
assert vals['list_val'] == {'value': [1, 2]}


def test_create_diff_modified(diff_for_update):
assert diff_for_update == [
('add', 'connections', [(1, ['node.1', 'res.1', ['key', 'key']])]),
('change', 'input.ip',
('10.0.0.2', {'value': '10.0.0.2'})), ('change', 'input.list_val',
([1], {'value': [1, 2]}))
]
operations = set()
vals = {}
for item in diff_for_update:
operations.add(item[0])
vals[item[1]] = item[2]

assert len(diff_for_update) == 2
assert set(['change']) == operations
assert vals['ip'] == ('10.0.0.2', {'value': '10.0.0.2'})
assert vals['list_val'] == ([1], {'value': [1, 2]})


def test_verify_patch_creates_expected(staged, diff_for_update, commited):
Expand All @@ -84,21 +76,3 @@ def test_verify_patch_creates_expected(staged, diff_for_update, commited):
def test_revert_update(staged, diff_for_update, commited):
expected = revert(diff_for_update, staged)
assert expected == commited


@fixture
def resources():
r = {'n.1': {'uid': 'n.1',
'args': {'ip': '10.20.0.2'},
'connections': [],
'tags': []},
'r.1': {'uid': 'r.1',
'args': {'ip': '10.20.0.2'},
'connections': [['n.1', 'r.1', ['ip', 'ip']]],
'tags': []},
'h.1': {'uid': 'h.1',
'args': {'ip': '10.20.0.2',
'ips': ['10.20.0.2']},
'connections': [['n.1', 'h.1', ['ip', 'ip']]],
'tags': []}}
return r
1 change: 0 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ envlist = pep8,py27
usedevelop = True
install_command = pip install -U {opts} {packages}
setenv = VIRTUAL_ENV={envdir}
PYTHONHASHSEED=0
deps = -r{toxinidir}/test-requirements.txt
commands = ostestr

Expand Down

0 comments on commit 4f2154e

Please sign in to comment.