def testParseFSMState(self):

    f = cStringIO.StringIO('Value Beer (.)\nValue Wine (\w)\n\nStart\n')
    t = textfsm.TextFSM(f)

    # Fails as we already have 'Start' state.
    buf = 'Start\n  ^.\n'
    f = cStringIO.StringIO(buf)
    self.failUnlessRaises(textfsm.TextFSMTemplateError, t._ParseFSMState, f)

    # Remove start so we can test new Start state.
    t.states = {}

    # Single state.
    buf = '# Headline\nStart\n  ^.\n\n'
    f = cStringIO.StringIO(buf)
    t._ParseFSMState(f)
    self.failUnless(t.states['Start'])
    self.failUnlessEqual(str(t.states['Start'][0]), '  ^.')
    try:
      _ = t.states['Start'][1]
    except __HOLE__:
      pass

    # Multiple states.
    buf = '# Headline\nStart\n  ^.\n  ^Hello World\n  ^Last-[Cc]ha$$nge\n'
    f = cStringIO.StringIO(buf)
    t._line_num = 0
    t.states = {}
    t._ParseFSMState(f)
    self.failUnlessEqual(str(t.states['Start'][0]), '  ^.')
    self.failUnlessEqual(str(t.states['Start'][1]), '  ^Hello World')
    self.failUnlessEqual(t.states['Start'][1].line_num, 4)
    self.failUnlessEqual(str(t.states['Start'][2]), '  ^Last-[Cc]ha$$nge')
    try:
      _ = t.states['Start'][3]
    except IndexError:
      pass

    t.states = {}
    # Malformed states.
    buf = 'St%art\n  ^.\n  ^Hello World\n'
    f = cStringIO.StringIO(buf)
    self.failUnlessRaises(textfsm.TextFSMTemplateError, t._ParseFSMState, f)

    buf = 'Start\n^.\n  ^Hello World\n'
    f = cStringIO.StringIO(buf)
    self.failUnlessRaises(textfsm.TextFSMTemplateError, t._ParseFSMState, f)

    buf = '  Start\n  ^.\n  ^Hello World\n'
    f = cStringIO.StringIO(buf)
    self.failUnlessRaises(textfsm.TextFSMTemplateError, t._ParseFSMState, f)

    # Multiple variables and substitution (depends on _ParseFSMVariables).
    buf = ('# Headline\nStart\n  ^.${Beer}${Wine}.\n'
           '  ^Hello $Beer\n  ^Last-[Cc]ha$$nge\n')
    f = cStringIO.StringIO(buf)
    t.states = {}
    t._ParseFSMState(f)
    self.failUnlessEqual(str(t.states['Start'][0]),
                         '  ^.${Beer}${Wine}.')
    self.failUnlessEqual(str(t.states['Start'][1]), '  ^Hello $Beer')
    self.failUnlessEqual(str(t.states['Start'][2]), '  ^Last-[Cc]ha$$nge')
    try:
      _ = t.states['Start'][3]
    except IndexError:
      pass

    t.states['bogus'] = []

    # State name too long (>32 char).
    buf = 'nametoolong_nametoolong_nametoolong_nametoolong_nametoolo\n  ^.\n\n'
    f = cStringIO.StringIO(buf)
    self.failUnlessRaises(textfsm.TextFSMTemplateError, t._ParseFSMState, f)
dataset/ETHPy150Open google/textfsm/textfsm_test.py/UnitTestFSM.testParseFSMState