Commit f1cbd577 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent f7c25c3b
......@@ -22,6 +22,7 @@ import io
import yaml
import pcpp
import unittest
from slapos.testing.testcase import makeModuleSetUpAndTestCaseClass
setUpModule, AmariTestCase = makeModuleSetUpAndTestCaseClass(
......@@ -257,56 +258,12 @@ class TestENB_SDR(ENBTestCase):
# assertDict asserts that d slice with keys from dok == dok.
# dok[k]=NO means d[k] must be absent.
# XXX -> assertMatch with support for {} and []
class NOClass:
def __repr__(self):
return 'ø'
NO = NOClass()
def assertDict(d, dok):
d_ = {}
for k in dok:
d_[k] = d.get(k, NO)
self.assertEqual(d_, dok)
# assertMatch recursively matches data structure against specified pattern.
#
# - atomic types like int and str match by equality
# - list match by matching all elements individually
# - dict match by verifying v[k] == vok[k] for keys from the pattern
# vok[k]=NO means v[k] must be absent
def assertMatch(v, vok):
v_ = _matchCollect(v, vok)
self.assertEqual(v_, vok)
def _matchCollect(v, vok):
if type(v) is not type(vok):
return v
if type(v) is dict:
v_ = {}
for k in vok:
#v_[k] = v.get(k, NO)
v_[k] = _matchCollect(v.get(k, NO), vok[k])
return v_
if type(v) is list:
v_ = []
for i in range(max(len(v), len(vok))):
e = NO
eok = NO
if i < len(v):
e = v[i]
if i < len(vok):
eok = vok[i]
if e is not NO:
if eok is not NO:
v_.append(_matchCollect(e, eok))
else:
v_.append(e)
return v_
# other types, e.g. atomic int/str/... - return as is
assert type(v) is not tuple, v
return v
cell_list = conf['cell_list']
nr_cell_list = conf['nr_cell_list']
self.assertEqual(len(cell_list), 2)
......@@ -353,7 +310,7 @@ class TestENB_SDR(ENBTestCase):
)})
# Carrier Aggregation
assertMatch(cell_list, [
assertMatch(self, cell_list, [
{
'scell_list': [{'cell_id': 0x2}], # LTE + LTE
'en_dc_scg_cell_list': [{'cell_id': 0x3}, {'cell_id': 0x4}], # LTE + NR
......@@ -537,3 +494,47 @@ class TestUEMonitorGadgetUrl(ORSTestCase):
def test_monitor_gadget_url(self):
test_monitor_gadget_url(self)
"""
# assertMatch recursively matches data structure against specified pattern.
#
# - dict match by verifying v[k] == vok[k] for keys from the pattern.
# vok[k]=NO means v[k] must be absent
# - list match by matching all elements individually
# - atomic types like int and str match by equality
class NOClass:
def __repr__(self):
return 'ø'
NO = NOClass()
def assertMatch(t: unittest.TestCase, v, vok):
v_ = _matchCollect(v, vok)
t.assertEqual(v_, vok)
def _matchCollect(v, vok):
if type(v) is not type(vok):
return v
if type(v) is dict:
v_ = {}
for k in vok:
#v_[k] = v.get(k, NO)
v_[k] = _matchCollect(v.get(k, NO), vok[k])
return v_
if type(v) is list:
v_ = []
for i in range(max(len(v), len(vok))):
e = NO
eok = NO
if i < len(v):
e = v[i]
if i < len(vok):
eok = vok[i]
if e is not NO:
if eok is not NO:
v_.append(_matchCollect(e, eok))
else:
v_.append(e)
return v_
# other types, e.g. atomic int/str/... - return as is
assert type(v) is not tuple, v
return v
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment