Ejemplo n.º 1
0
  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")
Ejemplo n.º 2
0
 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')
Ejemplo n.º 3
0
    def test_This_is_how_you_can_make_a_special_case_for_one_language(self):

        interp = CmdInterp()        
##        In next test all languages are first set to "ccc",
##        and then for python is changed to 'qqq'.
        interp.add_lsa(LSAlias(['spoken', 'form'],
                                    {'python': 'qqq', all_languages:  'ccc'}))
                                                         
        all_lsas = interp.language_specific_aliases
        python_lsas = all_lsas['python']
        # extract and check only one item:
        for an_LSA in python_lsas.items():
            wordList, entry = an_LSA
            spoken_form_text = ' '.join(wordList)
            written_form_text = getattr(entry, 'written_form', '')
            expected_spoken_form = 'spoken'
            expected_written_form = 'qqq'
            self.assert_equal(expected_spoken_form, spoken_form_text,
                               "LSA spoken form is not as expected")
            self.assert_equal(expected_written_form, written_form_text,
                               "LSA written form is not as expected")
            break
        c_lsas = all_lsas['C']
        # extract and check only one item:
        for an_LSA in c_lsas.items():
            wordList, entry = an_LSA
            spoken_form_text = ' '.join(wordList)
            written_form_text = getattr(entry, 'written_form', '')
            expected_spoken_form = 'spoken'
            expected_written_form = 'ccc'
            self.assert_equal(expected_spoken_form, spoken_form_text,
                               "LSA spoken form is not as expected")
            self.assert_equal(expected_written_form, written_form_text,
                               "LSA written form is not as expected")
            break
Ejemplo n.º 4
0
    def test_This_is_how_you_create_a_LSAlias__instance(self):

        interp = CmdInterp()        

        interp.add_lsa(LSAlias(['spoken', 'form'],
                                    {'C':  'sss', 'python': 'ppp'}))
                                                         
        all_lsas = interp.language_specific_aliases
        languages = all_lsas.keys()
        languages.sort()
        expected = list(all_languages)  # list (of keys)
        self.assert_equal(expected, languages, "LSAs, all languages should have a key, this was not as expected")
        expected = all_languages  # tuple
        self.assert_equal(expected, interp.supported_languages(),
                          "LSAs, languages not as expected through interp method")
        python_lsas = all_lsas['python']
        # extract and check only one item:
        for an_LSA in python_lsas.items():
            wordList, entry = an_LSA
            spoken_form_text = ' '.join(wordList)
            written_form_text = getattr(entry, 'written_form', '')
            expected_spoken_form = 'spoken'
            expected_written_form = 'ppp'
            self.assert_equal(expected_spoken_form, spoken_form_text,
                               "LSA spoken form is not as expected")
            self.assert_equal(expected_written_form, written_form_text,
                               "LSA written form is not as expected")
            break
Ejemplo n.º 5
0
    def test_This_is_how_you_can_make_a_special_case_c_style_languages(self):

        interp = CmdInterp()
        ##        In next test all languages are first set to "aaa",
        ##        next c_style_languages to ccc, and
        ##        after that java and python to something more specific
        ##        and then for python is changed to 'qqq'.
        interp.add_lsa(
            LSAlias(
                ['spoken', 'form'], {
                    'java': 'jjj',
                    'python': 'pppp',
                    all_languages: 'aaa',
                    c_style_languages: 'ccc'
                }))

        all_lsas = interp.language_specific_aliases
        python_lsas = all_lsas['python']
        # extract and check only one item:
        for an_LSA in python_lsas.items():
            wordList, entry = an_LSA
            spoken_form_text = ' '.join(wordList)
            written_form_text = getattr(entry, 'written_form', '')
            expected_spoken_form = 'spoken'
            expected_written_form = 'pppp'
            self.assert_equal(expected_spoken_form, spoken_form_text,
                              "LSA spoken form is not as expected")
            self.assert_equal(expected_written_form, written_form_text,
                              "LSA written form is not as expected")
            break
        c_lsas = all_lsas['C']
        # extract and check only one item:
        for an_LSA in c_lsas.items():
            wordList, entry = an_LSA
            spoken_form_text = ' '.join(wordList)
            written_form_text = getattr(entry, 'written_form', '')
            expected_spoken_form = 'spoken'
            expected_written_form = 'ccc'
            self.assert_equal(expected_spoken_form, spoken_form_text,
                              "LSA spoken form is not as expected")
            self.assert_equal(expected_written_form, written_form_text,
                              "LSA written form is not as expected")
            break

        java_lsas = all_lsas['java']
        # extract and check only one item:
        for an_LSA in java_lsas.items():
            wordList, entry = an_LSA
            spoken_form_text = ' '.join(wordList)
            written_form_text = getattr(entry, 'written_form', '')
            expected_spoken_form = 'spoken'
            expected_written_form = 'jjj'
            self.assert_equal(expected_spoken_form, spoken_form_text,
                              "LSA spoken form is not as expected")
            self.assert_equal(expected_written_form, written_form_text,
                              "LSA written form is not as expected")
            break
Ejemplo n.º 6
0
    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")
Ejemplo n.º 7
0
    def test_This_is_how_you_can_make_a_special_case_c_style_languages(self):

        interp = CmdInterp()        
##        In next test all languages are first set to "aaa",
##        next c_style_languages to ccc, and
##        after that java and python to something more specific
##        and then for python is changed to 'qqq'.
        interp.add_lsa(LSAlias(['spoken', 'form'], 
                                    {'java': 'jjj','python': 'pppp', all_languages:  'aaa',
                                     c_style_languages: 'ccc'}))
                                                         
        all_lsas = interp.language_specific_aliases
        python_lsas = all_lsas['python']
        # extract and check only one item:
        for an_LSA in python_lsas.items():
            wordList, entry = an_LSA
            spoken_form_text = ' '.join(wordList)
            written_form_text = getattr(entry, 'written_form', '')
            expected_spoken_form = 'spoken'
            expected_written_form = 'pppp'
            self.assert_equal(expected_spoken_form, spoken_form_text,
                               "LSA spoken form is not as expected")
            self.assert_equal(expected_written_form, written_form_text,
                               "LSA written form is not as expected")
            break
        c_lsas = all_lsas['C']
        # extract and check only one item:
        for an_LSA in c_lsas.items():
            wordList, entry = an_LSA
            spoken_form_text = ' '.join(wordList)
            written_form_text = getattr(entry, 'written_form', '')
            expected_spoken_form = 'spoken'
            expected_written_form = 'ccc'
            self.assert_equal(expected_spoken_form, spoken_form_text,
                               "LSA spoken form is not as expected")
            self.assert_equal(expected_written_form, written_form_text,
                               "LSA written form is not as expected")
            break
    
        java_lsas = all_lsas['java']
        # extract and check only one item:
        for an_LSA in java_lsas.items():
            wordList, entry = an_LSA
            spoken_form_text = ' '.join(wordList)
            written_form_text = getattr(entry, 'written_form', '')
            expected_spoken_form = 'spoken'
            expected_written_form = 'jjj'
            self.assert_equal(expected_spoken_form, spoken_form_text,
                               "LSA spoken form is not as expected")
            self.assert_equal(expected_written_form, written_form_text,
                               "LSA written form is not as expected")
            break
Ejemplo n.º 8
0
 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')
Ejemplo n.º 9
0
  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")
Ejemplo n.º 10
0
    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")
Ejemplo n.º 11
0
class LSAliasTest(VoiceCodeRootTest.VoiceCodeRootTest):
    """tests of CSCmd and CSCmdDict

    """
    def __init__(self, name):
        VoiceCodeRootTest.VoiceCodeRootTest.__init__(self, name)
        
    def setUp(self):
        self.interp = CmdInterp()
 
        self.interp = CmdInterp()
        self.interp.add_lsa(LSAlias(lsa_multiply_spoken_forms, lsa_multiply_meanings))
        self.interp.add_lsa(LSAlias(lsa_not_spoken_forms, lsa_not_meanings))
    


        
##########################################################
# Documentation tests
#
# These tests illustrate how to use the class.
##########################################################
        

    def test_This_is_how_you_create_a_LSAlias__instance(self):

        interp = CmdInterp()        

        interp.add_lsa(LSAlias(['spoken', 'form'],
                                    {'C':  'sss', 'python': 'ppp'}))
                                                         
        all_lsas = interp.language_specific_aliases
        languages = all_lsas.keys()
        languages.sort()
        expected = list(all_languages)  # list (of keys)
        self.assert_equal(expected, languages, "LSAs, all languages should have a key, this was not as expected")
        expected = all_languages  # tuple
        self.assert_equal(expected, interp.supported_languages(),
                          "LSAs, languages not as expected through interp method")
        python_lsas = all_lsas['python']
        # extract and check only one item:
        for an_LSA in python_lsas.items():
            wordList, entry = an_LSA
            spoken_form_text = ' '.join(wordList)
            written_form_text = getattr(entry, 'written_form', '')
            expected_spoken_form = 'spoken'
            expected_written_form = 'ppp'
            self.assert_equal(expected_spoken_form, spoken_form_text,
                               "LSA spoken form is not as expected")
            self.assert_equal(expected_written_form, written_form_text,
                               "LSA written form is not as expected")
            break

    def test_This_is_how_you_can_make_a_special_case_for_one_language(self):

        interp = CmdInterp()        
##        In next test all languages are first set to "ccc",
##        and then for python is changed to 'qqq'.
        interp.add_lsa(LSAlias(['spoken', 'form'],
                                    {'python': 'qqq', all_languages:  'ccc'}))
                                                         
        all_lsas = interp.language_specific_aliases
        python_lsas = all_lsas['python']
        # extract and check only one item:
        for an_LSA in python_lsas.items():
            wordList, entry = an_LSA
            spoken_form_text = ' '.join(wordList)
            written_form_text = getattr(entry, 'written_form', '')
            expected_spoken_form = 'spoken'
            expected_written_form = 'qqq'
            self.assert_equal(expected_spoken_form, spoken_form_text,
                               "LSA spoken form is not as expected")
            self.assert_equal(expected_written_form, written_form_text,
                               "LSA written form is not as expected")
            break
        c_lsas = all_lsas['C']
        # extract and check only one item:
        for an_LSA in c_lsas.items():
            wordList, entry = an_LSA
            spoken_form_text = ' '.join(wordList)
            written_form_text = getattr(entry, 'written_form', '')
            expected_spoken_form = 'spoken'
            expected_written_form = 'ccc'
            self.assert_equal(expected_spoken_form, spoken_form_text,
                               "LSA spoken form is not as expected")
            self.assert_equal(expected_written_form, written_form_text,
                               "LSA written form is not as expected")
            break

    def test_This_is_how_you_can_make_a_special_case_c_style_languages(self):

        interp = CmdInterp()        
##        In next test all languages are first set to "aaa",
##        next c_style_languages to ccc, and
##        after that java and python to something more specific
##        and then for python is changed to 'qqq'.
        interp.add_lsa(LSAlias(['spoken', 'form'], 
                                    {'java': 'jjj','python': 'pppp', all_languages:  'aaa',
                                     c_style_languages: 'ccc'}))
                                                         
        all_lsas = interp.language_specific_aliases
        python_lsas = all_lsas['python']
        # extract and check only one item:
        for an_LSA in python_lsas.items():
            wordList, entry = an_LSA
            spoken_form_text = ' '.join(wordList)
            written_form_text = getattr(entry, 'written_form', '')
            expected_spoken_form = 'spoken'
            expected_written_form = 'pppp'
            self.assert_equal(expected_spoken_form, spoken_form_text,
                               "LSA spoken form is not as expected")
            self.assert_equal(expected_written_form, written_form_text,
                               "LSA written form is not as expected")
            break
        c_lsas = all_lsas['C']
        # extract and check only one item:
        for an_LSA in c_lsas.items():
            wordList, entry = an_LSA
            spoken_form_text = ' '.join(wordList)
            written_form_text = getattr(entry, 'written_form', '')
            expected_spoken_form = 'spoken'
            expected_written_form = 'ccc'
            self.assert_equal(expected_spoken_form, spoken_form_text,
                               "LSA spoken form is not as expected")
            self.assert_equal(expected_written_form, written_form_text,
                               "LSA written form is not as expected")
            break
    
        java_lsas = all_lsas['java']
        # extract and check only one item:
        for an_LSA in java_lsas.items():
            wordList, entry = an_LSA
            spoken_form_text = ' '.join(wordList)
            written_form_text = getattr(entry, 'written_form', '')
            expected_spoken_form = 'spoken'
            expected_written_form = 'jjj'
            self.assert_equal(expected_spoken_form, spoken_form_text,
                               "LSA spoken form is not as expected")
            self.assert_equal(expected_written_form, written_form_text,
                               "LSA written form is not as expected")
            break
    

            
            
##########################################################
# Unit tests lsa and general commands
#
# These tests check the internal workings of the class.
##########################################################

    def test_Test_contents_of_test_LSAliases(self):
        aliases_visible = {}
        for lang in self.interp.language_specific_aliases:
            aliases_visible[lang] = []
            for wordList, entry in self.interp.language_specific_aliases[lang].items():
                spoken_form_text = ' '.join(wordList)
                written_form_text = getattr(entry, 'written_form', '')
                aliases_visible[lang].append( (spoken_form_text, written_form_text) )
        self.assert_equal(expected_lsa_index, aliases_visible,
                          "testcase language_specific_aliases (made visible) not as expected")


    def test_Test_erroneous_definitions(self):
        
        interp = CmdInterp()
        # unknown language 'D'
        self.assertRaises(ValueError, LSAlias, (['wrong'],), {'D':  'oops'})
        self.assertRaises(DeprecationError, LSAlias, (['deprecated'],), {None:  'oops'})