Exemple #1
0
    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"
            )
Exemple #2
0
    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:
        lsas = LSAliasSet("lsa/ commands", description="description of LSAS")
        lsas.add_lsa(
            LSAlias(lsa_multiply_spoken_forms,
                    lsa_multiply_meanings,
                    name="multiply"))
        lsas.add_lsa(
            LSAlias(lsa_not_spoken_forms, lsa_not_meanings, name="not"))
        lsas.add_lsa(
            LSAlias(lsa_not_duplicate_spoken_forms,
                    lsa_not_meanings,
                    name="not"))
        lsas.add_lsa(
            LSAlias(lsa_equals_spoken_forms,
                    lsa_equals_meanings,
                    name="equals lsa"))
        self.interp.add_lsa_set(lsas)

        # csc set:
        cscs = CSCmdSet('csc commands', description='description of CSCS')
        cscs2 = CSCmdSet('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 inanother 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))
        cscs.add_csc(
            CSCmd(spoken_forms=csc_equals_spoken_forms,
                  meanings=csc_equals_meanings,
                  docstring=csc_equals_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')
Exemple #5
0
    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"
                )