本文整理汇总了Python中scap.Model.Model.load方法的典型用法代码示例。如果您正苦于以下问题:Python Model.load方法的具体用法?Python Model.load怎么用?Python Model.load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scap.Model.Model
的用法示例。
在下文中一共展示了Model.load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_load_attribute_required
# 需要导入模块: from scap.Model import Model [as 别名]
# 或者: from scap.Model.Model import load [as 别名]
def test_load_attribute_required():
attr = Model.load(None, ET.fromstring('<test:RequiredAttributeFixture xmlns:test="http://jaymes.biz/test" required_attribute="test" />'))
assert isinstance(attr, RequiredAttributeFixture)
assert hasattr(attr, 'required_attribute')
assert attr.required_attribute == 'test'
with pytest.raises(RequiredAttributeException):
attr = Model.load(None, ET.fromstring('<test:RequiredAttributeFixture xmlns:test="http://jaymes.biz/test" />'))
示例2: test_load_root_model
# 需要导入模块: from scap.Model import Model [as 别名]
# 或者: from scap.Model.Model import load [as 别名]
def test_load_root_model():
root = Model.load(None, ET.fromstring('<test:RootFixture xmlns:test="http://jaymes.biz/test" />'))
assert isinstance(root, RootFixture)
with pytest.raises(UnregisteredNamespaceException):
Model.load(None, ET.fromstring('<test:RootFixture xmlns:test="http://jaymes.biz/derp" />'))
with pytest.raises(TagMappingException):
Model.load(None, ET.fromstring('<test:Derp xmlns:test="http://jaymes.biz/test" />'))
示例3: test_load_element_min
# 需要导入模块: from scap.Model import Model [as 别名]
# 或者: from scap.Model.Model import load [as 别名]
def test_load_element_min():
el = Model.load(None, ET.fromstring('''
<test:MinMaxElementFixture xmlns:test="http://jaymes.biz/test">
<test:min>test1</test:min>
<test:min>test2</test:min>
<test:min>test3</test:min>
<test:max>test4</test:max>
<test:max>test5</test:max>
</test:MinMaxElementFixture>
'''))
assert isinstance(el, MinMaxElementFixture)
assert hasattr(el, 'min')
assert isinstance(el.min, ModelList)
assert len(el.min) == 3
assert el.min[0].text == 'test1'
assert el.min[1].text == 'test2'
assert el.min[2].text == 'test3'
assert hasattr(el, 'max')
assert isinstance(el.max, ModelList)
assert len(el.max) == 2
assert el.max[0].text == 'test4'
assert el.max[1].text == 'test5'
with pytest.raises(MinimumElementException):
el = Model.load(None, ET.fromstring('''
<test:MinMaxElementFixture xmlns:test="http://jaymes.biz/test">
<test:min>test1</test:min>
<test:max>test4</test:max>
<test:max>test5</test:max>
</test:MinMaxElementFixture>
'''))
with pytest.raises(MaximumElementException):
el = Model.load(None, ET.fromstring('''
<test:MinMaxElementFixture xmlns:test="http://jaymes.biz/test">
<test:min>test1</test:min>
<test:min>test2</test:min>
<test:min>test3</test:min>
<test:max>test4</test:max>
<test:max>test5</test:max>
<test:max>test6</test:max>
</test:MinMaxElementFixture>
'''))
示例4: test_simple_remote
# 需要导入模块: from scap.Model import Model [as 别名]
# 或者: from scap.Model.Model import load [as 别名]
def test_simple_remote():
model = Model.load(None, ET.fromstring('<test:XLinkFixture ' +
'xmlns:test="http://jaymes.biz/test" ' +
'xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" ' +
'xlink:href="http://jaymes.biz/test.xml" />'))
assert isinstance(model._elements, ModelList)
assert len(model._elements) > 0
assert isinstance(model._elements[0], RootFixture)
assert isinstance(model._elements[0].EnclosedFixture, EnclosedFixture)
示例5: test_load_enclosed_model
# 需要导入模块: from scap.Model import Model [as 别名]
# 或者: from scap.Model.Model import load [as 别名]
def test_load_enclosed_model():
root = RootFixture()
el = Model.load(root, ET.fromstring('<test:EnclosedFixture xmlns:test="http://jaymes.biz/test" />'))
assert isinstance(el, EnclosedFixture)
el = Model.load(root, ET.fromstring('<EnclosedFixture />'))
assert isinstance(el, EnclosedFixture)
with pytest.raises(UnregisteredNamespaceException):
Model.load(root, ET.fromstring('<test:EnclosedFixture xmlns:test="http://jaymes.biz/derp" />'))
with pytest.raises(UnregisteredNamespaceException):
Model.load(None, ET.fromstring('<EnclosedFixture />'))
with pytest.raises(TagMappingException):
Model.load(root, ET.fromstring('<Derp />'))
示例6: test_simple_local
# 需要导入模块: from scap.Model import Model [as 别名]
# 或者: from scap.Model.Model import load [as 别名]
def test_simple_local():
path = (
pathlib.Path(str(pytest.config.rootdir)) / 'tests' / 'model' / 'test_xlink.xml'
).as_posix()
if not path.startswith('/'):
path = '/' + path
model = Model.load(None, ET.fromstring('<test:XLinkFixture ' +
'xmlns:test="http://jaymes.biz/test" ' +
'xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" ' +
'xlink:href="file://' + path + '" />'))
assert isinstance(model._elements, ModelList)
assert len(model._elements) > 0
assert isinstance(model._elements[0], RootFixture)
assert isinstance(model._elements[0].EnclosedFixture, EnclosedFixture)
示例7: test_oval_5_3_detected
# 需要导入模块: from scap.Model import Model [as 别名]
# 或者: from scap.Model.Model import load [as 别名]
def test_oval_5_3_detected():
test_xml = '<oval_definitions ' + \
'xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5" ' + \
'xmlns:oval="http://oval.mitre.org/XMLSchema/oval-common-5" ' + \
'xmlns:oval-def="http://oval.mitre.org/XMLSchema/oval-definitions-5">' + \
'<generator>' + \
'<oval:product_name>The OVAL Repository</oval:product_name>' + \
'<oval:schema_version>5.3</oval:schema_version>' + \
'<oval:timestamp>2008-04-10T09:00:10.653-04:00</oval:timestamp>' + \
'</generator>' + \
'</oval_definitions>'
model = Model.load(None, ET.fromstring(test_xml))
from scap.model.oval_5.defs.OvalDefinitionsElement import OvalDefinitionsElement
assert isinstance(model, OvalDefinitionsElement)
示例8: test_load_element_wildcard_not_in
# 需要导入模块: from scap.Model import Model [as 别名]
# 或者: from scap.Model.Model import load [as 别名]
def test_load_element_wildcard_not_in():
el = Model.load(None, ET.fromstring('''
<test:WildcardElementNotInFixture xmlns:test2="http://jaymes.biz/test2" xmlns:test="http://jaymes.biz/test">
<test:wildcard_element>test1</test:wildcard_element>
<test2:wildcard_element>test2</test2:wildcard_element>
</test:WildcardElementNotInFixture>
'''))
assert isinstance(el, WildcardElementNotInFixture)
assert hasattr(el, '_elements')
assert isinstance(el._elements, ModelList)
assert len(el._elements) == 2
assert isinstance(el._elements[0], EnclosedFixture)
assert isinstance(el._elements[1], EnclosedFixture2)
assert el._elements[0].text == 'test1'
assert el._elements[1].text == 'test2'
示例9: test_load_element_append_nil
# 需要导入模块: from scap.Model import Model [as 别名]
# 或者: from scap.Model.Model import load [as 别名]
def test_load_element_append_nil():
el = Model.load(None, ET.fromstring('''
<test:AppendElementFixture xmlns:test="http://jaymes.biz/test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<test:append_nil xsi:nil="true" />
<test:append_nil>test2</test:append_nil>
</test:AppendElementFixture>
'''))
assert isinstance(el, AppendElementFixture)
assert hasattr(el, 'append_nil')
assert isinstance(el.append_nil, ModelList)
assert len(el.append_nil) == 2
assert el.append_nil[0] is None
assert isinstance(el.append_nil[1], EnclosedFixture)
assert el.append_nil[1].text == 'test2'
示例10: test_load_element_map_value_type
# 需要导入模块: from scap.Model import Model [as 别名]
# 或者: from scap.Model.Model import load [as 别名]
def test_load_element_map_value_type():
el = Model.load(None, ET.fromstring('''
<test:MapElementFixture xmlns:test="http://jaymes.biz/test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<test:map_value_type id="test1">test1</test:map_value_type>
<test:map_value_type id="test2">test2</test:map_value_type>
</test:MapElementFixture>
'''))
assert isinstance(el, MapElementFixture)
assert hasattr(el, 'map_value_type')
assert len(el.map_value_type) == 2
assert 'test1' in el.map_value_type
assert el.map_value_type['test1'] == 'test1'
assert 'test2' in el.map_value_type
assert el.map_value_type['test2'] == 'test2'
示例11: test_def
# 需要导入模块: from scap.Model import Model [as 别名]
# 或者: from scap.Model.Model import load [as 别名]
def test_def():
test_xml = '''<?xml version="1.0" encoding="UTF-8"?>
<oval_definitions
xmlns:unix-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#unix"
xmlns:ind-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent"
xmlns:lin-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux"
xmlns:oval="http://oval.mitre.org/XMLSchema/oval-common-5"
xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<generator>
<oval:product_name>Text Editors</oval:product_name>
<oval:schema_version>5.8</oval:schema_version>
<oval:timestamp>2013-12-17T12:00:00-04:00</oval:timestamp>
</generator>
<definitions>
<definition class="compliance" id="oval:gov.nist.usgcb.rhel:def:20000" version="2">
<metadata>
<title>Ensure that /tmp has its own partition or logical volume</title>
<description>The /tmp directory is a world-writable directory used for temporary file storage. Verify that it has its own partition or logical volume.</description>
</metadata>
<criteria>
<!-- <criterion test_ref="oval:gov.nist.usgcb.rhel:tst:20000" comment="Check in /etc/fstab for a /tmp mount point"/> -->
<criterion test_ref="oval:gov.nist.usgcb.rhel:tst:2000000" comment="Check if /tmp partition exists"/>
</criteria>
</definition>
</definitions>
<tests>
<lin-def:partition_test id="oval:gov.nist.usgcb.rhel:tst:2000000" comment="Check if /tmp partition exists" check_existence="at_least_one_exists" check="at least one" version="1">
<lin-def:object object_ref="oval:gov.nist.usgcb.rhel:obj:144120"/>
</lin-def:partition_test>
</tests>
<objects>
<lin-def:partition_object version="1" id="oval:gov.nist.usgcb.rhel:obj:144120">
<lin-def:mount_point>/tmp</lin-def:mount_point>
</lin-def:partition_object>
</objects>
<states>
</states>
<variables>
</variables>
</oval_definitions>'''
model = Model.load(None, ET.fromstring(test_xml))
from scap.model.oval_5.defs.OvalDefinitionsElement import OvalDefinitionsElement
assert isinstance(model, OvalDefinitionsElement)
示例12: test_load_element_append_class
# 需要导入模块: from scap.Model import Model [as 别名]
# 或者: from scap.Model.Model import load [as 别名]
def test_load_element_append_class():
el = Model.load(None, ET.fromstring('''
<test:AppendElementFixture xmlns:test="http://jaymes.biz/test">
<test:append_class>test1</test:append_class>
<test:append_class>test2</test:append_class>
</test:AppendElementFixture>
'''))
assert isinstance(el, AppendElementFixture)
assert hasattr(el, 'append_class')
assert isinstance(el.append_class, ModelList)
assert len(el.append_class) == 2
assert isinstance(el.append_class[0], EnclosedFixture)
assert el.append_class[0].text == 'test1'
assert isinstance(el.append_class[1], EnclosedFixture)
assert el.append_class[1].text == 'test2'
示例13: test_load_element_append_type
# 需要导入模块: from scap.Model import Model [as 别名]
# 或者: from scap.Model.Model import load [as 别名]
def test_load_element_append_type():
el = Model.load(None, ET.fromstring('''
<test:AppendElementFixture xmlns:test="http://jaymes.biz/test">
<test:append_type>1.1</test:append_type>
<test:append_type>1.2</test:append_type>
</test:AppendElementFixture>
'''))
assert isinstance(el, AppendElementFixture)
assert hasattr(el, 'append_type')
assert isinstance(el.append_type, ModelList)
assert len(el.append_type) == 2
assert isinstance(el.append_type[0], float)
assert el.append_type[0] == 1.1
assert isinstance(el.append_type[1], float)
assert el.append_type[1] == 1.2
示例14: test_in_and_out
# 需要导入模块: from scap.Model import Model [as 别名]
# 或者: from scap.Model.Model import load [as 别名]
def test_in_and_out():
test_xml = b'<test:InitFixture xmlns:test="http://jaymes.biz/test" xmlns:test2="http://jaymes.biz/test2">' + \
b'<test:list id="test1" />' + \
b'<test:list id="test2" />' + \
b'<test:list id="test3" />' + \
b'<test:dict id="test4" />' + \
b'<test:dict id="test5" />' + \
b'<test:dict id="test6" />' + \
b'<test:dict id="test7" />' + \
b'<test:dict id="test8" />' + \
b'<test:in_test id="test9" />' + \
b'<test:dash-test id="test10" />' + \
b'<test2:wildcard_element id="test11" />' + \
b'<test:wildcard_element id="test12" />' + \
b'<test:dict id="test13" />' + \
b'<test:list id="test14" />' + \
b'</test:InitFixture>'
model = Model.load(None, ET.fromstring(test_xml))
out_xml = ET.tostring(model.to_xml())
print(test_xml)
print(out_xml)
assert out_xml == test_xml
示例15: test_load_element_map_value_class
# 需要导入模块: from scap.Model import Model [as 别名]
# 或者: from scap.Model.Model import load [as 别名]
def test_load_element_map_value_class():
el = Model.load(None, ET.fromstring('''
<test:MapElementFixture xmlns:test="http://jaymes.biz/test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<test:map_value_class id="test1" tag="blue">text1</test:map_value_class>
<test:map_value_class id="test2" tag="red">text2</test:map_value_class>
</test:MapElementFixture>
'''))
assert isinstance(el, MapElementFixture)
assert hasattr(el, 'map_value_class')
assert len(el.map_value_class) == 2
assert 'test1' in el.map_value_class
assert isinstance(el.map_value_class['test1'], MappableElementFixture)
assert el.map_value_class['test1'].id == 'test1'
assert el.map_value_class['test1'].tag == 'blue'
assert el.map_value_class['test1'].text == 'text1'
assert 'test2' in el.map_value_class
assert isinstance(el.map_value_class['test2'], MappableElementFixture)
assert el.map_value_class['test2'].id == 'test2'
assert el.map_value_class['test2'].tag == 'red'
assert el.map_value_class['test2'].text == 'text2'