本文整理汇总了Python中helpers.XProtoTestHelpers类的典型用法代码示例。如果您正苦于以下问题:Python XProtoTestHelpers类的具体用法?Python XProtoTestHelpers怎么用?Python XProtoTestHelpers使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XProtoTestHelpers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_field_graph
def test_field_graph(self):
xproto = \
"""
message VRouterDevice (PlCoreBase){
optional string name = 1 [help_text = "device friendly name", max_length = 20, null = True, db_index = False, blank = True, unique_with="openflow_id"];
required string openflow_id = 2 [help_text = "device identifier in ONOS", max_length = 20, null = False, db_index = False, blank = False, unique_with="name"];
required string config_key = 3 [default = "basic", max_length = 32, blank = False, help_text = "configuration key", null = False, db_index = False, unique_with="driver"];
required string driver = 4 [help_text = "driver type", max_length = 32, null = False, db_index = False, blank = False, unique_with="vrouter_service"];
required manytoone vrouter_service->VRouterService:devices = 5 [db_index = True, null = False, blank = False];
required string A = 6 [unique_with="B"];
required string B = 7 [unique_with="C"];
required string C = 8 [unique_with="A"];
required string D = 9;
required string E = 10 [unique_with="F,G"];
required string F = 11;
required string G = 12;
}
"""
target = XProtoTestHelpers.write_tmp_target(
"""
{{ xproto_field_graph_components(proto.messages.0.fields) }}
""")
args = FakeArgs()
args.inputs = xproto
args.target = target
output = XOSGenerator.generate(args)
output = eval(output)
self.assertIn({'A','B','C'}, output)
self.assertIn({'openflow_id','name'}, output)
self.assertIn({'config_key','vrouter_service','driver'}, output)
self.assertIn({'E','F','G'}, output)
union = reduce(lambda acc,x: acc | x, output)
self.assertNotIn('D', union)
示例2: _test_field_graph
def _test_field_graph(self):
xproto = """
message VRouterDevice (PlCoreBase){
optional string name = 1 [help_text = "device friendly name", max_length = 20, null = True, db_index = False, blank = True, unique_with="openflow_id"];
required string openflow_id = 2 [help_text = "device identifier in ONOS", max_length = 20, null = False, db_index = False, blank = False, unique_with="name"];
required string config_key = 3 [default = "basic", max_length = 32, blank = False, help_text = "configuration key", null = False, db_index = False, unique_with="driver"];
required string driver = 4 [help_text = "driver type", max_length = 32, null = False, db_index = False, blank = False, unique_with="vrouter_service"];
required manytoone vrouter_service->VRouterService:devices = 5 [db_index = True, null = False, blank = False];
required string A = 6 [unique_with="B"];
required string B = 7 [unique_with="C"];
required string C = 8 [unique_with="A"];
required string D = 9;
required string E = 10 [unique_with="F,G"];
required string F = 11;
required string G = 12;
}
"""
target = XProtoTestHelpers.write_tmp_target(
"""
{{ xproto_field_graph_components(proto.messages.0.fields, proto.messages.0) }}
"""
)
args = XOSProcessorArgs(inputs=xproto, target=target)
output = XOSProcessor.process(args)
output = eval(output)
self.assertIn({"A", "B", "C"}, output)
self.assertIn({"openflow_id", "name"}, output)
self.assertIn({"config_key", "vrouter_service", "driver"}, output)
self.assertIn({"E", "F", "G"}, output)
union = reduce(lambda acc, x: acc | x, output)
self.assertNotIn("D", union)
示例3: test_missing_field
def test_missing_field(self):
xproto = \
"""
message VRouterDevice (PlCoreBase){
optional string name = 1 [help_text = "device friendly name", max_length = 20, null = True, db_index = False, blank = True, unique_with="hamburger"];
required string openflow_id = 2 [help_text = "device identifier in ONOS", max_length = 20, null = False, db_index = False, blank = False, unique_with="name"];
required string config_key = 3 [default = "basic", max_length = 32, blank = False, help_text = "configuration key", null = False, db_index = False, unique_with="driver"];
required string driver = 4 [help_text = "driver type", max_length = 32, null = False, db_index = False, blank = False, unique_with="vrouter_service"];
required manytoone vrouter_service->VRouterService:devices = 5 [db_index = True, null = False, blank = False];
required string A = 6 [unique_with="B"];
required string B = 7 [unique_with="C"];
required string C = 8 [unique_with="A"];
required string D = 9;
}
"""
target = XProtoTestHelpers.write_tmp_target(
"""
{{ xproto_field_graph_components(proto.messages.0.fields) }}
""")
def generate():
args = FakeArgs()
args.inputs = xproto
args.target = target
output = XOSGenerator.generate(args)
# The following call generates some output, which should disappear
# when Matteo merges his refactoring of XOSGenerator.
self.assertRaises(FieldNotFound, generate)
示例4: test_singularize
def test_singularize(self):
proto = \
"""
message TestSingularize {
// The following field has an explicitly specified singular
required int many = 1 [singular = "one"];
// The following fields have automatically computed singulars
required int sheep = 2;
required int radii = 2;
required int slices = 2;
required int networks = 2;
required int omf_friendlies = 2;
}
"""
target = XProtoTestHelpers.write_tmp_target(
"""
{% for m in proto.messages.0.fields -%}
{{ xproto_singularize(m) }},
{%- endfor %}
""")
args = FakeArgs()
args.inputs = proto
args.target = target
output = XOSGenerator.generate(args)
self.assertEqual("one,sheep,radius,slice,network,omf_friendly", output.lstrip().rstrip().rstrip(','))
示例5: test_pure_policies
def test_pure_policies(self):
xproto = """
policy my_policy < exists x:a=b >
"""
proto = """
option my_policy = "policy:< exists x:a=b >";
"""
target = XProtoTestHelpers.write_tmp_target(
"""
{{ policies }}
"""
)
args_xproto = XOSProcessorArgs()
args_xproto.inputs = xproto
args_xproto.target = target
xproto_gen = XOSProcessor.process(args_xproto)
args_proto = XOSProcessorArgs()
args_proto.inputs = proto
args_proto.target = target
args_proto.rev = True
proto_gen = XOSProcessor.process(args_proto)
self.assertEqual(proto_gen, xproto_gen)
示例6: test_pluralize
def test_pluralize(self):
proto = \
"""
message TestPluralize {
// The following field has an explicitly specified plural
required int anecdote = 1 [plural = "data"];
// The following fields have automatically computed plurals
required int sheep = 2;
required int radius = 2;
required int slice = 2;
required int network = 2;
required int omf_friendly = 2;
}
"""
target = XProtoTestHelpers.write_tmp_target(
"""
{% for m in proto.messages.0.fields -%}
{{ xproto_pluralize(m) }},
{%- endfor %}
""")
args = FakeArgs()
args.inputs = proto
args.target = target
output = XOSGenerator.generate(args)
self.assertEqual("data,sheep,radii,slices,networks,omf_friendlies", output.lstrip().rstrip().rstrip(','))
示例7: test_basic_proto
def test_basic_proto(self):
xtarget = XProtoTestHelpers.write_tmp_target("{{ proto }}")
xproto = """
message Person {
required string name = 1;
required int32 id = 2; // Unique ID number for this person.
optional string email = 3 [symphony = "da da da dum"];
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
required string number = 1;
optional PhoneType type = 2;
repeated PhoneNumber phones = 4;
}
"""
args = XOSProcessorArgs()
args.inputs = xproto
args.target = xtarget
output = XOSProcessor.process(args)
self.assertIn("PhoneNumber", output)
示例8: test_package_fqn
def test_package_fqn(self):
args = XOSProcessorArgs()
target = XProtoTestHelpers.write_tmp_target(
"""
{% for m in proto.messages %}
{{ m.name }},{{ m.package }},{{ m.fqn }}
{% endfor %}
"""
)
xproto = """
package xos.core;
message Port (PlCoreBase,ParameterMixin) {
required manytoone network->Network:links = 1 [db_index = True, null = False, blank = False];
optional manytoone instance->Instance:ports = 2 [db_index = True, null = True, blank = True];
optional string ip = 3 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
optional string port_id = 4 [help_text = "Neutron port id", max_length = 256, null = True, db_index = False, blank = True];
optional string mac = 5 [help_text = "MAC address associated with this port", max_length = 256, null = True, db_index = False, blank = True];
required bool xos_created = 6 [default = False, null = False, db_index = False, blank = True];
}
"""
args = XOSProcessorArgs()
args.inputs = xproto
args.target = target
output = XOSProcessor.process(args)
self.assertIn("Port,xos.core,xos.core.Port", output)
示例9: setUp
def setUp(self):
self.target = XProtoTestHelpers.write_tmp_target(
"""
{% for name, policy in proto.policies.items() %}
{{ xproto_fol_to_python_test(name, policy, None, '0') }}
{% endfor %}
"""
)
示例10: setUp
def setUp(self):
self.target_tosca_keys = XProtoTestHelpers.write_tmp_target(
"""
{%- for m in proto.messages %}
{{ xproto_fields_to_tosca_keys(m.fields, m) }}
{% endfor -%}
"""
)
示例11: setUp
def setUp(self):
self.target = XProtoTestHelpers.write_tmp_target(
"""
{% for name, policy in proto.policies.items() %}
{{ xproto_fol_to_python_validator(name, policy, None, 'Necessary Failure') }}
{% endfor %}
"""
)
示例12: test_base_class_fields
def test_base_class_fields(self):
target = XProtoTestHelpers.write_tmp_target(
"""
{% for m in proto.messages %}
{{ m.name }} {
{%- for b in m.bases %}
{%- if proto.message_table[b.fqn] -%}
{%- set model = proto.message_table[b.fqn] %}
{% for f in model.fields %}
{{ f.type }} {{ f.name }};
{% endfor %}
{%- endif -%}
{% endfor %}
}
{% endfor %}
"""
)
xproto = """
package xos.network;
message Port (PlCoreBase,ParameterMixin){
required manytoone network->Network:links = 1 [db_index = True, null = False, blank = False];
optional manytoone instance->Instance:ports = 2 [db_index = True, null = True, blank = True];
optional string ip = 3 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
optional string port_id = 4 [help_text = "Neutron port id", max_length = 256, null = True, db_index = False, blank = True];
optional string mac = 5 [help_text = "MAC address associated with this port", max_length = 256, null = True, db_index = False, blank = True];
required bool xos_created = 6 [default = False, null = False, db_index = False, blank = True];
}
package xos.someotherpackage;
message Instance (xos.network.Port){
optional string instance_id = 1 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance id", null = True, db_index = False];
optional string instance_uuid = 2 [max_length = 200, content_type = "stripped", blank = True, help_text = "Nova instance uuid", null = True, db_index = False];
required string name = 3 [max_length = 200, content_type = "stripped", blank = False, help_text = "Instance name", null = False, db_index = False];
optional string instance_name = 4 [max_length = 200, content_type = "stripped", blank = True, help_text = "OpenStack generated name", null = True, db_index = False];
optional string ip = 5 [max_length = 39, content_type = "ip", blank = True, help_text = "Instance ip address", null = True, db_index = False];
required manytoone image->Image:instances = 6 [db_index = True, null = False, blank = False];
optional manytoone creator->User:instances = 7 [db_index = True, null = True, blank = True];
required manytoone slice->Slice:instances = 8 [db_index = True, null = False, blank = False];
required manytoone deployment->Deployment:instance_deployment = 9 [db_index = True, null = False, blank = False];
required manytoone node->Node:instances = 10 [db_index = True, null = False, blank = False];
required int32 numberCores = 11 [help_text = "Number of cores for instance", default = 0, null = False, db_index = False, blank = False];
required manytoone flavor->Flavor:instance = 12 [help_text = "Flavor of this instance", default = "get_default_flavor()", null = False, db_index = True, blank = False];
optional string userData = 13 [help_text = "user_data passed to instance during creation", null = True, db_index = False, blank = True];
required string isolation = 14 [default = "vm", choices = "(('vm', 'Virtual Machine'), ('container', 'Container'), ('container_vm', 'Container In VM'))", max_length = 30, blank = False, null = False, db_index = False];
optional string volumes = 15 [help_text = "Comma-separated list of directories to expose to parent context", null = True, db_index = False, blank = True];
optional manytoone parent->Instance:instance = 16 [help_text = "Parent Instance for containers nested inside of VMs", null = True, db_index = True, blank = True];
required manytomany tags->Tag = 17 [db_index = False, null = False, blank = True];
}
"""
args = XOSProcessorArgs()
args.inputs = xproto
args.target = target
output = XOSProcessor.process(args)
self.assertIn("xos_created", output)
示例13: test_xproto_lib
def test_xproto_lib(self):
target = XProtoTestHelpers.write_tmp_target(
"""
{{ xproto_first_non_empty([None, None, None, None, None, None, "Eureka"]) }}
""")
args = FakeArgs()
args.inputs = ''
args.target = target
output = XOSGenerator.generate(args)
self.assertIn("Eureka", output)
示例14: test_xproto_lib
def test_xproto_lib(self):
target = XProtoTestHelpers.write_tmp_target(
"""
{{ xproto_first_non_empty([None, None, None, None, None, None, "Eureka"]) }}
"""
)
args = XOSProcessorArgs()
args.inputs = ""
args.target = target
output = XOSProcessor.process(args)
self.assertIn("Eureka", output)
示例15: test_context
def test_context(self):
target = XProtoTestHelpers.write_tmp_target(
"""
{{ context.what }}
""")
args = FakeArgs()
args.inputs = ''
args.target = target
args.kv='what:what is what'
output = XOSGenerator.generate(args)
self.assertIn("what is what", output)