|
|
@ -19,20 +19,20 @@ class TestNamespace: |
|
|
|
|
|
|
|
def test_create_variable(self): |
|
|
|
ns = Namespace() |
|
|
|
ns.addStringVariable("test", "12345") |
|
|
|
assert ns.test.getValue() == "12345" |
|
|
|
ns.addStringVariable("zxcv", "23456") |
|
|
|
assert ns.zxcv.getValue() == "23456" |
|
|
|
ns.add_string_variable("test", "12345") |
|
|
|
assert ns.test.get_value() == "12345" |
|
|
|
ns.add_string_variable("zxcv", "23456") |
|
|
|
assert ns.zxcv.get_value() == "23456" |
|
|
|
|
|
|
|
def test_create_ns_with_vars(self): |
|
|
|
ns = Namespace() |
|
|
|
ns.addNamespace(Namespace("os")) |
|
|
|
ns.os.addStringVariable("test", "123") |
|
|
|
ns.os.addNamespace(Namespace("linux")) |
|
|
|
ns.os.linux.addStringVariable("shortname", "CLD") |
|
|
|
assert ns.os.test.getValue() == "123" |
|
|
|
assert ns.os["test"].getValue() == "123" |
|
|
|
assert ns.os.linux.shortname.getValue() == "CLD" |
|
|
|
ns.add_namespace(Namespace("os")) |
|
|
|
ns.os.add_string_variable("test", "123") |
|
|
|
ns.os.add_namespace(Namespace("linux")) |
|
|
|
ns.os.linux.add_string_variable("shortname", "CLD") |
|
|
|
assert ns.os.test.get_value() == "123" |
|
|
|
assert ns.os["test"].get_value() == "123" |
|
|
|
assert ns.os.linux.shortname.get_value() == "CLD" |
|
|
|
assert ns.os.root == ns |
|
|
|
|
|
|
|
def test_fill_namespace_simple(self): |
|
|
@ -47,9 +47,9 @@ class TestNamespace: |
|
|
|
fullname = Calculate Linux Desktop |
|
|
|
""") |
|
|
|
|
|
|
|
assert ns.os.test.getValue() == "123" |
|
|
|
assert ns.os.linux.shortname.getValue() == "CLD" |
|
|
|
assert ns.os.linux.fullname.getValue() == "Calculate Linux Desktop" |
|
|
|
assert ns.os.test.get_value() == "123" |
|
|
|
assert ns.os.linux.shortname.get_value() == "CLD" |
|
|
|
assert ns.os.linux.fullname.get_value() == "Calculate Linux Desktop" |
|
|
|
assert ns.os.linux.root == ns |
|
|
|
|
|
|
|
nsif.fill(ns, """ |
|
|
@ -57,8 +57,8 @@ class TestNamespace: |
|
|
|
shortname = CLDX |
|
|
|
""") |
|
|
|
|
|
|
|
assert ns.os.linux.shortname.getValue() == "CLDX" |
|
|
|
assert ns.os.linux.fullname.getValue() == "Calculate Linux Desktop" |
|
|
|
assert ns.os.linux.shortname.get_value() == "CLDX" |
|
|
|
assert ns.os.linux.fullname.get_value() == "Calculate Linux Desktop" |
|
|
|
|
|
|
|
def test_fill_namespace_append_and_remove(self): |
|
|
|
ns = Namespace() |
|
|
@ -71,28 +71,28 @@ class TestNamespace: |
|
|
|
test += 345 |
|
|
|
""") |
|
|
|
|
|
|
|
assert ns.os.test.getValue() == "123,345" |
|
|
|
assert ns.os.test.get_value() == "123,345" |
|
|
|
|
|
|
|
nsif.fill(ns, """ |
|
|
|
[os] |
|
|
|
test -= 123 |
|
|
|
""") |
|
|
|
|
|
|
|
assert ns.os.test.getValue() == "345" |
|
|
|
assert ns.os.test.get_value() == "345" |
|
|
|
|
|
|
|
nsif.fill(ns, """ |
|
|
|
[os] |
|
|
|
test += asdf,qwer,zxcv |
|
|
|
""") |
|
|
|
|
|
|
|
assert ns.os.test.getValue() == "345,asdf,qwer,zxcv" |
|
|
|
assert ns.os.test.get_value() == "345,asdf,qwer,zxcv" |
|
|
|
|
|
|
|
nsif.fill(ns, """ |
|
|
|
[os] |
|
|
|
test -= asdf,zxcv |
|
|
|
""") |
|
|
|
|
|
|
|
assert ns.os.test.getValue() == "345,qwer" |
|
|
|
assert ns.os.test.get_value() == "345,qwer" |
|
|
|
|
|
|
|
def test_fill_namespace_clear_namespaces(self): |
|
|
|
ns = Namespace() |
|
|
@ -111,9 +111,9 @@ class TestNamespace: |
|
|
|
mount = /var/calculate |
|
|
|
""") |
|
|
|
|
|
|
|
assert [x.dev.getValue() for x in ns.test] == ['/dev/sda1', |
|
|
|
'/dev/sda2', |
|
|
|
'/dev/sda5'] |
|
|
|
assert [x.dev.get_value() for x in ns.test] == ['/dev/sda1', |
|
|
|
'/dev/sda2', |
|
|
|
'/dev/sda5'] |
|
|
|
|
|
|
|
nsif.fill(ns, """ |
|
|
|
[test][0] |
|
|
@ -125,9 +125,9 @@ class TestNamespace: |
|
|
|
mount = / |
|
|
|
""") |
|
|
|
|
|
|
|
assert [x.dev.getValue() for x in ns.test] == ['/dev/sdb1', |
|
|
|
'/dev/sdb2', |
|
|
|
'/dev/sda5'] |
|
|
|
assert [x.dev.get_value() for x in ns.test] == ['/dev/sdb1', |
|
|
|
'/dev/sdb2', |
|
|
|
'/dev/sda5'] |
|
|
|
|
|
|
|
nsif.fill(ns, """ |
|
|
|
[test][] |
|
|
@ -141,8 +141,8 @@ class TestNamespace: |
|
|
|
mount = / |
|
|
|
""") |
|
|
|
|
|
|
|
assert [x.dev.getValue() for x in ns.test] == ['/dev/sdb1', |
|
|
|
'/dev/sdb2'] |
|
|
|
assert [x.dev.get_value() for x in ns.test] == ['/dev/sdb1', |
|
|
|
'/dev/sdb2'] |
|
|
|
|
|
|
|
def test_fill_namespace_strict_clear(self): |
|
|
|
ns = Namespace() |
|
|
@ -167,8 +167,8 @@ class TestNamespace: |
|
|
|
zxcv = 2 |
|
|
|
""") |
|
|
|
|
|
|
|
assert ns.custom.test.zxcv.getValue() == "1" |
|
|
|
assert ns.custom.test2.zxcv.getValue() == "2" |
|
|
|
assert ns.custom.test.zxcv.get_value() == "1" |
|
|
|
assert ns.custom.test2.zxcv.get_value() == "2" |
|
|
|
|
|
|
|
nsifs = NamespaceIniFillerStrict() |
|
|
|
nsifs.fill(ns, """ |
|
|
@ -182,16 +182,16 @@ class TestNamespace: |
|
|
|
def test_get_namespace_attrs(self): |
|
|
|
ns = Namespace() |
|
|
|
os = Namespace("os") |
|
|
|
os.addStringVariable("test", "zxcv") |
|
|
|
ns.addNamespace(os) |
|
|
|
os.add_string_variable("test", "zxcv") |
|
|
|
ns.add_namespace(os) |
|
|
|
|
|
|
|
assert ns.os.test.getValue() == "zxcv" |
|
|
|
assert ns.os["test"].getValue() == "zxcv" |
|
|
|
assert ns.os.test.get_value() == "zxcv" |
|
|
|
assert ns.os["test"].get_value() == "zxcv" |
|
|
|
assert "test" in ns.os |
|
|
|
ns.os.test.setValue("123") |
|
|
|
assert ns.os.test.getValue() == "123" |
|
|
|
ns.os["test"].setValue("234") |
|
|
|
assert ns.os.test.getValue() == "234" |
|
|
|
ns.os.test.set_value("123") |
|
|
|
assert ns.os.test.get_value() == "123" |
|
|
|
ns.os["test"].set_value("234") |
|
|
|
assert ns.os.test.get_value() == "234" |
|
|
|
|
|
|
|
def test_variable_get_value(self): |
|
|
|
class TestVar(Variable): |
|
|
@ -200,62 +200,62 @@ class TestNamespace: |
|
|
|
|
|
|
|
var = TestVar("test") |
|
|
|
|
|
|
|
assert var.getValue() == "A" |
|
|
|
assert var.get_value() == "A" |
|
|
|
|
|
|
|
def test_namespace_lookup(self): |
|
|
|
ns = Namespace() |
|
|
|
os = Namespace("os") |
|
|
|
device = Namespace("device") |
|
|
|
linux = Namespace("linux") |
|
|
|
ns.addNamespace(os) |
|
|
|
os.addNamespace(linux) |
|
|
|
os.addNamespace(device) |
|
|
|
device1 = device.addNamespace() |
|
|
|
device1.addStringVariable("dev", "/dev/sda") |
|
|
|
device2 = device.addNamespace() |
|
|
|
device2.addStringVariable("dev", "/dev/sdb") |
|
|
|
device3 = device.addNamespace() |
|
|
|
device3.addStringVariable("dev", "/dev/sdc") |
|
|
|
|
|
|
|
ns.addStringVariable("first", "first") |
|
|
|
os.addStringVariable("second", "second") |
|
|
|
linux.addStringVariable("third", "third") |
|
|
|
|
|
|
|
assert ns.first.getValue() == "first" |
|
|
|
assert ns.root.os.second.getValue() == "second" |
|
|
|
assert ns.os.second.getValue() == "second" |
|
|
|
assert os.root.os.second.getValue() == "second" |
|
|
|
assert os.second.getValue() == "second" |
|
|
|
assert linux.third.getValue() == "third" |
|
|
|
assert linux.root.os.second.getValue() == "second" |
|
|
|
ns.add_namespace(os) |
|
|
|
os.add_namespace(linux) |
|
|
|
os.add_namespace(device) |
|
|
|
device1 = device.add_namespace() |
|
|
|
device1.add_string_variable("dev", "/dev/sda") |
|
|
|
device2 = device.add_namespace() |
|
|
|
device2.add_string_variable("dev", "/dev/sdb") |
|
|
|
device3 = device.add_namespace() |
|
|
|
device3.add_string_variable("dev", "/dev/sdc") |
|
|
|
|
|
|
|
ns.add_string_variable("first", "first") |
|
|
|
os.add_string_variable("second", "second") |
|
|
|
linux.add_string_variable("third", "third") |
|
|
|
|
|
|
|
assert ns.first.get_value() == "first" |
|
|
|
assert ns.root.os.second.get_value() == "second" |
|
|
|
assert ns.os.second.get_value() == "second" |
|
|
|
assert os.root.os.second.get_value() == "second" |
|
|
|
assert os.second.get_value() == "second" |
|
|
|
assert linux.third.get_value() == "third" |
|
|
|
assert linux.root.os.second.get_value() == "second" |
|
|
|
|
|
|
|
with pytest.raises(VariableNotFoundError): |
|
|
|
os.third |
|
|
|
|
|
|
|
assert ns.os.device[0].dev.getValue() == "/dev/sda" |
|
|
|
assert ns.os.device["0"].dev.getValue() == "/dev/sda" |
|
|
|
assert ns.os.device[1].dev.getValue() == "/dev/sdb" |
|
|
|
assert ns.os.device[2].dev.getValue() == "/dev/sdc" |
|
|
|
assert ns.os.device[0].dev.get_value() == "/dev/sda" |
|
|
|
assert ns.os.device["0"].dev.get_value() == "/dev/sda" |
|
|
|
assert ns.os.device[1].dev.get_value() == "/dev/sdb" |
|
|
|
assert ns.os.device[2].dev.get_value() == "/dev/sdc" |
|
|
|
|
|
|
|
assert ns.os.device.parent.second.getValue() == "second" |
|
|
|
assert ns.os.device.parent.parent.os.second.getValue() == "second" |
|
|
|
assert ns.os.device.parent.second.get_value() == "second" |
|
|
|
assert ns.os.device.parent.parent.os.second.get_value() == "second" |
|
|
|
assert ns.os.device.parent.parent.parent.os.second.\ |
|
|
|
getValue() == "second" |
|
|
|
get_value() == "second" |
|
|
|
|
|
|
|
def test_variable_get_value_by_variable(self): |
|
|
|
class TestVar1(Variable): |
|
|
|
def get(self): |
|
|
|
return "%s,B" % self.vars.test2.getValue(self) |
|
|
|
return "%s,B" % self.vars.test2.get_value(self) |
|
|
|
|
|
|
|
class TestVar2(Variable): |
|
|
|
def get(self): |
|
|
|
return "A" |
|
|
|
|
|
|
|
ns = Namespace() |
|
|
|
ns.addVariable(TestVar1("test1")) |
|
|
|
ns.addVariable(TestVar2("test2")) |
|
|
|
ns.add_variable(TestVar1("test1")) |
|
|
|
ns.add_variable(TestVar2("test2")) |
|
|
|
|
|
|
|
assert ns.test1.getValue() == "A,B" |
|
|
|
assert ns.test1.get_value() == "A,B" |
|
|
|
|
|
|
|
def test_variable_get_value_by_changed_variable(self): |
|
|
|
class TestVar1(Variable): |
|
|
@ -263,59 +263,59 @@ class TestNamespace: |
|
|
|
|
|
|
|
def get(self): |
|
|
|
self.counter += 1 |
|
|
|
return "%s,B" % self.vars.test2.getValue(self) |
|
|
|
return "%s,B" % self.vars.test2.get_value(self) |
|
|
|
|
|
|
|
ns = Namespace() |
|
|
|
test1 = TestVar1("test1") |
|
|
|
ns.addVariable(test1) |
|
|
|
ns.addStringVariable("test2", "A") |
|
|
|
ns.add_variable(test1) |
|
|
|
ns.add_string_variable("test2", "A") |
|
|
|
|
|
|
|
assert ns.test1.getValue() == "A,B" |
|
|
|
assert ns.test1.get_value() == "A,B" |
|
|
|
|
|
|
|
assert test1.counter == 1 |
|
|
|
# test for get cached variable value |
|
|
|
assert ns.test1.getValue() == "A,B" |
|
|
|
assert ns.test1.get_value() == "A,B" |
|
|
|
assert test1.counter == 1 |
|
|
|
|
|
|
|
# change value of test2 for recalculate test1 |
|
|
|
ns.test2.setValue("C") |
|
|
|
assert ns.test1.getValue() == "C,B" |
|
|
|
ns.test2.set_value("C") |
|
|
|
assert ns.test1.get_value() == "C,B" |
|
|
|
assert test1.counter == 2 |
|
|
|
|
|
|
|
# change value of test2 for recalculate test1 |
|
|
|
ns.test2.setValue("D") |
|
|
|
assert ns.test1.getValue() == "D,B" |
|
|
|
ns.test2.set_value("D") |
|
|
|
assert ns.test1.get_value() == "D,B" |
|
|
|
assert test1.counter == 3 |
|
|
|
|
|
|
|
def test_cyclic_variable(self): |
|
|
|
class TestVar1(Variable): |
|
|
|
def get(self): |
|
|
|
return "%s,test1" % self.vars.test2.getValue(self) |
|
|
|
return "%s,test1" % self.vars.test2.get_value(self) |
|
|
|
|
|
|
|
class TestVar2(Variable): |
|
|
|
def get(self): |
|
|
|
return "%s,test2" % self.vars.test3.getValue(self) |
|
|
|
return "%s,test2" % self.vars.test3.get_value(self) |
|
|
|
|
|
|
|
class TestVar3(Variable): |
|
|
|
def get(self): |
|
|
|
return "%s,test3" % self.vars.test1.getValue(self) |
|
|
|
return "%s,test3" % self.vars.test1.get_value(self) |
|
|
|
|
|
|
|
test1 = TestVar1("test1") |
|
|
|
test2 = TestVar2("test2") |
|
|
|
test3 = TestVar3("test3") |
|
|
|
|
|
|
|
ns = Namespace() |
|
|
|
ns.addVariable(test1) |
|
|
|
ns.addVariable(test2) |
|
|
|
ns.addVariable(test3) |
|
|
|
ns.add_variable(test1) |
|
|
|
ns.add_variable(test2) |
|
|
|
ns.add_variable(test3) |
|
|
|
|
|
|
|
with pytest.raises(CyclicVariableError) as e: |
|
|
|
ns.test1.getValue() |
|
|
|
ns.test1.get_value() |
|
|
|
|
|
|
|
assert e.value.queue[:-1] == ("test1", "test2", "test3") |
|
|
|
|
|
|
|
with pytest.raises(VariableError) as e: |
|
|
|
ns.test1.getValue() |
|
|
|
ns.test1.get_value() |
|
|
|
|
|
|
|
def test_drop_invalidate_after_set_value(self): |
|
|
|
class TestVar1(Variable): |
|
|
@ -323,7 +323,7 @@ class TestNamespace: |
|
|
|
|
|
|
|
def get(self): |
|
|
|
self.counter += 1 |
|
|
|
return "%s,test1" % self.vars.test2.getValue(self) |
|
|
|
return "%s,test1" % self.vars.test2.get_value(self) |
|
|
|
|
|
|
|
class TestVar2(Variable): |
|
|
|
def get(self): |
|
|
@ -332,24 +332,24 @@ class TestNamespace: |
|
|
|
test1 = TestVar1("test1") |
|
|
|
test2 = TestVar2("test2") |
|
|
|
ns = Namespace() |
|
|
|
ns.addVariable(test1) |
|
|
|
ns.addVariable(test2) |
|
|
|
ns.add_variable(test1) |
|
|
|
ns.add_variable(test2) |
|
|
|
|
|
|
|
assert test1.getValue() == "ZZZZ,test1" |
|
|
|
assert test1.get_value() == "ZZZZ,test1" |
|
|
|
|
|
|
|
test1.setValue("VVVV") |
|
|
|
test1.set_value("VVVV") |
|
|
|
|
|
|
|
assert test1.getValue() == "VVVV" |
|
|
|
assert test1.get_value() == "VVVV" |
|
|
|
assert test1.counter == 1 |
|
|
|
|
|
|
|
test2.setValue("XXXX") |
|
|
|
test2.set_value("XXXX") |
|
|
|
|
|
|
|
assert test1.getValue() == "VVVV" |
|
|
|
assert test1.get_value() == "VVVV" |
|
|
|
assert test1.counter == 1 |
|
|
|
|
|
|
|
test1.invalidate() |
|
|
|
|
|
|
|
assert test1.getValue() == "XXXX,test1" |
|
|
|
assert test1.get_value() == "XXXX,test1" |
|
|
|
assert test1.counter == 2 |
|
|
|
|
|
|
|
def test_change_invalidator_variable(self): |
|
|
@ -359,31 +359,31 @@ class TestNamespace: |
|
|
|
def get(self): |
|
|
|
self.counter += 1 |
|
|
|
|
|
|
|
if self.vars.ifvar.getValue(self): |
|
|
|
return "%s,test1" % self.vars.vara.getValue(self) |
|
|
|
if self.vars.ifvar.get_value(self): |
|
|
|
return "%s,test1" % self.vars.vara.get_value(self) |
|
|
|
else: |
|
|
|
return "%s,test1" % self.vars.varb.getValue(self) |
|
|
|
return "%s,test1" % self.vars.varb.get_value(self) |
|
|
|
|
|
|
|
vartest = VarTest("vartest") |
|
|
|
ns = Namespace() |
|
|
|
ns.addVariable(vartest) |
|
|
|
ns.addStringVariable("vara", "vara") |
|
|
|
ns.addStringVariable("varb", "varb") |
|
|
|
ns.addStringVariable("ifvar", "true") |
|
|
|
ns.add_variable(vartest) |
|
|
|
ns.add_string_variable("vara", "vara") |
|
|
|
ns.add_string_variable("varb", "varb") |
|
|
|
ns.add_string_variable("ifvar", "true") |
|
|
|
|
|
|
|
assert vartest.getValue() == "vara,test1" |
|
|
|
assert vartest.get_value() == "vara,test1" |
|
|
|
assert vartest.counter == 1 |
|
|
|
|
|
|
|
ns.vara.setValue("varc") |
|
|
|
assert vartest.getValue() == "varc,test1" |
|
|
|
ns.vara.set_value("varc") |
|
|
|
assert vartest.get_value() == "varc,test1" |
|
|
|
assert vartest.counter == 2 |
|
|
|
|
|
|
|
ns.ifvar.setValue("") |
|
|
|
assert vartest.getValue() == "varb,test1" |
|
|
|
ns.ifvar.set_value("") |
|
|
|
assert vartest.get_value() == "varb,test1" |
|
|
|
assert vartest.counter == 3 |
|
|
|
|
|
|
|
ns.vara.setValue("vard") |
|
|
|
assert vartest.getValue() == "varb,test1" |
|
|
|
ns.vara.set_value("vard") |
|
|
|
assert vartest.get_value() == "varb,test1" |
|
|
|
assert vartest.counter == 3 |
|
|
|
|
|
|
|
def test_readonly_varaible(self): |
|
|
@ -394,14 +394,14 @@ class TestNamespace: |
|
|
|
return "test1" |
|
|
|
|
|
|
|
test1 = TestVar1("test1") |
|
|
|
assert test1.getValue() == "test1" |
|
|
|
assert test1.get_value() == "test1" |
|
|
|
|
|
|
|
with pytest.raises(VariableError): |
|
|
|
test1.setValue("test2") |
|
|
|
test1.set_value("test2") |
|
|
|
|
|
|
|
assert test1.getValue() == "test1" |
|
|
|
test1.setValue("test2", force=True) |
|
|
|
assert test1.getValue() == "test2" |
|
|
|
assert test1.get_value() == "test1" |
|
|
|
test1.set_value("test2", force=True) |
|
|
|
assert test1.get_value() == "test2" |
|
|
|
|
|
|
|
def test_choice_variable(self): |
|
|
|
class TestVar1(Variable): |
|
|
@ -412,9 +412,9 @@ class TestNamespace: |
|
|
|
|
|
|
|
test1 = TestVar1("test1") |
|
|
|
with pytest.raises(VariableError): |
|
|
|
test1.setValue("test3") |
|
|
|
test1.setValue("test2") |
|
|
|
assert test1.getValue() == "test2" |
|
|
|
test1.set_value("test3") |
|
|
|
test1.set_value("test2") |
|
|
|
assert test1.get_value() == "test2" |
|
|
|
|
|
|
|
def test_integer_variable(self): |
|
|
|
class TestVar1(Variable): |
|
|
@ -422,11 +422,11 @@ class TestNamespace: |
|
|
|
|
|
|
|
test1 = TestVar1("test1") |
|
|
|
with pytest.raises(VariableError): |
|
|
|
test1.setValue("test3") |
|
|
|
test1.setValue("33") |
|
|
|
assert test1.getValue() == 33 |
|
|
|
test1.setValue("-33") |
|
|
|
assert test1.getValue() == -33 |
|
|
|
test1.set_value("test3") |
|
|
|
test1.set_value("33") |
|
|
|
assert test1.get_value() == 33 |
|
|
|
test1.set_value("-33") |
|
|
|
assert test1.get_value() == -33 |
|
|
|
|
|
|
|
def test_default_value_property(self): |
|
|
|
class TestVar1(Variable): |
|
|
@ -434,14 +434,14 @@ class TestNamespace: |
|
|
|
return "123" |
|
|
|
|
|
|
|
test1 = TestVar1("test1") |
|
|
|
assert test1.getValue() == "123" |
|
|
|
assert test1.get_value() == "123" |
|
|
|
|
|
|
|
test1.setValue("987") |
|
|
|
test1.set_value("987") |
|
|
|
test1.addProperty(DefaultValue("567")) |
|
|
|
|
|
|
|
assert test1.getValue() == "987" |
|
|
|
assert test1.get_value() == "987" |
|
|
|
test1.invalidate() |
|
|
|
assert test1.getValue() == "567" |
|
|
|
assert test1.get_value() == "567" |
|
|
|
|
|
|
|
def test_get_comment(self): |
|
|
|
class TestVar1(Variable): |
|
|
@ -452,30 +452,30 @@ class TestNamespace: |
|
|
|
def get(self): |
|
|
|
return "234" |
|
|
|
|
|
|
|
def getComment(self): |
|
|
|
return "[%s]" % self.getValue() |
|
|
|
def get_comment(self): |
|
|
|
return "[%s]" % self.get_value() |
|
|
|
|
|
|
|
class TestVar3(Variable): |
|
|
|
def get(self): |
|
|
|
return "ZXC %s" % self.vars.test2.getCommentValue(self) |
|
|
|
return "ZXC %s" % self.vars.test2.get_comment_value(self) |
|
|
|
|
|
|
|
ns = Namespace() |
|
|
|
test1 = TestVar1("test1") |
|
|
|
assert test1.getValue() == "123" |
|
|
|
assert test1.getComment() == "123" |
|
|
|
assert test1.get_value() == "123" |
|
|
|
assert test1.get_comment() == "123" |
|
|
|
|
|
|
|
test2 = TestVar2("test2") |
|
|
|
assert test2.getValue() == "234" |
|
|
|
assert test2.getComment() == "[234]" |
|
|
|
assert test2.get_value() == "234" |
|
|
|
assert test2.get_comment() == "[234]" |
|
|
|
|
|
|
|
test3 = TestVar3("test3") |
|
|
|
ns.addVariable(test1) |
|
|
|
ns.addVariable(test2) |
|
|
|
ns.addVariable(test3) |
|
|
|
ns.add_variable(test1) |
|
|
|
ns.add_variable(test2) |
|
|
|
ns.add_variable(test3) |
|
|
|
|
|
|
|
assert test3.getValue() == "ZXC [234]" |
|
|
|
test2.setValue("567") |
|
|
|
assert test3.getValue() == "ZXC [567]" |
|
|
|
assert test3.get_value() == "ZXC [234]" |
|
|
|
test2.set_value("567") |
|
|
|
assert test3.get_value() == "ZXC [567]" |
|
|
|
|
|
|
|
def test_wrong_choice_varaible(self): |
|
|
|
class TestVar1(Variable): |
|
|
@ -490,7 +490,7 @@ class TestNamespace: |
|
|
|
class TestVar3(Variable): |
|
|
|
properties = [ChoiceVariable] |
|
|
|
|
|
|
|
def choiceComment(self): |
|
|
|
def choice_comment(self): |
|
|
|
return [("test1", "Test1"), |
|
|
|
("test2", "Test2")] |
|
|
|
|
|
|
@ -502,30 +502,30 @@ class TestNamespace: |
|
|
|
test1.choice() |
|
|
|
|
|
|
|
with pytest.raises(VariableError): |
|
|
|
test1.choiceComment() |
|
|
|
test1.choice_comment() |
|
|
|
|
|
|
|
assert test2.choice() == ["test1", "test2"] |
|
|
|
assert test2.choiceComment() == [("test1", "test1"), |
|
|
|
("test2", "test2")] |
|
|
|
assert test2.choice_comment() == [("test1", "test1"), |
|
|
|
("test2", "test2")] |
|
|
|
|
|
|
|
assert test3.choice() == ["test1", "test2"] |
|
|
|
assert test3.choiceComment() == [("test1", "Test1"), |
|
|
|
("test2", "Test2")] |
|
|
|
assert test3.choice_comment() == [("test1", "Test1"), |
|
|
|
("test2", "Test2")] |
|
|
|
|
|
|
|
def test_loading_test_variable_module(self): |
|
|
|
ns = Namespace() |
|
|
|
vl = VariableLoader() |
|
|
|
vl.fill(ns, "tests/vars/variables", "testvars") |
|
|
|
|
|
|
|
assert ns.level.simple.getValue() == "simple value" |
|
|
|
assert ns.level.uselocalsimple.getValue() == "Using simple value" |
|
|
|
assert ns.level.usefullsimple.getValue() == "Using simple value" |
|
|
|
assert ns.level.simple.get_value() == "simple value" |
|
|
|
assert ns.level.uselocalsimple.get_value() == "Using simple value" |
|
|
|
assert ns.level.usefullsimple.get_value() == "Using simple value" |
|
|
|
|
|
|
|
with pytest.raises(VariableError): |
|
|
|
ns.level.badchoice.choice() |
|
|
|
|
|
|
|
with pytest.raises(VariableError): |
|
|
|
ns.level.badchoice.choiceComment() |
|
|
|
ns.level.badchoice.choice_comment() |
|
|
|
|
|
|
|
assert ns.level.simple_choice.choice() == ["/dev/sda1", |
|
|
|
"/dev/sda2", |
|
|
@ -533,23 +533,23 @@ class TestNamespace: |
|
|
|
assert ns.level.comment_choice.choice() == ["/dev/sda1", |
|
|
|
"/dev/sda2", |
|
|
|
"/dev/sda3"] |
|
|
|
assert ns.level.comment_choice.choiceComment() == [ |
|
|
|
assert ns.level.comment_choice.choice_comment() == [ |
|
|
|
("/dev/sda1", "SWAP"), |
|
|
|
("/dev/sda2", "ROOT"), |
|
|
|
("/dev/sda3", "DATA")] |
|
|
|
|
|
|
|
ns.level.disks.setValue(["/dev/sda2", "/dev/sda1"]) |
|
|
|
ns.level.disks.set_value(["/dev/sda2", "/dev/sda1"]) |
|
|
|
|
|
|
|
assert ns.level.disks.getValue() == ["/dev/sda2", "/dev/sda1"] |
|
|
|
assert ns.level.disks.get_value() == ["/dev/sda2", "/dev/sda1"] |
|
|
|
|
|
|
|
assert ns.level.comment_choice.choice() == ["/dev/sda2", "/dev/sda1"] |
|
|
|
assert ns.level.comment_choice.choiceComment() == [ |
|
|
|
assert ns.level.comment_choice.choice_comment() == [ |
|
|
|
("/dev/sda2", "ROOT"), |
|
|
|
("/dev/sda1", "SWAP")] |
|
|
|
|
|
|
|
assert ns.level is not ns.level.level2.root |
|
|
|
assert ns is ns.level.level2.root |
|
|
|
assert ns.level.level2.vargetter.getValue() == "/ test" |
|
|
|
assert ns.level.level2.vargetter.get_value() == "/ test" |
|
|
|
|
|
|
|
def test_hash_variable(self): |
|
|
|
# hash variable |
|
|
@ -557,43 +557,43 @@ class TestNamespace: |
|
|
|
vl = VariableLoader() |
|
|
|
vl.fill(ns, "tests/vars/variables", "testvars") |
|
|
|
|
|
|
|
assert ns.level.linux.getFullname() == "level.linux" |
|
|
|
assert ns.level.linux.get_fullname() == "level.linux" |
|
|
|
assert ns.level.linux.ver.fullname == "level.linux.ver" |
|
|
|
|
|
|
|
assert ns.level.linux.ver.getValue() == "1.0" |
|
|
|
assert ns.level.linux.shortname.getValue() == "CLD" |
|
|
|
assert ns.level.linux.ver.get_value() == "1.0" |
|
|
|
assert ns.level.linux.shortname.get_value() == "CLD" |
|
|
|
|
|
|
|
# проверка обновления значения hash переменной при обновлении |
|
|
|
# значения у зависимой перемнной |
|
|
|
ns.level.version.setValue("2.0") |
|
|
|
assert ns.level.linux.ver.getValue() == "2.0" |
|
|
|
ns.level.version.set_value("2.0") |
|
|
|
assert ns.level.linux.ver.get_value() == "2.0" |
|
|
|
|
|
|
|
# проверка установки значения hash переменной |
|
|
|
ns.level.linux.ver.setValue("3.0") |
|
|
|
assert ns.level.linux.ver.getValue() == "3.0" |
|
|
|
ns.level.linux.ver.set_value("3.0") |
|
|
|
assert ns.level.linux.ver.get_value() == "3.0" |
|
|
|
|
|
|
|
# после установки хотя бы одного значения в hash переменной |
|
|
|
# обновление остальных прекращаются до инвалидации (так как |
|
|
|
# значения рассматриваются комплексно) |
|
|
|
ns.level.myshortname.setValue("CLDG") |
|
|
|
assert ns.level.linux.shortname.getValue() == "CLD" |
|
|
|
ns.level.myshortname.set_value("CLDG") |
|
|
|
assert ns.level.linux.shortname.get_value() == "CLD" |
|
|
|
|
|
|
|
# проверка попытки изменить readonly переменную |
|
|
|
with pytest.raises(VariableError): |
|
|
|
ns.level.linux.shortname.setValue("CLDX") |
|
|
|
ns.level.linux.shortname.set_value("CLDX") |
|
|
|
|
|
|
|
# проверка сбора значения hash перемнной |
|
|
|
ns.level.linux.invalidate() |
|
|
|
assert ns.level.linux.ver.getValue() == "2.0" |
|
|
|
assert ns.level.linux.shortname.getValue() == "CLDG" |
|
|
|
assert ns.level.linux.ver.get_value() == "2.0" |
|
|
|
assert ns.level.linux.shortname.get_value() == "CLDG" |
|
|
|
|
|
|
|
assert ns.level.linux.test.getValue() == "my test - 2.0" |
|
|
|
assert ns.level.linux.test.get_value() == "my test - 2.0" |
|
|
|
|
|
|
|
# проверка обновления значения переменной, используеющей одно |
|
|
|
|