def test_get_data(self): """ Test case to confirm that we are getting data from the file """ with open('test.txt', 'r') as handle: data = handle.read() self.assertEqual(data, readfiles.read_file('test.txt'))
def test_get_data(self): ''' Test case to confirm we are getting data from the file ''' with open("test.txt", "r") as handle: data = handle.read() self.assertEqual(data, readfiles.read_file('test.txt'))
from readfiles import read_file def extract_word(word, words): new_words = [] for i in range(len(word)): new_word = word[0:i] + word[i + 1:] if new_word in words: if new_word != ' ': new_words.append(new_word) return new_words if __name__ == '__main__': words = read_file( 'E:\PostGraduate\python project\\think python\Chapter10\words1.txt') for word in words: print extract_word(word, words)
def test_get_data(self): # test case to confirm tat we are gettin data from the file with open("test.txt", "r") as handle: data = handle.read() self.assertEqual(data, readfiles.read_file("test.txt"))
def test_nonfile(self): # test t confirm that an exception is raised when the wrong file is inputted self.assertEqual(None, readfiles.read_file("tests.txt"))
def test_get_data(self): with open("test.txt", "r") as handle: data = handle.read() self.assertEqual(data, readfiles.read_file("test.txt"))
def test_nonfile(self): self.assertEqual(None, readfiles.read_file("tests.txt"))
def test_nonfile(self): """ Test to confirm that an exeption is raised when a wrong file is inputted """ self.assertEqual(None, readfiles.read_file("tests.txt"))
res = [] top = 20 temp = sorted(dic_words.items(), key=itemgetter(1), reverse=True) for i in range(20): res.append(temp[i][0]) return res ##not in table def notintable(dic_words, words_table): res = [] for key in dic_words: if key not in words_table: res.append(key) return res if __name__ == '__main__': words = read_file('emma.txt') count_all, dic_words = calculate_words(words) print 'total words:%d' % count_all print 'number of different words:%d' % len(dic_words) ## 13.3 high_words = highFrequence_word(dic_words) for high_word in high_words[0:10]: print '%s:%d' % (high_word, dic_words[high_word]) ##13.4 words_table = readfiles.read_file('words.txt') no = notintable(dic_words, words_table)
def test_nonfile(self): ''' Test to confirm that an exception is raised when a wrong file is inputted ''' self.assertEqual(None, readfiles.read_file('tests.txt'))