How to use ttp - 10 common examples

To help you get started, we’ve selected a few ttp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dmulyalin / ttp / test / pytest / test_group_chain_attribute.py View on Github external
def test_macro3(data):
    data["test_macro3"] = "DONE"
    return data
	
def test_macro4(data):
    data["test_macro4"] = "DONE"
    return data



interface {{ interface }}
  vlan {{ vlan | to_int }}
  description {{ description | ORPHRASE }}

"""
    parser = ttp(template=template_1)
    parser.parse()
    res = parser.result()
    # pprint.pprint(res)
    assert res == [[[{'description': 'test loopback0',
                      'interface': 'Loopback0',
                      'set_key': 'set_value',
                      'test_macro': 'DONE',
                      'test_macro1': 'DONE',
                      'test_macro2': 'DONE',
                      'test_macro3': 'DONE',
                      'test_macro4': 'DONE'},
                     {'description': 'test loopback1',
                      'interface': 'Loopback1',
                      'set_key': 'set_value',
                      'test_macro': 'DONE',
                      'test_macro1': 'DONE',
github dmulyalin / ttp / test / pytest / test_group_chain_attribute.py View on Github external
def test_macro(data):
    data["test_macro"] = "DONE"
    return data
	
def test_macro1(data):
    data["test_macro1"] = "DONE"
    return data



interface {{ interface }}
  vlan {{ vlan | to_int }}
  description {{ description | ORPHRASE }}

"""
    parser = ttp(template=template_1)
    parser.parse()
    res = parser.result()
    # pprint.pprint(res)
    assert res == [[[{'description': 'test loopback0',
                      'interface': 'Loopback0',
                      'set_key': 'set_value',
                      'test_macro': 'DONE',
                      'test_macro1': 'DONE'},
                     {'description': 'test loopback1',
                      'interface': 'Loopback1',
                      'set_key': 'set_value',
                      'test_macro': 'DONE',
                      'test_macro1': 'DONE'}]]]
github dmulyalin / ttp / test / pytest / test_anonymous_template.py View on Github external
def test_simple_anonymous_template():
    parser = ttp(template=template_1, data=data_1)
    # check that data added:
    datums_added = {"{}:{}".format(template.name, input_name): input_obj.data for template in parser._templates for input_name, input_obj in template.inputs.items()}
    # pprint.pprint(datums_added)
    parser.parse()
    res = parser.result()
    assert res == [[[{'description': 'Storage Management', 'interface': 'Port-Chanel11'}, {'description': 'RID', 'interface': 'Loopback0'}]]]
github dmulyalin / ttp / test / pytest / test_ttp_parser_methods.py View on Github external
data_2 = """
interface Lo2
 ip address 124.171.238.22 32
!
interface Lo3
 description this interface has description
 ip address 2.2.2.2 32    
"""
    template_1 = """

interface {{ interface }}
 description {{ description | ORPHRASE }}
 ip address {{ ip }} {{ mask }}
    
"""
    parser = ttp(template=template_1)
    parser.add_input(data_1, input_name='Default_Input', template_name="_root_template_", groups=['all'])
    parser.add_input(data_2, input_name='Default_Input', template_name="does_not_exists", groups=['all'])
    # check that data added:
    datums_added = {"{}:{}".format(template.name, input_name): input_obj.data for template in parser._templates for input_name, input_obj in template.inputs.items()}
    # pprint.pprint(datums_added)
    assert datums_added == {'_root_template_:Default_Input': [('text_data',
                                                               '\n'
                                                               'interface Lo0\n'
                                                               ' ip address 124.171.238.50 32\n'
                                                               '!\n'
                                                               'interface Lo1\n'
                                                               ' description this interface has '
                                                               'description\n'
                                                               ' ip address 1.1.1.1 32    \n')]}
    parser.parse()
    res = parser.result()
github dmulyalin / ttp / test / pytest / test_ttp_parser_methods.py View on Github external
interface {{ interface }}
 description {{ description | ORPHRASE }}
 ip address {{ ip }} {{ mask }}
    


<template name="template_2">

interface {{ interface }}
 description {{ description | ORPHRASE }}
 ip address {{ ip }} {{ mask }}
    
</template>
"""
    parser = ttp(template=template_1)
    parser.add_input(data_1, input_name='Default_Input', template_name="template_1", groups=['all'])
    parser.add_input(data_2, input_name='Default_Input', template_name="template_2", groups=['all'])
    parser.add_input(data_3, input_name='Default_Input', template_name="template_2", groups=['all'])
    # check that data added:
    datums_added = {"{}:{}".format(template.name, input_name): input_obj.data for template in parser._templates for input_name, input_obj in template.inputs.items()}
    # pprint.pprint(datums_added)
    assert datums_added == {'template_1:Default_Input': [('text_data',
                                                          '\n'
                                                          'interface Lo0\n'
                                                          ' ip address 124.171.238.50 32\n'
                                                          '!\n'
                                                          'interface Lo1\n'
                                                          ' description this interface has description\n'
                                                          ' ip address 1.1.1.1 32    \n')],
                            'template_2:Default_Input': [('text_data',
                                                          '\n'
github dmulyalin / ttp / test / pytest / test_headers_indicator.py View on Github external
Gi0/15                       connected    trunk        full   1000 1000BaseLX SFP
Gi0/16    pitrs2201 te1/1/4  connected    trunk        full   1000  1000BaseLX SFP



Port      Name               Status       Vlan       Duplex  Speed Type   {{ _headers_ }}
   


def clean_up(data):
    if "----" in data["Port"]:
        return False
    return True

"""
    parser = ttp(template=template, log_level="ERROR")
    parser.parse()
    # res = parser.result(format="tabulate")[0]
    # print(res)
    res = parser.result()
    # pprint.pprint(res)
    assert res == [[[{'Duplex': 'a-full',
    'Name': 'PIT-VDU213',
    'Port': 'Gi0/1',
    'Speed': 'a-100',
    'Status': 'connected',
    'Type': '10/100/1000BaseTX',
    'Vlan': '18'},
   {'Duplex': 'a-full',
    'Name': 'PIT-VDU211',
    'Port': 'Gi0/2',
    'Speed': 'a-100',
github dmulyalin / ttp / test / pytest / test_ttp_parser_methods.py View on Github external
data_2 = """
interface Lo2
 ip address 124.171.238.22 32
!
interface Lo3
 description this interface has description
 ip address 2.2.2.2 32    
"""
    template_1 = """

interface {{ interface }}
 description {{ description | ORPHRASE }}
 ip address {{ ip }} {{ mask }}
    
"""
    parser = ttp(template=template_1)
    parser.add_input(data_1, input_name='Default_Input', template_name="_root_template_", groups=['all'])
    parser.add_input(data_2, input_name='Default_Input', template_name="_root_template_", groups=['all'])
    # check that data added:
    datums_added = {"{}:{}".format(template.name, input_name): input_obj.data for template in parser._templates for input_name, input_obj in template.inputs.items()}
    # pprint.pprint(datums_added)
    assert datums_added == {'_root_template_:Default_Input': [('text_data',
                                                               '\n'
                                                               'interface Lo0\n'
                                                               ' ip address 124.171.238.50 32\n'
                                                               '!\n'
                                                               'interface Lo1\n'
                                                               ' description this interface has '
                                                               'description\n'
                                                               ' ip address 1.1.1.1 32    \n'),
                                                              ('text_data',
                                                               '\n'
github dmulyalin / ttp / test / pytest / test_ttp_parser_methods.py View on Github external
interface {{ interface }}
 description {{ description | ORPHRASE }}
 ip address {{ ip }} {{ mask }}
    


<template name="template_2">
<input name="input2">

interface {{ interface }}
 description {{ description | ORPHRASE }}
 ip address {{ ip }} {{ mask }}
    
</template>
"""
    parser = ttp(template=template_1)
    parser.add_input(data_1, input_name='input1', template_name="template_1", groups=['all'])
    parser.add_input(data_2, input_name='input2', template_name="template_2", groups=['all'])
    parser.add_input(data_3, input_name='input2', template_name="template_2", groups=['all'])
    # check that data added:
    datums_added = {"{}:{}".format(template.name, input_name): input_obj.data for template in parser._templates for input_name, input_obj in template.inputs.items()}   
    # pprint.pprint(datums_added)
    assert datums_added == {'template_1:input1': [('text_data',
                                                   '\n'
                                                   'interface Lo0\n'
                                                   ' ip address 124.171.238.50 32\n'
                                                   '!\n'
                                                   'interface Lo1\n'
                                                   ' description this interface has description\n'
                                                   ' ip address 1.1.1.1 32    \n')],
                            'template_2:input2': [('text_data',
                                                   '\n'
github edmondburnett / twitter-text-python / ttp / tests.py View on Github external
def setUp(self):
        self.parser = ttp.Parser(include_spans=True)