def test_This_is_how_you_collect_all_the_CSC_commands_and_get_info(self): interp = CmdInterp() contAny = ContAny() actionHello = ActionInsert("hello") contBlankLine = ContBlankLine() actionThere = ActionInsert("there") actionOtherwise = ActionInsert("there otherwise") interp.add_csc( CSCmd(spoken_forms=['hello'], meanings={contAny: actionHello}, docstring="hello")) interp.add_csc( CSCmd(spoken_forms=['there'], meanings={ contBlankLine: actionThere, contAny: actionOtherwise }, docstring="there on blankline or otherwise")) wTrie = interp.commands for spoken, cscmd_list in wTrie.items(): if spoken == ['hello']: cscmd_list_expected = [{ 'action': "Inserts 'hello^' in current buffer", 'doc': 'hello', 'equiv': 'Any', 'scope': 'global', 'setdescription': 'no description', 'setname': 'cscs' }] elif spoken == ['there']: cscmd_list_expected = [{ 'action': "Inserts 'there^' in current buffer", 'doc': 'there on blankline or otherwise', 'equiv': 'BlankLine: any', 'scope': 'immediate', 'setdescription': 'no description', 'setname': 'cscs' }, { 'action': "Inserts 'there otherwise^' in current buffer", 'doc': 'there on blankline or otherwise', 'equiv': 'Any', 'scope': 'global', 'setdescription': 'no description', 'setname': 'cscs' }] visible_list = cscmd_list.get_info() self.assert_equal( cscmd_list_expected, visible_list, 'wTrie CSCmdList of meanings with spoken form "%s" is not as expected' % repr(spoken))
def setUp(self): self.interp = CmdInterp() self.interp.add_csc( CSCmd(spoken_forms=csc_with_arguments_spoken_forms, meanings=csc_with_arguments_meanings, docstring=csc_with_arguments_docstring)) self.interp.add_csc( CSCmd(spoken_forms=csc_else_spoken_forms, meanings=csc_else_meanings, docstring=csc_else_docstring)) self.interp.add_csc( CSCmd(spoken_forms=csc_equals_spoken_forms, meanings=csc_equals_meanings, docstring=csc_equals_docstring))
def test_the_index_of_simple_csc_and_an_lsa_definition(self): wciSay = WhatCanISay.WhatCanISay() interp = CmdInterp() # do one csc and one lsa: interp.add_csc( CSCmd(["equals"], meanings={contAny: ActionInsert("====")}, name="equals csc")) interp.add_lsa( LSAlias(["plus"], meanings={all_languages: " + "}, name="plus sign")) wciSay.load_commands_from_interpreter(self._app(), interp, 'C') expected = \ {'C': {'equals': [[{'action': "Inserts '====^' in current buffer", 'doc': None, 'equiv': 'Any', 'scope': 'global', 'setdescription': 'no description', 'setname': 'cscs'}]], 'plus': [{'description': 'no description', 'name': 'plus sign', 'new_symbol': None, 'setname': 'lsas', 'spacing': 0, 'written_form': ' + '}]}} self.assert_equal( expected, wciSay.index, "index of one CSC and one LSA command is not as expected")
def test_Test_correct_order_of_CSCmdList1(self): interp = CmdInterp() actionHello = ActionInsert("csc hello") actionBlankLine = ActionInsert("csc blank") actionBeforeArguments = ActionInsert("csc before arguments") contBlankLine = ContBlankLine() contAny = ContAny() cscs = CSCmdSet('csc demo set', description='description of csc demo set') # test the sorting of the csc : cscs.add_csc( CSCmd(spoken_forms=['hello'], meanings={ ContBeforeArguments(all_languages): actionBeforeArguments, contAny: actionHello, contBlankLine: actionBlankLine }, docstring="hello in csc set testlist1")) interp.add_csc_set(cscs) wTrie = interp.commands for spoken, cscmd_list in wTrie.items(): if spoken == ['hello']: cscmd_list_expected = \ [{'action': "Inserts 'csc blank^' in current buffer", 'doc': 'hello in csc set testlist1', 'equiv': 'BlankLine: any', 'scope': 'immediate', 'setdescription': 'description of csc demo set', 'setname': 'csc demo set'}, {'action': "Inserts 'csc before arguments^' in current buffer", 'doc': 'hello in csc set testlist1', 'equiv': 'ContBeforeArguments: any', 'scope': 'immediate', 'setdescription': 'description of csc demo set', 'setname': 'csc demo set'}, {'action': "Inserts 'csc hello^' in current buffer", 'doc': 'hello in csc set testlist1', 'equiv': 'Any', 'scope': 'global', 'setdescription': 'description of csc demo set', 'setname': 'csc demo set'}] else: self.fail( "should not come here, testing error, should have exactly 1 spoken form" ) visible_list = cscmd_list.get_info() self.assert_equal( cscmd_list_expected, visible_list, 'wTrie CSCmdList of meanings with spoken form "%s" is not as expected' % repr(spoken)) break else: self.fail( "no spoken forms in test, should not come here, testing error, should have 1 spoken form" )
def test_the_index_of_a_cmdset_with_an_lsa_and_a_csc_in_it(self): wciSay = WhatCanISay.WhatCanISay() interp = CmdInterp() # the new CmdSet can contain both CSCs and LSAs... # do one csc and one lsa: cmds = CmdSet("commands set", description="generic commands set") cmds.add_lsa( LSAlias(["plus"], meanings={all_languages: " + "}, name="plus sign")) # without docstring: cmds.add_csc( CSCmd(["equals"], meanings={contAny: ActionInsert("====")})) # with docstring: cmds.add_csc( CSCmd(["not equal"], meanings={contAny: ActionInsert(" != ")}, docstring="csc not equal")) interp.add_cmd_set(cmds) wciSay.load_commands_from_interpreter(self._app(), interp, 'C') expected = \ {'C': {'equals': [[{'action': "Inserts '====^' in current buffer", 'doc': None, 'equiv': 'Any', 'scope': 'global', 'setdescription': 'generic commands set', 'setname': 'commands set'}]], 'not equal': [[{'action': "Inserts ' != ^' in current buffer", 'doc': 'csc not equal', 'equiv': 'Any', 'scope': 'global', 'setdescription': 'generic commands set', 'setname': 'commands set'}]], 'plus': [{'name': 'plus sign', 'new_symbol': None, 'setdescription': 'generic commands set', 'setname': 'commands set', 'spacing': 0, 'written_form': ' + '}]}} self.assert_equal( expected, wciSay.index, "index of one CSC and one LSA command is not as expected")
def test_This_is_how_you_create_a_CSCmd_instance(self): command1 = CSCmd(spoken_forms=['hello'], meanings={ 'python': ActionInsert('hello python'), 'C': ActionInsert('hello C') }) command2 = CSCmd(spoken_forms=['hello'], meanings={ contPython: ActionInsert('hello python'), contC: ActionInsert('hello C') }) command3 = CSCmd(spoken_forms=['hello'], meanings={ ContLanguage('python'): ActionInsert('hello python'), ContLanguage('C'): ActionInsert('hello C') }) self.assert_equal(command2, command1, \ "Csc commands 2 and 1 should have been the same with different ways to define") self.assert_equal(command3, command1, \ "Csc commands 3 and 1 should have been the same with different ways to define")
def test_This_is_how_you_create_a_WhatCanISay_instance(self): wciSay = WhatCanISay.WhatCanISay() interp = CmdInterp() # load one lsa and one csc: interp.add_csc( CSCmd(["equals"], meanings={contAny: ActionInsert("====")}, name="equals csc")) interp.add_lsa( LSAlias(["plus"], meanings={all_languages: " + "}, name="plus sign")) wciSay.load_commands_from_interpreter(self._app(), interp, 'C')
def test_This_is_how_you_enter_and_get_info_through_CSCmdSet(self): interp = CmdInterp() actionHello = ActionInsert("csc hello") contAny = ContAny() cscs = CSCmdSet('csc demo set', description='description of csc demo set') cscs.add_csc( CSCmd(spoken_forms=['hello'], meanings={contAny: actionHello}, docstring="hello in csc set")) interp.add_csc_set(cscs) wTrie = interp.commands for spoken, cscmd_list in wTrie.items(): if spoken == ['hello']: cscmd_list_expected = [{ 'action': "Inserts 'csc hello^' in current buffer", 'doc': 'hello in csc set', 'equiv': 'Any', 'scope': 'global', 'setdescription': 'description of csc demo set', 'setname': 'csc demo set' }] else: self.fail( "should not come here, testing error, should have exactly 1 spoken form" ) visible_list = cscmd_list.get_info() self.assert_equal( cscmd_list_expected, visible_list, 'wTrie CSCmdList of meanings with spoken form "%s" is not as expected' % repr(spoken)) break else: self.fail( "no spoken forms in test, should not come here, testing error, should have 1 spoken form" )
def test_the_index_of_c_else_with_different_csc_set_name_as_python_else( self): wciSay = WhatCanISay.WhatCanISay() interp = CmdInterp() # do a csc set for python and a csc set for c # note: for try all went well in C, except for the setname cscs1 = CSCmdSet('try command python', description='description of CSCS') cscs2 = CSCmdSet('try command C', description='description duplicates of CSCS') cscs2.add_csc( CSCmd(spoken_forms=csc_else_spoken_forms, meanings=csc_c_else_meanings, docstring=csc_c_else_docstring)) cscs1.add_csc( CSCmd(spoken_forms=csc_else_spoken_forms, meanings=csc_python_else_meanings, docstring=csc_python_else_docstring)) interp.add_csc_set(cscs2) interp.add_csc_set(cscs1) interp.add_lsa( LSAlias(["plus"], meanings={all_languages: " + "}, name="plus sign")) wciSay.load_commands_from_interpreter(self._app(), interp, 'C') expected = \ {'C': {'else': [[{'action': 'else clause of a C conditional', 'doc': 'else clause only c', 'equiv': 'Language: C', 'scope': 'buffer', 'setdescription': 'description duplicates of CSCS', 'setname': 'try command C'}]], 'plus': [{'description': 'no description', 'name': 'plus sign', 'new_symbol': None, 'setname': 'lsas', 'spacing': 0, 'written_form': ' + '}]}} self.assert_equal( expected, wciSay.index, "index of else csc set in C different from expected") wciSay.load_commands_from_interpreter(self._app(), interp, 'python') expected = \ {'python': {'else': [[{'action': 'no docstring available', 'doc': 'else clause only python', 'equiv': 'BlankLine: python', 'scope': 'immediate', 'setdescription': 'description of CSCS', 'setname': 'try command python'}, {'action': "Inserts 'else on non blank line^' in current buffer", 'doc': 'else clause only python', 'equiv': 'Language: python', 'scope': 'buffer', 'setdescription': 'description of CSCS', 'setname': 'try command python'}]], 'plus': [{'description': 'no description', 'name': 'plus sign', 'new_symbol': None, 'setname': 'lsas', 'spacing': 0, 'written_form': ' + '}]}} self.assert_equal( expected, wciSay.index, "index of else csc set in python different from expected")
def setUp(self): print '\n=======setting up WhatCanISay test instance' self.wciSay = WhatCanISay.WhatCanISay() self.interp = CmdInterp() # lsa set: commands = CmdSet("mixed commands", description="description of commands") commands.add_lsa( LSAlias(lsa_multiply_spoken_forms, lsa_multiply_meanings, name="multiply")) commands.add_lsa( LSAlias(lsa_not_spoken_forms, lsa_not_meanings, name="not")) commands.add_lsa( LSAlias(lsa_not_duplicate_spoken_forms, lsa_not_meanings, name="not")) commands.add_lsa( LSAlias(lsa_equals_spoken_forms, lsa_equals_meanings, name="equals lsa")) # also add an equals csc to these commands: commands.add_csc( CSCmd(spoken_forms=csc_equals_spoken_forms, meanings=csc_equals_meanings, docstring=csc_equals_docstring)) self.interp.add_cmd_set(commands) # csc set: cscs = CmdSet('csc commands', description='description of CSCS') cscs2 = CmdSet('csc commands too', description='description duplicates of CSCS') cscs.add_csc( CSCmd(spoken_forms=csc_with_arguments_spoken_forms, meanings=csc_with_arguments_meanings, docstring=csc_with_arguments_docstring)) # here the tricky one: else only for python: cscs.add_csc( CSCmd(spoken_forms=csc_else_spoken_forms, meanings=csc_python_else_meanings, docstring=csc_python_else_docstring)) # else duplicate, only for python: cscs.add_csc( CSCmd(spoken_forms=csc_else_duplicate_spoken_forms, meanings=csc_python_else_meanings, docstring=csc_python_else_docstring)) # csc_c_else_meanings only for c, group should be : csc commands too! # and in another set: else for c! should come in set cscs commands too!!! cscs2.add_csc( CSCmd(spoken_forms=csc_else_spoken_forms, meanings=csc_c_else_meanings, docstring=csc_c_else_docstring)) self.interp.add_csc_set(cscs) self.interp.add_csc_set(cscs2) # punctuation: punc = SinglePunctuation(name='standard punctuation') punc.add('%', ['percent-sign']) punc.create(self.interp) self.wciSay.load_commands_from_interpreter(self._app(), self.interp, 'python')
def test_Test_correct_order_of_CSCmdList_permutations_test(self): """Add meanings in different orders, placing in CSCmdList should be sorted right away""" actionHello = ActionInsert("csc hello") actionBlankLine = ActionInsert("csc blank") actionBeforeArguments = ActionInsert("csc before arguments") contBlankLine = ContBlankLine() contAny = ContAny() CAList = [(ContPyBeforeArguments(), actionBeforeArguments), (contAny, actionHello), (contBlankLine, actionBlankLine)] for permutation in [(1, 2, 0), (2, 0, 1), (0, 2, 1), (1, 0, 2), (2, 1, 0), (0, 1, 2)]: interp = CmdInterp() CAListPermuted = [CAList[i] for i in permutation] cscs = CSCmdSet('csc demo set', description='description of csc demo set') # test the sorting of the csc. order of dict not important, always returning same CSCmdList: meanings = dict() for (c, a) in CAListPermuted: meanings[c] = a csc = CSCmd(spoken_forms=['hello'], meanings=meanings, docstring="hello in csc test permutations") cscs.add_csc(csc) interp.add_csc_set(cscs) wTrie = interp.commands for spoken, cscmd_list in wTrie.items(): if spoken == ['hello']: cscmd_list_expected = \ [{'action': "Inserts 'csc blank^' in current buffer", 'doc': 'hello in csc test permutations', 'equiv': 'BlankLine: any', 'scope': 'immediate', 'setdescription': 'description of csc demo set', 'setname': 'csc demo set'}, {'action': "Inserts 'csc before arguments^' in current buffer", 'doc': 'hello in csc test permutations', 'equiv': 'ContPyBeforeArguments: python', 'scope': 'immediate', 'setdescription': 'description of csc demo set', 'setname': 'csc demo set'}, {'action': "Inserts 'csc hello^' in current buffer", 'doc': 'hello in csc test permutations', 'equiv': 'Any', 'scope': 'global', 'setdescription': 'description of csc demo set', 'setname': 'csc demo set'}] else: self.fail( "should not come here, testing error, should have exactly 1 spoken form" ) visible_list = cscmd_list.get_info() self.assert_equal(cscmd_list_expected, visible_list, 'wTrie CSCmdList of meanings with spoken form "%s" (permutation: %s) is not as expected'% \ (repr(spoken), permutation)) break else: self.fail( "no spoken forms in test, should not come here, testing error, should have 1 spoken form" )