def test_pickled_list_of_strings_matches_original(self): test_list = ['one', 'two', 'three', 'four'] with open('testfile.p', 'w') as f: list_pickler(test_list, f) with open('testfile.p', 'r') as f: unpickled = unpickler(f) self.assertEqual(test_list, unpickled)
def test_pickled_list_of_numbers_matches_original(self): test_list = [1, 2, 3, 4] with open('testfile.p', 'w') as f: list_pickler(test_list, f) with open('testfile.p', 'r') as f: unpickled = unpickler(f) self.assertEqual(test_list, unpickled)
def test_mixed_pickled_list_matches_original(self): test_list = [1, 2, 'red', 'blue'] with open('testfile.p', 'w') as f: list_pickler(test_list, f) with open('testfile.p', 'r') as f: unpickled = unpickler(f) self.assertEqual(test_list, unpickled)
def pickle_unpickle_equal_test(self): my_list = [1, 2, "sherman Wosely"] #list_pickler(my_list, self.file_obj) list_pickler(my_list, self.file_name ) another_list = unpickler(self.file_name) # check that my_list and another list are equal self.assertEqual(True, my_list == another_list)
def test_original_and_unpickled_list_same(self): list_pickler(self.file, self.my_list) unpickled_list = unpickler(self.file) self.assertEqual(self.my_list, unpickled_list) def tearDown(self): # tearDown gets run after the tests have been run, # whether they fail or pass. In this case, we're # using tear down to delete our temp folder and its # contents shutil.rmtree(self.path) #shutil.rmtree deletes a directory and all its contents
def test_lists_equal_using_pickle(self): my_list = ['R', 'a', 'l', 'p', 'h'] file_pickled = open('pickle_test.txt', 'w') #open file if exists, create it otherwise list_pickler(my_list, file_pickled) file_pickled.close() file_pickled = open('pickle_test.txt', 'r') #open file for reading unpickled_list = unpickler(file_pickled) file_pickled.close() remove('pickle_test.txt') #delete file self.assertEqual(my_list, unpickled_list)
def pickled_list_no_change_test(self): #old code - ignore me #tester = open('pickle_test.p','r+') #my_list = ["cheese","ham"] #pickle.dump(my_list,tester) #another_list = pickle.load(tester) #tester.close() my_list = ["cheese","ham"] file_loc = list_pickler(my_list) another_list = unpickler(file_loc) self.assertEqual(my_list,another_list)
def test_original_list_same_as_unpickled_list(self): list_pickler(self.file, self.pickle_list) unpickled_list = unpickler(self.file) self.assertEqual(self.pickle_list, unpickled_list) print "Test complete..."
def test_unpickler_returns_same_list_as_original(self): pick_list = list_pickler(self.original_list, self.fil_name) self.assertEqual(self.original_list, unpickler(self.fil_name))
def test_original_and_unpickled_list_same(self): list_pickler(self.file, self.my_list) unpickled_list = unpickler(self.file) self.assertEqual(self.my_list, unpickled_list)
def test_pickled_then_unpickled_lists_are_equal(self): list_pickler(self.file_path, self.my_list) another_list = unpickler(self.file_path) self.assertEqual(self.my_list,another_list)
def test_pickled_list_equals_unpickled_list(self): list_pickler(self.file, self.my_list) unpickled_list = unpickler(self.file) self.assertEqual(self.my_list, unpickled_list)
def test_pickler(self): data = [9, 9, 9] pickler.make_pickler(data, "save.p") result = pickler.unpickler("save.p") self.assertEqual(data, result)
def test_pickled_then_unpickled_lists_are_equal(self): list_pickler(self.file_path, self.my_list) another_list = unpickler(self.file_path) self.assertEqual(self.my_list, another_list)
def test_compare_lists(self): list_pickler(self.my_list,self.file) another_list = unpickler(self.file) self.assertEqual(self.my_list, another_list)
def test_original_and_unpickled_list_same(self): list_pickler(self.my_list,self.file_name) unpickled_list = unpickler(self.file_name) unpickled_list = [5,4,3,2,1] self.assertEqual(self.my_list, unpickled_list)
def test_pickled_equality(self): self.recovered_list = unpickler('test_list.pkl') self.assertEqual(self.list, self.recovered_list)
def compare_pick_to_unpick_lists(self): list_pickler(self.file, self.test_list) unpicked_list = unpickler(self.file) self.assertEqual(self.test_list, unpicked_list)