@ -1,7 +1,14 @@
import pytest
import pytest
import os
import os
from calculate . vars . datavars import Namespace , Variable , CyclicVariableError , VariableError , ReadonlyVariable , ChoiceVariable , IntegerVariable , StringVariable , DefaultValue , TableVariable , HashVariable , VariableNotFoundError
from calculate . vars . datavars import Namespace , Variable , CyclicVariableError , \
from calculate . vars . vars_loader import NamespaceIniFiller , VariableLoader , ProfileFiller , NamespaceIniFillerStrict
VariableError , ReadonlyVariable , \
ChoiceVariable , IntegerVariable , \
StringVariable , DefaultValue , \
TableVariable , HashVariable , \
VariableNotFoundError
from calculate . vars . vars_loader import NamespaceIniFiller , VariableLoader , \
ProfileFiller , NamespaceIniFillerStrict
@pytest.mark.vars
@pytest.mark.vars
class TestNamespace :
class TestNamespace :
@ -45,7 +52,7 @@ class TestNamespace:
assert ns . os . linux . fullname . getValue ( ) == " Calculate Linux Desktop "
assert ns . os . linux . fullname . getValue ( ) == " Calculate Linux Desktop "
assert ns . os . linux . root == ns
assert ns . os . linux . root == ns
nsif . fill ( ns , """
nsif . fill ( ns , """
[ os ] [ linux ]
[ os ] [ linux ]
shortname = CLDX
shortname = CLDX
""" )
""" )
@ -59,32 +66,32 @@ class TestNamespace:
nsif . fill ( ns , """
nsif . fill ( ns , """
[ os ]
[ os ]
test = 123
test = 123
[ os ]
[ os ]
test + = 345
test + = 345
""" )
""" )
assert ns . os . test . getValue ( ) == " 123,345 "
assert ns . os . test . getValue ( ) == " 123,345 "
nsif . fill ( ns , """
nsif . fill ( ns , """
[ os ]
[ os ]
test - = 123
test - = 123
""" )
""" )
assert ns . os . test . getValue ( ) == " 345 "
assert ns . os . test . getValue ( ) == " 345 "
nsif . fill ( ns , """
nsif . fill ( ns , """
[ os ]
[ os ]
test + = asdf , qwer , zxcv
test + = asdf , qwer , zxcv
""" )
""" )
assert ns . os . test . getValue ( ) == " 345,asdf,qwer,zxcv "
assert ns . os . test . getValue ( ) == " 345,asdf,qwer,zxcv "
nsif . fill ( ns , """
nsif . fill ( ns , """
[ os ]
[ os ]
test - = asdf , zxcv
test - = asdf , zxcv
""" )
""" )
assert ns . os . test . getValue ( ) == " 345,qwer "
assert ns . os . test . getValue ( ) == " 345,qwer "
def test_fill_namespace_clear_namespaces ( self ) :
def test_fill_namespace_clear_namespaces ( self ) :
@ -94,7 +101,7 @@ class TestNamespace:
[ test ] [ 0 ]
[ test ] [ 0 ]
dev = / dev / sda1
dev = / dev / sda1
mount = swap
mount = swap
[ test ] [ 1 ]
[ test ] [ 1 ]
dev = / dev / sda2
dev = / dev / sda2
mount = /
mount = /
@ -104,19 +111,23 @@ class TestNamespace:
mount = / var / calculate
mount = / var / calculate
""" )
""" )
assert [ x . dev . getValue ( ) for x in ns . test ] == [ ' /dev/sda1 ' , ' /dev/sda2 ' , ' /dev/sda5 ' ]
assert [ x . dev . getValue ( ) for x in ns . test ] == [ ' /dev/sda1 ' ,
' /dev/sda2 ' ,
' /dev/sda5 ' ]
nsif . fill ( ns , """
nsif . fill ( ns , """
[ test ] [ 0 ]
[ test ] [ 0 ]
dev = / dev / sdb1
dev = / dev / sdb1
mount = swap
mount = swap
[ test ] [ 1 ]
[ test ] [ 1 ]
dev = / dev / sdb2
dev = / dev / sdb2
mount = /
mount = /
""" )
""" )
assert [ x . dev . getValue ( ) for x in ns . test ] == [ ' /dev/sdb1 ' , ' /dev/sdb2 ' , ' /dev/sda5 ' ]
assert [ x . dev . getValue ( ) for x in ns . test ] == [ ' /dev/sdb1 ' ,
' /dev/sdb2 ' ,
' /dev/sda5 ' ]
nsif . fill ( ns , """
nsif . fill ( ns , """
[ test ] [ ]
[ test ] [ ]
@ -124,13 +135,14 @@ class TestNamespace:
[ test ] [ 0 ]
[ test ] [ 0 ]
dev = / dev / sdb1
dev = / dev / sdb1
mount = swap
mount = swap
[ test ] [ 1 ]
[ test ] [ 1 ]
dev = / dev / sdb2
dev = / dev / sdb2
mount = /
mount = /
""" )
""" )
assert [ x . dev . getValue ( ) for x in ns . test ] == [ ' /dev/sdb1 ' , ' /dev/sdb2 ' ]
assert [ x . dev . getValue ( ) for x in ns . test ] == [ ' /dev/sdb1 ' ,
' /dev/sdb2 ' ]
def test_fill_namespace_strict_clear ( self ) :
def test_fill_namespace_strict_clear ( self ) :
ns = Namespace ( )
ns = Namespace ( )
@ -139,7 +151,7 @@ class TestNamespace:
[ os ] [ test ] [ 0 ]
[ os ] [ test ] [ 0 ]
dev = / dev / sda1
dev = / dev / sda1
mount = swap
mount = swap
[ os ] [ test ] [ 1 ]
[ os ] [ test ] [ 1 ]
dev = / dev / sda2
dev = / dev / sda2
mount = /
mount = /
@ -165,15 +177,12 @@ class TestNamespace:
[ custom ] [ ]
[ custom ] [ ]
""" )
""" )
assert [ x for x in ns . custom ] == [ ]
assert [ x for x in ns . custom ] == [ ]
def test_get_namespace_attrs ( self ) :
def test_get_namespace_attrs ( self ) :
ns = Namespace ( )
ns = Namespace ( )
os = Namespace ( " os " )
os = Namespace ( " os " )
os . addStringVariable ( " test " , " zxcv " )
os . addStringVariable ( " test " , " zxcv " )
ns . addNamespace ( os )
ns . addNamespace ( os )
assert ns . os . test . getValue ( ) == " zxcv "
assert ns . os . test . getValue ( ) == " zxcv "
@ -190,7 +199,7 @@ class TestNamespace:
return " A "
return " A "
var = TestVar ( " test " )
var = TestVar ( " test " )
assert var . getValue ( ) == " A "
assert var . getValue ( ) == " A "
def test_namespace_lookup ( self ) :
def test_namespace_lookup ( self ) :
@ -202,11 +211,11 @@ class TestNamespace:
os . addNamespace ( linux )
os . addNamespace ( linux )
os . addNamespace ( device )
os . addNamespace ( device )
device1 = device . addNamespace ( )
device1 = device . addNamespace ( )
device1 . addStringVariable ( " dev " , " /dev/sda " )
device1 . addStringVariable ( " dev " , " /dev/sda " )
device2 = device . addNamespace ( )
device2 = device . addNamespace ( )
device2 . addStringVariable ( " dev " , " /dev/sdb " )
device2 . addStringVariable ( " dev " , " /dev/sdb " )
device3 = device . addNamespace ( )
device3 = device . addNamespace ( )
device3 . addStringVariable ( " dev " , " /dev/sdc " )
device3 . addStringVariable ( " dev " , " /dev/sdc " )
ns . addStringVariable ( " first " , " first " )
ns . addStringVariable ( " first " , " first " )
os . addStringVariable ( " second " , " second " )
os . addStringVariable ( " second " , " second " )
@ -221,7 +230,7 @@ class TestNamespace:
assert linux . root . os . second . getValue ( ) == " second "
assert linux . root . os . second . getValue ( ) == " second "
with pytest . raises ( VariableNotFoundError ) :
with pytest . raises ( VariableNotFoundError ) :
z = os. third
os. third
assert ns . os . device [ 0 ] . dev . getValue ( ) == " /dev/sda "
assert ns . os . device [ 0 ] . dev . getValue ( ) == " /dev/sda "
assert ns . os . device [ " 0 " ] . dev . getValue ( ) == " /dev/sda "
assert ns . os . device [ " 0 " ] . dev . getValue ( ) == " /dev/sda "
@ -230,7 +239,8 @@ class TestNamespace:
assert ns . os . device . parent . second . getValue ( ) == " second "
assert ns . os . device . parent . second . getValue ( ) == " second "
assert ns . os . device . parent . parent . os . second . getValue ( ) == " second "
assert ns . os . device . parent . parent . os . second . getValue ( ) == " second "
assert ns . os . device . parent . parent . parent . os . second . getValue ( ) == " second "
assert ns . os . device . parent . parent . parent . os . second . \
getValue ( ) == " second "
def test_variable_get_value_by_variable ( self ) :
def test_variable_get_value_by_variable ( self ) :
class TestVar1 ( Variable ) :
class TestVar1 ( Variable ) :
@ -278,7 +288,6 @@ class TestNamespace:
assert test1 . counter == 3
assert test1 . counter == 3
def test_cyclic_variable ( self ) :
def test_cyclic_variable ( self ) :
class TestVar1 ( Variable ) :
class TestVar1 ( Variable ) :
def get ( self ) :
def get ( self ) :
return " %s ,test1 " % self . vars . test2 . getValue ( self )
return " %s ,test1 " % self . vars . test2 . getValue ( self )
@ -301,10 +310,12 @@ class TestNamespace:
ns . addVariable ( test3 )
ns . addVariable ( test3 )
with pytest . raises ( CyclicVariableError ) as e :
with pytest . raises ( CyclicVariableError ) as e :
z = ns . test1 . getValue ( )
ns . test1 . getValue ( )
assert e . value . queue [ : - 1 ] == ( " test1 " , " test2 " , " test3 " )
assert e . value . queue [ : - 1 ] == ( " test1 " , " test2 " , " test3 " )
with pytest . raises ( VariableError ) as e :
with pytest . raises ( VariableError ) as e :
z = ns . test1 . getValue ( )
ns. test1 . getValue ( )
def test_drop_invalidate_after_set_value ( self ) :
def test_drop_invalidate_after_set_value ( self ) :
class TestVar1 ( Variable ) :
class TestVar1 ( Variable ) :
@ -317,7 +328,7 @@ class TestNamespace:
class TestVar2 ( Variable ) :
class TestVar2 ( Variable ) :
def get ( self ) :
def get ( self ) :
return " ZZZZ "
return " ZZZZ "
test1 = TestVar1 ( " test1 " )
test1 = TestVar1 ( " test1 " )
test2 = TestVar2 ( " test2 " )
test2 = TestVar2 ( " test2 " )
ns = Namespace ( )
ns = Namespace ( )
@ -325,7 +336,7 @@ class TestNamespace:
ns . addVariable ( test2 )
ns . addVariable ( test2 )
assert test1 . getValue ( ) == " ZZZZ,test1 "
assert test1 . getValue ( ) == " ZZZZ,test1 "
test1 . setValue ( " VVVV " )
test1 . setValue ( " VVVV " )
assert test1 . getValue ( ) == " VVVV "
assert test1 . getValue ( ) == " VVVV "
@ -344,9 +355,10 @@ class TestNamespace:
def test_change_invalidator_variable ( self ) :
def test_change_invalidator_variable ( self ) :
class VarTest ( Variable ) :
class VarTest ( Variable ) :
counter = 0
counter = 0
def get ( self ) :
def get ( self ) :
self . counter + = 1
self . counter + = 1
if self . vars . ifvar . getValue ( self ) :
if self . vars . ifvar . getValue ( self ) :
return " %s ,test1 " % self . vars . vara . getValue ( self )
return " %s ,test1 " % self . vars . vara . getValue ( self )
else :
else :
@ -384,7 +396,7 @@ class TestNamespace:
test1 = TestVar1 ( " test1 " )
test1 = TestVar1 ( " test1 " )
assert test1 . getValue ( ) == " test1 "
assert test1 . getValue ( ) == " test1 "
with pytest . raises ( VariableError ) as e :
with pytest . raises ( VariableError ) :
test1 . setValue ( " test2 " )
test1 . setValue ( " test2 " )
assert test1 . getValue ( ) == " test1 "
assert test1 . getValue ( ) == " test1 "
@ -399,7 +411,7 @@ class TestNamespace:
return [ " test1 " , " test2 " ]
return [ " test1 " , " test2 " ]
test1 = TestVar1 ( " test1 " )
test1 = TestVar1 ( " test1 " )
with pytest . raises ( VariableError ) as e :
with pytest . raises ( VariableError ) :
test1 . setValue ( " test3 " )
test1 . setValue ( " test3 " )
test1 . setValue ( " test2 " )
test1 . setValue ( " test2 " )
assert test1 . getValue ( ) == " test2 "
assert test1 . getValue ( ) == " test2 "
@ -409,7 +421,7 @@ class TestNamespace:
properties = [ IntegerVariable ]
properties = [ IntegerVariable ]
test1 = TestVar1 ( " test1 " )
test1 = TestVar1 ( " test1 " )
with pytest . raises ( VariableError ) as e :
with pytest . raises ( VariableError ) :
test1 . setValue ( " test3 " )
test1 . setValue ( " test3 " )
test1 . setValue ( " 33 " )
test1 . setValue ( " 33 " )
assert test1 . getValue ( ) == 33
assert test1 . getValue ( ) == 33
@ -447,7 +459,6 @@ class TestNamespace:
def get ( self ) :
def get ( self ) :
return " ZXC %s " % self . vars . test2 . getCommentValue ( self )
return " ZXC %s " % self . vars . test2 . getCommentValue ( self )
ns = Namespace ( )
ns = Namespace ( )
test1 = TestVar1 ( " test1 " )
test1 = TestVar1 ( " test1 " )
assert test1 . getValue ( ) == " 123 "
assert test1 . getValue ( ) == " 123 "
@ -474,7 +485,7 @@ class TestNamespace:
properties = [ ChoiceVariable ]
properties = [ ChoiceVariable ]
def choice ( self ) :
def choice ( self ) :
return [ " test1 " , " test2 " ]
return [ " test1 " , " test2 " ]
class TestVar3 ( Variable ) :
class TestVar3 ( Variable ) :
properties = [ ChoiceVariable ]
properties = [ ChoiceVariable ]
@ -487,43 +498,54 @@ class TestNamespace:
test2 = TestVar2 ( " test2 " )
test2 = TestVar2 ( " test2 " )
test3 = TestVar3 ( " test3 " )
test3 = TestVar3 ( " test3 " )
with pytest . raises ( VariableError ) as e :
with pytest . raises ( VariableError ) :
test1 . choice ( )
test1 . choice ( )
with pytest . raises ( VariableError ) as e :
with pytest . raises ( VariableError ) :
test1 . choiceComment ( )
test1 . choiceComment ( )
assert test2 . choice ( ) == [ " test1 " , " test2 " ]
assert test2 . choice ( ) == [ " test1 " , " test2 " ]
assert test2 . choiceComment ( ) == [ ( " test1 " , " test1 " ) , ( " test2 " , " test2 " ) ]
assert test2 . choiceComment ( ) == [ ( " test1 " , " test1 " ) ,
( " test2 " , " test2 " ) ]
assert test3 . choice ( ) == [ " test1 " , " test2 " ]
assert test3 . choice ( ) == [ " test1 " , " test2 " ]
assert test3 . choiceComment ( ) == [ ( " test1 " , " Test1 " ) , ( " test2 " , " Test2 " ) ]
assert test3 . choiceComment ( ) == [ ( " test1 " , " Test1 " ) ,
( " test2 " , " Test2 " ) ]
def test_loading_test_variable_module ( self ) :
def test_loading_test_variable_module ( self ) :
ns = Namespace ( )
ns = Namespace ( )
vl = VariableLoader ( )
vl = VariableLoader ( )
vl . fill ( ns , " tests/vars/variables " , " testvars " )
vl . fill ( ns , " tests/vars/variables " , " testvars " )
assert ns . level . simple . getValue ( ) == " simple value "
assert ns . level . simple . getValue ( ) == " simple value "
assert ns . level . uselocalsimple . getValue ( ) == " Using simple value "
assert ns . level . uselocalsimple . getValue ( ) == " Using simple value "
assert ns . level . usefullsimple . getValue ( ) == " Using simple value "
assert ns . level . usefullsimple . getValue ( ) == " Using simple value "
with pytest . raises ( VariableError ) as e :
with pytest . raises ( VariableError ) :
ns . level . badchoice . choice ( )
ns . level . badchoice . choice ( )
with pytest . raises ( VariableError ) as e :
with pytest . raises ( VariableError ) :
ns . level . badchoice . choiceComment ( )
ns . level . badchoice . choiceComment ( )
assert ns . level . simple_choice . choice ( ) == [ " /dev/sda1 " , " /dev/sda2 " , " /dev/sda3 " ]
assert ns . level . simple_choice . choice ( ) == [ " /dev/sda1 " ,
assert ns . level . comment_choice . choice ( ) == [ " /dev/sda1 " , " /dev/sda2 " , " /dev/sda3 " ]
" /dev/sda2 " ,
assert ns . level . comment_choice . choiceComment ( ) == [ ( " /dev/sda1 " , " SWAP " ) , ( " /dev/sda2 " , " ROOT " ) , ( " /dev/sda3 " , " DATA " ) ]
" /dev/sda3 " ]
assert ns . level . comment_choice . choice ( ) == [ " /dev/sda1 " ,
" /dev/sda2 " ,
" /dev/sda3 " ]
assert ns . level . comment_choice . choiceComment ( ) == [
( " /dev/sda1 " , " SWAP " ) ,
( " /dev/sda2 " , " ROOT " ) ,
( " /dev/sda3 " , " DATA " ) ]
ns . level . disks . setValue ( [ " /dev/sda2 " , " /dev/sda1 " ] )
ns . level . disks . setValue ( [ " /dev/sda2 " , " /dev/sda1 " ] )
assert ns . level . disks . getValue ( ) == [ " /dev/sda2 " , " /dev/sda1 " ]
assert ns . level . disks . getValue ( ) == [ " /dev/sda2 " , " /dev/sda1 " ]
assert ns . level . comment_choice . choice ( ) == [ " /dev/sda2 " , " /dev/sda1 " ]
assert ns . level . comment_choice . choice ( ) == [ " /dev/sda2 " , " /dev/sda1 " ]
assert ns . level . comment_choice . choiceComment ( ) == [ ( " /dev/sda2 " , " ROOT " ) ,
assert ns . level . comment_choice . choiceComment ( ) == [
( " /dev/sda1 " , " SWAP " ) ]
( " /dev/sda2 " , " ROOT " ) ,
( " /dev/sda1 " , " SWAP " ) ]
assert ns . level is not ns . level . level2 . root
assert ns . level is not ns . level . level2 . root
assert ns is ns . level . level2 . root
assert ns is ns . level . level2 . root
@ -535,7 +557,6 @@ class TestNamespace:
vl = VariableLoader ( )
vl = VariableLoader ( )
vl . fill ( ns , " tests/vars/variables " , " testvars " )
vl . fill ( ns , " tests/vars/variables " , " testvars " )
assert ns . level . linux . getFullname ( ) == " level.linux "
assert ns . level . linux . getFullname ( ) == " level.linux "
assert ns . level . linux . ver . fullname == " level.linux.ver "
assert ns . level . linux . ver . fullname == " level.linux.ver "
@ -550,7 +571,7 @@ class TestNamespace:
# проверка установки значения hash переменной
# проверка установки значения hash переменной
ns . level . linux . ver . setValue ( " 3.0 " )
ns . level . linux . ver . setValue ( " 3.0 " )
assert ns . level . linux . ver . getValue ( ) == " 3.0 "
assert ns . level . linux . ver . getValue ( ) == " 3.0 "
# после установки хотя бы одного значения в hash переменной
# после установки хотя бы одного значения в hash переменной
# обновление остальных прекращаются до инвалидации (так как
# обновление остальных прекращаются до инвалидации (так как
# значения рассматриваются комплексно)
# значения рассматриваются комплексно)
@ -558,7 +579,7 @@ class TestNamespace:
assert ns . level . linux . shortname . getValue ( ) == " CLD "
assert ns . level . linux . shortname . getValue ( ) == " CLD "
# проверка попытки изменить readonly переменную
# проверка попытки изменить readonly переменную
with pytest . raises ( VariableError ) as e :
with pytest . raises ( VariableError ) :
ns . level . linux . shortname . setValue ( " CLDX " )
ns . level . linux . shortname . setValue ( " CLDX " )
# проверка с б о р а значения hash перемнной
# проверка с б о р а значения hash перемнной
@ -571,10 +592,9 @@ class TestNamespace:
# проверка обновления значения переменной, используеющей одно
# проверка обновления значения переменной, используеющей одно
# из значений hash переменной
# из значений hash переменной
assert ns . level . shortname_test . getValue ( ) == " CLDG test "
assert ns . level . shortname_test . getValue ( ) == " CLDG test "
ns . level . linux . shortname . setValue ( " CLDX " , force = True )
ns . level . linux . shortname . setValue ( " CLDX " , force = True )
assert ns . level . shortname_test . getValue ( ) == " CLDX test "
assert ns . level . shortname_test . getValue ( ) == " CLDX test "
def test_table_variable ( self ) :
def test_table_variable ( self ) :
# table variable
# table variable
ns = Namespace ( )
ns = Namespace ( )
@ -583,77 +603,83 @@ class TestNamespace:
assert ns . level . device [ 0 ] . dev . getValue ( ) == " /dev/sda "
assert ns . level . device [ 0 ] . dev . getValue ( ) == " /dev/sda "
assert ns . level . device [ 1 ] . dev . getValue ( ) == " /dev/sdb "
assert ns . level . device [ 1 ] . dev . getValue ( ) == " /dev/sdb "
assert ns . level . device . getValue ( ) == [
assert ns . level . device . getValue ( ) == [ { " dev " : " /dev/sda " ,
{ " dev " : " /dev/sda " ,
" type " : " hdd " ,
" type " : " hdd " ,
" name " : " Samsung SSD " } ,
" name " : " Samsung SSD "
{ " dev " : " /dev/sdb " ,
} ,
" type " : " flash " ,
{ " dev " : " /dev/sdb " ,
" name " : " Transcend 64GB " } ]
" type " : " flash " ,
" name " : " Transcend 64GB "
} ,
]
assert ns . level . device [ 1 ] . type . getValue ( ) == " flash "
assert ns . level . device [ 1 ] . type . getValue ( ) == " flash "
# проверка обновления списка пространства имён у табличной переменной
# проверка обновления списка пространства имён у табличной переменной
ns . level . devicelist . setValue ( [ " /dev/sda " , " /dev/sdb " , " /dev/sdc " ] )
ns . level . devicelist . setValue ( [ " /dev/sda " , " /dev/sdb " , " /dev/sdc " ] )
assert ns . level . device [ 2 ] . type . getValue ( ) == " usbhdd "
assert ns . level . device [ 2 ] . type . getValue ( ) == " usbhdd "
assert [ x . type . getValue ( ) for x in ns . level . device ] == [ " hdd " , " flash " , " usbhdd " ]
assert [ x . type . getValue ( ) for x in ns . level . device ] == [ " hdd " ,
" flash " ,
" usbhdd " ]
assert ns . level . device_child . getValue ( ) == " hdd "
assert ns . level . device_child . getValue ( ) == " hdd "
ns . level . devicelist . setValue ( [ " /dev/sda " , " /dev/sdb " ] )
ns . level . devicelist . setValue ( [ " /dev/sda " , " /dev/sdb " ] )
ns . level . device [ 0 ] . type . setValue ( " flash " )
ns . level . device [ 0 ] . type . setValue ( " flash " )
assert ns . level . device . getValue ( ) == [
assert ns . level . device . getValue ( ) == [ { " dev " : " /dev/sda " ,
{ " dev " : " /dev/sda " ,
" type " : " flash " ,
" type " : " flash " ,
" name " : " Samsung SSD " } ,
" name " : " Samsung SSD "
{ " dev " : " /dev/sdb " ,
} ,
" type " : " flash " ,
{ " dev " : " /dev/sdb " ,
" name " : " Transcend 64GB " } ]
" type " : " flash " ,
" name " : " Transcend 64GB "
} ,
]
assert ns . level . device_child . getValue ( ) == " flash "
assert ns . level . device_child . getValue ( ) == " flash "
# после установки хотя бы одного значения в table переменной
# после установки хотя бы одного значения в table переменной
# обновление остальных прекращаются до инвалидации (так как
# обновление остальных прекращаются до инвалидации (так как
# значения рассматриваются комплексно)
# значения рассматриваются комплексно)
ns . level . devicelist . setValue ( [ " /dev/sda " , " /dev/sdb " , " /dev/sdc " ] )
ns . level . devicelist . setValue ( [ " /dev/sda " , " /dev/sdb " , " /dev/sdc " ] )
assert [ x . dev . getValue ( ) for x in ns . level . device ] == [ " /dev/sda " , " /dev/sdb " ]
assert [ x . dev . getValue ( ) for x in ns . level . device ] == [ " /dev/sda " ,
" /dev/sdb " ]
ns . level . device . invalidate ( )
ns . level . device . invalidate ( )
assert [ x . dev . getValue ( ) for x in ns . level . device ] == [ " /dev/sda " , " /dev/sdb " , " /dev/sdc " ]
assert [ x . dev . getValue ( ) for x in ns . level . device ] == [ " /dev/sda " ,
# проверить на повторное изменение, убедится, что _drop_child отрабатывает
" /dev/sdb " ,
ns . level . devicelist . setValue ( [ " /dev/sda " , " /dev/sdb " , " /dev/sdc " , " /dev/sdd " ] )
" /dev/sdc " ]
# проверить на повторное изменение, убедится, что _drop_child
# отрабатывает
ns . level . devicelist . setValue ( [ " /dev/sda " , " /dev/sdb " ,
" /dev/sdc " , " /dev/sdd " ] )
ns . level . device . invalidate ( )
ns . level . device . invalidate ( )
assert [ x . dev . getValue ( ) for x in ns . level . device ] == [ " /dev/sda " , " /dev/sdb " , " /dev/sdc " , " /dev/sdd " ]
assert [ x . dev . getValue ( ) for x in ns . level . device ] == [ " /dev/sda " ,
" /dev/sdb " ,
" /dev/sdc " ,
" /dev/sdd " ]
def test_wrong_table_variable ( self ) :
def test_wrong_table_variable ( self ) :
class Testtable ( TableVariable ) :
class Testtable ( TableVariable ) :
class Data ( TableVariable . Data ) :
class Data ( TableVariable . Data ) :
def get ( self ) :
def get ( self ) :
return [ { ' dev ' : ' 123 ' , ' name ' : ' 098 ' } ]
return [ { ' dev ' : ' 123 ' , ' name ' : ' 098 ' } ]
ns = Namespace ( )
ns = Namespace ( )
ns . addNamespace ( Namespace ( " test " ) )
ns . addNamespace ( Namespace ( " test " ) )
ns . test . addNamespace ( Namespace ( " test2 " ) )
ns . test . addNamespace ( Namespace ( " test2 " ) )
error_message = ( " Missed ' hash_vars ' attribute for table "
" variable test.test2.testtable " )
with pytest . raises ( VariableError ) as e :
with pytest . raises ( VariableError ) as e :
ns . test . test2 . addNamespace ( Testtable ( " testtable " , ns . test . test2 ) )
ns . test . test2 . addNamespace ( Testtable ( " testtable " , ns . test . test2 ) )
assert str ( e . value ) == " Missed ' hash_vars ' attribute for table variable test.test2.testtable "
assert str ( e . value ) == error_message
def test_wrong_hash_variable ( self ) :
def test_wrong_hash_variable ( self ) :
class Testhash ( HashVariable ) :
class Testhash ( HashVariable ) :
class Data ( HashVariable . Data ) :
class Data ( HashVariable . Data ) :
def get ( self ) :
def get ( self ) :
return { ' dev ' : ' 123 ' , ' name ' : ' 098 ' }
return { ' dev ' : ' 123 ' , ' name ' : ' 098 ' }
ns = Namespace ( )
ns = Namespace ( )
ns . addNamespace ( Namespace ( " test " ) )
ns . addNamespace ( Namespace ( " test " ) )
ns . test . addNamespace ( Namespace ( " test2 " ) )
ns . test . addNamespace ( Namespace ( " test2 " ) )
error_message = ( " Missed ' hash_vars ' attribute for hash "
" variable test.test2.testhash " )
with pytest . raises ( VariableError ) as e :
with pytest . raises ( VariableError ) as e :
ns . test . test2 . addNamespace ( Testhash ( " testhash " , ns . test . test2 ) )
ns . test . test2 . addNamespace ( Testhash ( " testhash " , ns . test . test2 ) )
assert str ( e . value ) == " Missed ' hash_vars ' attribute for hash variable test.test2.testhash "
assert str ( e . value ) == error_message
def test_namespace_iteration ( self ) :
def test_namespace_iteration ( self ) :
ns = Namespace ( )
ns = Namespace ( )
@ -664,7 +690,7 @@ class TestNamespace:
ns2 = ns . addNamespace ( )
ns2 = ns . addNamespace ( )
ns2 . addStringVariable ( " test " , " 456 " )
ns2 . addStringVariable ( " test " , " 456 " )
assert [ x . test . getValue ( ) for x in ns ] == [ " 123 " , " 234 " , " 456 " ]
assert [ x . test . getValue ( ) for x in ns ] == [ " 123 " , " 234 " , " 456 " ]
def test_subnamespace ( self ) :
def test_subnamespace ( self ) :
ns = Namespace ( )
ns = Namespace ( )
@ -679,20 +705,24 @@ class TestNamespace:
vl = VariableLoader ( )
vl = VariableLoader ( )
vl . fill ( ns , " tests/vars/variables " , " testvars " )
vl . fill ( ns , " tests/vars/variables " , " testvars " )
error_message = " Variable or namespace level.level3.myvar3 not found "
with pytest . raises ( VariableError ) as e :
with pytest . raises ( VariableError ) as e :
z = ns. level . level3 . myvar3 . getValue ( )
ns. level . level3 . myvar3 . getValue ( )
assert str ( e . value ) == " Variable or namespace level.level3.myvar3 not found "
assert str ( e . value ) == error_message
# TODO: тест использует значения на конкретной машине
# TODO: тест использует значения на конкретной машине
#def test_simple(self):
# def test_simple(self):
# ns = Namespace()
# ns = Namespace()
# vl = VariableLoader()
# vl = VariableLoader()
# vl.fill(ns, *VariableLoader.default())
# vl.fill(ns, *VariableLoader.default())
# # нужно исправить тест, так
# # нужно исправить тест, так
# # assert [x.name.getValue() for x in ns.os.gentoo.repositories] == ["gentoo","distros","calculate","custom"]
# # assert [x.name.getValue() for x in ns.os.gentoo.repositories] ==\
# assert ns.os.gentoo.make_profile.getValue() == "/etc/portage/make.profile"
# ["gentoo","distros","calculate","custom"]
# assert ns.os.gentoo.profile.path.getValue() == "/var/db/repos/distros/profiles/CLD/amd64/20"
# assert ns.os.gentoo.make_profile.getValue() ==\
# assert ns.os.gentoo.profile.name.getValue() == "distros:CLD/amd64/20"
# "/etc/portage/make.profile"
# assert ns.os.gentoo.profile.path.getValue() ==\
# "/var/db/repos/distros/profiles/CLD/amd64/20"
# assert ns.os.gentoo.profile.name.getValue() == "distros:CLD/amd64/20"
def test_profile_filler ( self ) :
def test_profile_filler ( self ) :
ns = Namespace ( )
ns = Namespace ( )
@ -702,11 +732,15 @@ class TestNamespace:
class ProfileFillerTest ( ProfileFiller ) :
class ProfileFillerTest ( ProfileFiller ) :
def getRepositoryMap ( self , ns ) :
def getRepositoryMap ( self , ns ) :
curdir = os . getcwd ( )
curdir = os . getcwd ( )
return {
return { ' distros ' :
' distros ' : os . path . join ( curdir , " tests/utils/gentoo/repos/distros " ) ,
os . path . join ( curdir ,
' calculate ' : os . path . join ( curdir , " tests/utils/gentoo/repos/calculate " ) ,
" tests/utils/gentoo/repos/distros " ) ,
' gentoo ' : os . path . join ( curdir , " tests/utils/gentoo/portage " ) ,
' calculate ' :
}
os . path . join ( curdir ,
" tests/utils/gentoo/repos/calculate " ) ,
' gentoo ' :
os . path . join ( curdir ,
" tests/utils/gentoo/portage " ) }
assert ns . os . hashvar . value1 . getValue ( ) == " test1 "
assert ns . os . hashvar . value1 . getValue ( ) == " test1 "
assert ns . os . hashvar . value2 . getValue ( ) == " test2 "
assert ns . os . hashvar . value2 . getValue ( ) == " test2 "
@ -740,12 +774,12 @@ class TestNamespace:
assert ns . os . tablevar [ 1 ] . dev . getValue ( ) == " /dev/sda2 "
assert ns . os . tablevar [ 1 ] . dev . getValue ( ) == " /dev/sda2 "
assert ns . os . tablevar [ 2 ] . dev . getValue ( ) == " /dev/sda5 "
assert ns . os . tablevar [ 2 ] . dev . getValue ( ) == " /dev/sda5 "
def test_fill_namespace_by_module ( self ) :
def test_fill_namespace_by_module ( self ) :
ns = Namespace ( )
pass
vl = VariableLoader ( )
# ns = Namespace()
vl . fill ( ns , * VariableLoader . default ( ) )
# vl = VariableLoader()
assert " os " in ns
# vl.fill(ns, *VariableLoader.default())
assert " config " in ns . os . gentoo
# assert "os" in ns
assert " main " in ns
# assert "config" in ns.os.gentoo
assert ns . os . gentoo . config . getValue ( ) is not None
# assert "main" in ns
# assert ns.os.gentoo.config.getValue() is not None