예제 #1
0
 def test_backup_long_contents(self):
     q03.backup("moby_dick.txt")
     with open("moby_dick.txt", 'r') as original_file:
         original_contents = original_file.read()
     with open("moby_dick.txt", 'r') as backup_file:
         backup_contents = backup_file.read()
     self.assertEqual(original_contents, backup_contents)
예제 #2
0
 def test_backup_empty_file(self):
     with open("empty_file.txt", 'w') as empty_file:
         empty_file.write("")
     q03.backup("empty_file.txt")
     with open("empty_file.bak", 'r') as new_file:
         new_contents = new_file.read()
     self.assertEqual("", new_contents)
예제 #3
0
 def test_backup_contents(self):
     with open("important_file.txt", 'w') as file_object:
         contents = ("This is very important file!!\n"
                     "That's why you cannot see anything!")
         file_object.write(contents)
     q03.backup("important_file.txt")
     with open("important_file.txt", 'r') as original_file:
         original_contents = original_file.read()
     with open("important_file.bak", 'r') as new_file:
         new_contents = new_file.read()
     self.assertEqual(original_contents, new_contents)
예제 #4
0
 def test_backup_does_not_exist_file(self, mock_stdout):
     expected_output = "The file does not exist.\n"
     q03.backup("doesnt_exist_file.txt")
     self.assertEqual(mock_stdout.getvalue(), expected_output)
예제 #5
0
 def test_backup_if_it_writes_properly(self):
     q03.backup("important_file.txt")
     self.assertTrue(os.path.exists("./important_file.bak"))