Esempio n. 1
0
def test_add_block():
    '''
    Add a basic empty block to the plog.blocks
    '''
    plog = Plog()
    block = PlogBlock()
    plog.add_block(block)
    assert len(plog.blocks) == 1
Esempio n. 2
0
def test_add_block_string():
    '''
    Add a plog block as as a string. This is converted to conform
    into a plog.line for a plog.block
    '''
    plog = Plog()
    plog.add_block('Device')
    assert len(plog.blocks) == 1
Esempio n. 3
0
def test_add_block_string():
    '''
    Add a plog block as as a string. This is converted to conform
    into a plog.line for a plog.block
    '''
    plog = Plog()
    plog.add_block('Device')
    assert len(plog.blocks) == 1
Esempio n. 4
0
def test_add_block():
    '''
    Add a basic empty block to the plog.blocks
    '''
    plog = Plog()
    block = PlogBlock()
    plog.add_block(block)
    assert len(plog.blocks) == 1
Esempio n. 5
0
def test_add_string():
    CDP_DATA = '''
    Device ID: SEP001F9EAB59F1
    Entry address(es):
      IP address: 10.243.14.48
    Platform: Cisco IP Phone 7941,  Capabilities: Host Phone
    Interface: FastEthernet0/15,  Port ID (outgoing port): Port 1
    Holdtime : 124 sec
    '''
    plog = Plog(CDP_DATA)
    assert plog.get_file()
Esempio n. 6
0
def test_add_string():
    CDP_DATA = '''
    Device ID: SEP001F9EAB59F1
    Entry address(es):
      IP address: 10.243.14.48
    Platform: Cisco IP Phone 7941,  Capabilities: Host Phone
    Interface: FastEthernet0/15,  Port ID (outgoing port): Port 1
    Holdtime : 124 sec
    '''
    plog = Plog(CDP_DATA)
    assert plog.get_file()
Esempio n. 7
0
def test_enumerate():
    '''
    Check to ensure the enumeration of a file or string 
    is exaclty the length of lines for the supplied.
    '''

    CDP_DATA = '''Device ID: SEP001F9EAB59F1
    Entry address(es):
      IP address: 10.243.14.48
    Platform: Cisco IP Phone 7941,  Capabilities: Host Phone
    Interface: FastEthernet0/15,  Port ID (outgoing port): Port 1
    Holdtime : 124 sec'''
    plog = Plog(CDP_DATA)
    plog._c = 0
    def counts(line, line_no):
        plog._c = plog._c + 1

    plog.run(counts)
    assert plog._c == 6
Esempio n. 8
0
def test_enumerate():
    '''
    Check to ensure the enumeration of a file or string 
    is exaclty the length of lines for the supplied.
    '''

    CDP_DATA = '''Device ID: SEP001F9EAB59F1
    Entry address(es):
      IP address: 10.243.14.48
    Platform: Cisco IP Phone 7941,  Capabilities: Host Phone
    Interface: FastEthernet0/15,  Port ID (outgoing port): Port 1
    Holdtime : 124 sec'''
    plog = Plog(CDP_DATA)
    plog._c = 0

    def counts(line, line_no):
        plog._c = plog._c + 1

    plog.run(counts)
    assert plog._c == 6
Esempio n. 9
0
block = PlogBlock('Device ID:', ref='Device')
block.header.ref = 'device_id'
block.footer = PlogLine('----------', ref='footer').anything()

lines = {}
lines['entry_address'] = PlogLine('IP address:')
lines['platform'] = PlogLine('Platform:')
lines['interface'] = PlogLine('Interface:')
lines['hold_time'] = PlogLine('Holdtime').maybe(' ').then(':')
lines['version'] = PlogLine('Version').maybe(' ').then(':').multiline()
lines['version'] = PlogLine('advertisement version:')
lines['duplex'] = PlogLine('Duplex:')
lines['power_drawn'] = PlogLine('Power drawn:')
lines['power_request_id'] = PlogLine('Power request id:')
lines['power_management_id'] = PlogLine('Power management id:')
lines['power_request_levels'] = PlogLine('Power request levels are:')
block.add_lines(**lines)

# new parser
f = open('test_data2.txt', 'r')
# plog = Plog(f, whitespace='|')
plog = Plog(f, whitespace='|', terminator=',')

# run it
plog.add_block(block)
blocks = plog.run()

for block in blocks:
    if block.valid():
        print block.as_dict()
Esempio n. 10
0
def test_file_on_init():
    f = open('file')
    plog = Plog(f)
    assert plog.get_file() == f
    assert plog.get_data() == f
Esempio n. 11
0
def test_add_file():
    f = open('file')
    plog = Plog()
    plog.set_file(f)
    assert plog.get_file() == f
    assert plog.get_data() == f
Esempio n. 12
0
from api import Plog
from patterns import PlogLine, PlogBlock

f = open('test_data2.txt', 'r')
# Capture something
block = PlogBlock('Device ID:', ref='Device')
block.header.ref = 'device_id'
block.footer = PlogLine('----------', ref='footer').anything()

# new parser
plog = Plog(f, whitespace='|')
# run it
plog.add_block(block)
blocks = plog.run()

for block in blocks:
    if block.valid():
        print block.as_dict()
Esempio n. 13
0

#
block = PlogBlock('Device ID:', ref='Device')
block.header.ref='device_id'

block.footer = PlogLine('----------', ref='footer').anything()

lines = {}
lines['entry_address'] = PlogLine('IP address:')
lines['platform'] = PlogLine('Platform:')
lines['interface'] = PlogLine('Interface:')
lines['hold_time'] = PlogLine('Holdtime').maybe(' ').then(':')
lines['version'] = PlogLine('Version').maybe(' ').then(':').multiline()
lines['ad_version'] = PlogLine('advertisement version:')

block.add_lines(**lines)


# new parser
f = open('test_data2.txt', 'r')
plog = Plog(f, whitespace='|')
# run it
plog.add_block(block)
blocks = plog.run()

for block in blocks:
	if block.valid():
		print block.as_dict()

Esempio n. 14
0
from pprint import pprint
from api import Plog
from patterns import PlogLine, PlogBlock
from blocks import CDPBlock

f = open('test_data2.txt', 'r')
plog = Plog(f, whitespace='|', terminator=',')
# import pdb; pdb.set_trace()
plog.add_blocks(CDPBlock)
plog.run()

for block in plog.data_blocks:
    if block.valid():
        d = block.as_dict()
        print d

import pdb
pdb.set_trace()
Esempio n. 15
0
def test_file_on_init():
    f = open('file')
    plog = Plog(f)
    assert plog.get_file() == f
    assert plog.get_data() == f
Esempio n. 16
0
def test_add_file():
    f = open('file')
    plog = Plog()
    plog.set_file(f)
    assert plog.get_file() == f
    assert plog.get_data() == f