added tests for getters and setters
This commit is contained in:
parent
728e36118a
commit
ca200b1c23
|
|
@ -1,10 +1,10 @@
|
||||||
|
from logging import exception
|
||||||
import bootstraparse.modules.environment as e
|
import bootstraparse.modules.environment as e
|
||||||
import rich
|
|
||||||
|
|
||||||
|
|
||||||
def test_wasInitialised():
|
def test_wasInitialised():
|
||||||
testenv = e.environment()
|
testcheck = e.environment()
|
||||||
for k in testenv._wasInitialised.values():
|
for k in testcheck._wasInitialised.values():
|
||||||
assert k is False
|
assert k is False
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -13,40 +13,88 @@ def test_integritycheck():
|
||||||
customtest_p = [p for p in testcheck._mParams.keys()]
|
customtest_p = [p for p in testcheck._mParams.keys()]
|
||||||
customtest_v = [False for p in testcheck._mParams.values()]
|
customtest_v = [False for p in testcheck._mParams.values()]
|
||||||
# Test all False
|
# Test all False
|
||||||
|
|
||||||
# rich.inspect(testcheck)
|
# rich.inspect(testcheck)
|
||||||
|
|
||||||
assert testcheck.integritycheck() is False
|
assert testcheck.integritycheck() is False
|
||||||
|
|
||||||
customtest_v[0] = True
|
customtest_v[0] = True
|
||||||
testcheck._wasInitialised = dict(zip(customtest_p, customtest_v))
|
testcheck._wasInitialised = dict(zip(customtest_p, customtest_v))
|
||||||
# Test first False
|
# Test first False
|
||||||
|
|
||||||
# rich.inspect(testcheck)
|
# rich.inspect(testcheck)
|
||||||
|
|
||||||
assert testcheck.integritycheck() is False
|
assert testcheck.integritycheck() is False
|
||||||
|
|
||||||
customtest_v[0] = False
|
customtest_v[0] = False
|
||||||
customtest_v[-1] = True
|
customtest_v[-1] = True
|
||||||
testcheck._wasInitialised = dict(zip(customtest_p, customtest_v))
|
testcheck._wasInitialised = dict(zip(customtest_p, customtest_v))
|
||||||
# Test last False
|
# Test last False
|
||||||
|
|
||||||
# rich.inspect(testcheck)
|
# rich.inspect(testcheck)
|
||||||
|
|
||||||
assert testcheck.integritycheck() is False
|
assert testcheck.integritycheck() is False
|
||||||
|
|
||||||
customtest_v[-1] = False
|
customtest_v[-1] = False
|
||||||
customtest_v[len(customtest_v)//2-1] = True
|
customtest_v[len(customtest_v)//2-1] = True
|
||||||
testcheck._wasInitialised = dict(zip(customtest_p, customtest_v))
|
testcheck._wasInitialised = dict(zip(customtest_p, customtest_v))
|
||||||
# Test middle False
|
# Test middle False
|
||||||
|
|
||||||
# rich.inspect(testcheck)
|
# rich.inspect(testcheck)
|
||||||
|
|
||||||
assert testcheck.integritycheck() is False
|
assert testcheck.integritycheck() is False
|
||||||
|
|
||||||
customtest_v = [True for p in testcheck._mParams.values()]
|
customtest_v = [True for p in testcheck._mParams.values()]
|
||||||
testcheck._wasInitialised = dict(zip(customtest_p, customtest_v))
|
testcheck._wasInitialised = dict(zip(customtest_p, customtest_v))
|
||||||
# Test all True
|
# Test all True
|
||||||
|
|
||||||
# rich.inspect(testcheck)
|
# rich.inspect(testcheck)
|
||||||
|
|
||||||
assert testcheck.integritycheck() is True
|
assert testcheck.integritycheck() is True
|
||||||
|
|
||||||
|
|
||||||
|
def test_getter():
|
||||||
|
testcheck = e.environment()
|
||||||
|
for p in testcheck._mParams:
|
||||||
|
assert testcheck.__getattr__(p) == testcheck._mParams[p]
|
||||||
|
|
||||||
|
testcheck._sParams = {
|
||||||
|
"testparam": "testvalue"
|
||||||
|
}
|
||||||
|
assert testcheck.testparam == "testvalue"
|
||||||
|
|
||||||
|
try:
|
||||||
|
testcheck.purposefullyunexistingparameter
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
except Exception:
|
||||||
|
assert False # Not AttributeError when getting unexisting parameter
|
||||||
|
|
||||||
|
try:
|
||||||
|
testcheck._purposefullyunexistingparameter
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
except Exception:
|
||||||
|
assert False # Not AttributeError when getting _unexisting parameter
|
||||||
|
|
||||||
|
|
||||||
|
def test_setter():
|
||||||
|
testcheck = e.environment()
|
||||||
|
for p in testcheck._mParams:
|
||||||
|
testcheck.__setattr__(p, "testvalue")
|
||||||
|
assert testcheck._mParams[p] == "testvalue"
|
||||||
|
|
||||||
|
testcheck._sParams = {
|
||||||
|
"testparam": "testvalue"
|
||||||
|
}
|
||||||
|
testcheck.testparam = "secondtestvalue"
|
||||||
|
assert testcheck.testparam == "secondtestvalue"
|
||||||
|
|
||||||
|
try:
|
||||||
|
testcheck.purposefullyunexistingparameter = "testvalue"
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
except Exception:
|
||||||
|
assert False # Not AttributeError when getting unexisting parameter
|
||||||
|
|
||||||
|
testcheck._purposefullyunexistingparameter = "testvalue"
|
||||||
|
assert testcheck._purposefullyunexistingparameter == "testvalue"
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_integritycheck()
|
test_setter()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue