示例#1
0
 def setUp(self):
     """define self.tmpTest (in TMP)
         and vocolausertest and unimacrousertest in HOME directory
         raise TestError if HOME is not existent, or one of these directories already exist
     """
     ## testfolder:
     tmp = natlinkcorefunctions.getExtendedEnv("TMP")
     tmpTest = os.path.join(tmp, 'testconfig')
     if not os.path.isdir(tmp):
         raise TestError('test error, not a valid tmp folderpath: %s'% tmp)
     if os.path.exists(tmpTest):
         shutil.rmtree(tmpTest)
     if os.path.exists(tmpTest):
         raise TestError('test error, test path should not be there: %s'% tmpTest)
     
     
     os.mkdir(tmpTest)
     homeDir = isValidPath("~")
     if homeDir:
         vocolausertest = os.path.join(homeDir, "vocolausertest")
         if not isValidPath(vocolausertest):
             os.mkdir(vocolausertest)
         self.vocolausertest = vocolausertest
         unimacrousertest = os.path.join(homeDir, "unimacrousertest")
         if not isValidPath(unimacrousertest):
             os.mkdir(unimacrousertest)
         self.unimacrousertest = unimacrousertest
     else:
         raise TestError("home directory not defined: %s")
             
         
     self.assertTrue(os.path.isdir(tmpTest), "Could not make test folder: %s"% tmpTest)
     # self.tmpTest to test directory things safely:
     self.tmpTest = tmpTest
     self.cli = natlinkconfigfunctions.CLI()
     config = self.cli.config
     config.userregnl = NatlinkstatusTestInifileSection()
     config.userregnl.clear()
     self.testinisection = config.userregnl
示例#2
0
    def test_setClearDirectoryOptions(self):
        """This option tests the different directory functions of natlinkconfigfunctions
        
        UserDirectory is NOT Unimacro any more.
        
        assume %HOME% and "~" point to C:\Documenten.
        assume testing with Dragon12 on a 64 bits machine
        
        
        """
        dnsinstalldir = "%PROGRAMFILES%/Nuance/NaturallySpeaking12"
        wordpadexe = r"C:\Program Files\Windows NT\Accessories\wordpad.exe"
        if not os.path.isfile(wordpadexe):
            raise TestError("should have a path to wordpad.exe, %s does not exist"% wordpadexe)
        dummyfile = os.path.join(self.tmpTest, 'exists.txt')
        f = open(dummyfile, 'w')
        f.close()
        dummyexefile = os.path.join(self.tmpTest, 'autohotkey.exe')
        f = open(dummyexefile, 'w')
        f.close()
        
        for (key, functionLetter, testFolder) in [
            ("DNSIniDir", 'c', self.tmpTest),
            ("DNSInstallDir", 'd', dnsinstalldir),
            ("UserDirectory", 'n', self.tmpTest),
            ("UnimacroUserDirectory", 'o', self.unimacrousertest),
            ("VocolaUserDirectory", 'v', self.vocolausertest),
            ("UnimacroIniFilesEditor", "p", wordpadexe), 
            ("AhkExeDir", "h", self.tmpTest),
            ("AhkUserDir", "k", self.tmpTest)]:
                print('---- start testing "%s", letter: "%s"'% (key, functionLetter))

                oldKey = "Old" + key
                cli = self.cli
                # make clean section:
                self.testinisection.clear()
                funcSetName = 'do_'+functionLetter
                funcClearName = 'do_'+functionLetter.upper()
                funcSet = getattr(cli, funcSetName)
                funcClear = getattr(cli, funcClearName)
                # not a valid folder:
                funcSet("notAValidFolder")
                self.checkusertestinifile(key, "", "%s, should be there yet"% key)
                self.checkusertestinifile(oldKey, "", "Old%s, should not be there yet")
        
                checkTestFolder = isValidPath(testFolder)
                if not checkTestFolder:
                    raise TestError("testFolder  should be a valid directory, not: %s"% testFolder)
                # setting the variable:
                funcSet(testFolder)
                if functionLetter == 'c':
                    self.checkusertestinifile(key,"", "%s, nothing should be changed yet (Inifiles do not exist)"% key)
            
                    #existence of these two files is checked:
                    testinifile = os.path.join(self.tmpTest, 'nsapps.ini')
                    f1 = open(testinifile, 'w')
                    f1.close()
            
                    testinifile = os.path.join(self.tmpTest, 'nssystem.ini')
                    f1 = open(testinifile, 'w')
                    f1.close()
            
                    funcSet(testFolder)
            
                self.checkusertestinifile(key, testFolder, "%s, should be set now to: %s"% (key, testFolder))
                self.checkusertestinifile(oldKey, "", "Old%s, should not be there yet"% key)
        
                # repeated has no effect:
                funcSet(testFolder)
                self.checkusertestinifile(key, testFolder, "%s, should be set now to: %s"% (key, testFolder))
                self.checkusertestinifile(oldKey, "", "Old%s, should not be there yet"% key)
        
        
                # now remove again:
                funcClear("dummy")
                self.checkusertestinifile(key, "", "%s, should be clear now")
                self.checkusertestinifile(oldKey, testFolder, "Old%s, should be set now to: %s"% (key, testFolder))
        
                # repeat has no effect:
                funcClear("dummy")
                self.checkusertestinifile(key, "", "%s, should be still clear")
                self.checkusertestinifile(oldKey, testFolder, "Old%s, should still be set now to: %s"%  (key, testFolder))
                
                # setting again:
                funcSet(testFolder)
                self.checkusertestinifile(key, testFolder, "%s, should again be set now to: %s"% (key,  testFolder))
                self.checkusertestinifile(oldKey, "", "Old%s, should be cleared again"% key)
                print('==== end of testing "%s", letter: "%s"'% (key, functionLetter))