def assert_equal_files(self, expected_file, actual_file, mess): """check contents of both files, to be equal a small issue (class=copyright) is in here because of the WhatCanISayTest files... """ trunk, ext = os.path.splitext(str(expected_file)) if ext in [".html", ".htm", ".txt", ".js", ".css", ".ini", ".log"]: encodingexp, bomexp, contentexp = readwritefile.readAnything( expected_file) encodinggot, bomgot, contentgot = readwritefile.readAnything( actual_file) if encodinggot != encodingexp: print( "warning: different encoding found\n---exp: %s: %s\n+++got: %s: %s" % (expected_file, encodingexp, actual_file, encodinggot)) if bomgot != bomexp: print( "warning: different bom found\n---exp: %s: %s\n+++got: %s: %s" % (expected_file, bomexp, actual_file, bomgot)) # # # with open(expected_file) as k: # with open(actual_file) as l: gotlines = contentgot.split('\n') explines = contentexp.split('\n') for i, (kline, lline) in enumerate(zip(gotlines, explines)): if ext in [".html", ".htm"] and \ kline.find('class="copyright"') >= 0 and \ lline.find('class="copyright"') >= 0: continue self.assert_equal( kline, lline, mess + '\nthe two files------------\n%s\nand\n %s should have been equal\nThey differ in line %s' % (expected_file, actual_file, i + 1)) else: if not filecmp.cmp(expected_file, actual_file): message = mess + '\nthe two files------------\n%s\nand\n%s should have been equal\n--- comparison with filecmp.cmp ---'% \ (expected_file, actual_file) self.fail(message)
def tttestCopyClipboardCautious(self): """test the copying of the clipboard, with waiting times """ ## open the txtFiles (are closed in tearDown) for txtFile in txtFiles: hndle = self.openTestFile( os.path.join(thisDir, 'test_clipboardfiles', txtFile)) if hndle: self.allWindows[hndle] = txtFile else: print 'could not open %s' % txtFile cb = natlinkclipboard.Clipboard(save_clear=True) ## empty file: expTextPrev = "" for hndle, txtFile in self.allWindows.iteritems(): filePath = os.path.join(thisDir, 'test_clipboardfiles', txtFile) encoding, bom, expText = readwritefile.readAnything(filePath) if txtFile == "emptytest.txt": # now the clipboard remains unchanged... expText = expTextPrev else: # now save for empty file: expTextPrev = expText natlinkutilsqh.SetForegroundWindow(hndle) time.sleep(0.5) if txtFile == "emptytest.txt": time.sleep(3) natlink.playString("{ctrl+a}{ctrl+c}") # cb.copy_from_system(waiting_interval=0.05) # natlinkutilsqh.SetForegroundWindow(self.thisHndle) # print 'cb text: %s'% cb got = cb.get_text(waiting_interval=0.05) if txtFile == "emptytest.txt": self.assert_equal( expTextPrev, got, "testing empty txt file %s, result not as expected" % txtFile) else: self.assert_equal( expPrev, got, "testing txt file %s, result not as expected" % txtFile)
def tttestCopyClipboardQuick(self): """test the copying of the clipboard, without waiting times """ ## open the txtFiles (are closed in tearDown) for txtFile in txtFiles: hndle = self.openTestFile( os.path.join(thisDir, 'test_clipboardfiles', txtFile)) if hndle: self.allWindows[hndle] = txtFile else: print 'did not open testfile: %s' % txtFile cb = natlinkclipboard.Clipboard(save_clear=True) ## empty file: expTextPrev = "" for hndle, txtFile in self.allWindows.iteritems(): filePath = os.path.join(thisDir, 'test_clipboardfiles', txtFile) encoding, bom, expText = readwritefile.readAnything(filePath) if txtFile == "emptytest.txt": expText = expTextPrev else: expTextPrev = expText natlinkutilsqh.SetForegroundWindow(hndle) natlink.playString("{ctrl+a}{ctrl+c}") cb.copy_from_system() # natlinkutilsqh.SetForegroundWindow(self.thisHndle) # print 'cb text: %s'% cb got = cb.get_text() self.assert_equal( expText, got, "testing txt file %s, result not as expected" % txtFile) # also test the class method (direct call) got = natlinkclipboard.Clipboard.get_system_text() self.assert_equal( expText, got, "testing txt file %s, with class method, result not as expected" % txtFile) cb.restore()