def test_1(self): text = "There's real poetry in the real world.Science is the poetry of reality." concat_files(["file_1.txt", "file_2.txt"]) file = open("MEGATRON.txt", "r") content = file.read().rstrip('\n') file.close() self.assertEqual(content, text)
def test_concat_files(self): concat_files(["test_file1", "test_file2"]) file_ = open("MEGATRON", "r") content = file_.read() file_.close() self.assertEqual("just a simple text for testing\n\n" + "again just a simple text for testing\n\n", content)
def test_with_two_files_with_empty_MEGATRON(self): with open('MEGATRON', 'w') as file: file.truncate() solution.concat_files('test_text_file1.txt', 'test_text_file2.txt') with open('MEGATRON') as file: contents = file.read() self.assertEqual(contents, self.text1 + '\n' + self.text2)
def setUp(self): self.filenames = ["file1.txt", "file2.txt", "file3.txt"] self.c_file = "bumblebee.txt" for filename in self.filenames: f = open(filename, "w") f.write("This is content of file with name: " + filename) f.close() f = open(self.c_file, "w") f.close() self.file = open(self.c_file, "r") concat_files(self.filenames)
def test_with_two_files_with_contents_in_MEGATRON(self): with open('MEGATRON', 'w') as file: file.write("This isn't over.") solution.concat_files('test_text_file1.txt', 'test_text_file2.txt') with open('MEGATRON') as file: contents = file.read() self.assertEqual(contents, '\n'.join(["This isn't over.", self.text1, self.text2]))
def test_concat_files(self): self.assertTrue(not concat_files([])) expected_string1 = "Some content 1." self.assertTrue(concat_files(['concat_files', 'test_file1'])) megatron = open('MEGATRON', 'r') content_megatron = megatron.read() megatron.close() self.assertEqual(expected_string1, content_megatron) expected_string2 = "Some content 2.\n\nPython is an awesome language!\nYou should try it." self.assertTrue(concat_files(['concat_files', 'test_file2', 'file1.txt'])) megatron = open('MEGATRON', 'r') content_megatron = megatron.read() megatron.close() self.assertEqual("Some content 1.\n\n" + expected_string2, content_megatron)
def test_concat_two_files(self): sys.argv.append("file.txt") sys.argv.append("file2.txt") file_to_write = "MEGATRON.txt" arr_content = [] file_write = open(file_to_write, "w") for index in range(1, len(sys.argv)): file_name = sys.argv[index] file_read = open(file_name, "r") content = file_read.read() arr_content.append(content) file_write.write(content) file_read.close() expect = "\n".join(arr_content) self.assertEqual(expect, solution.concat_files(file_read)) file_write.close()
def test_concat_files(self): self.assertEqual("Hi my name is Dayana!\nYour name is?", concat_files('filename1.txt', 'filename2.txt'))
def test_concat_files(self): self.assertEqual('test1\ntest2\n', solution.concat_files(self.array))
def test_two_files_second_concatenate(self): self.assertEqual(self.content_megatron + "Spam\n\nSpam\n\n",concat_files([self.file_name,self.file_name]))
def test_one_file_first_concatenate(self): self.assertEqual(self.content_megatron + "Spam\n\n",concat_files([self.file_name]))