def test_g_function_read_file_string_correct_output(self): """[Lab 5] - [Investigation 1] - [Part 2] - Files - Test for output: ./lab5b.py""" try: import lab5b as lab5bStudent except: self.fail( 'lab5b.py contains errors(HINT: run the function and fix errors' ) error_output = 'incorrect output or file contents(HINT: compare your output to sample output and check data.txt for correct text)' filename = 'data.txt' answer = 'Hello World\nThis is the second line\nThird line\nLast line\n' self.assertEqual(lab5bStudent.read_file_string(filename), answer, msg=error_output)
def test_k_function_copy_file_add_line_numbers_correct_output_3(self): """[Lab 5] - [Investigation 1] - [Part 2] - Files - Test for output: ./lab5b.py""" try: import lab5b as lab5bStudent except: self.fail( 'lab5b.py contains errors(HINT: run the function and fix errors' ) error_output = 'incorrect output(HINT: read instructions again and confirm code follows correctly)' filename = 'seneca3.txt.checkscript' tempfile = 'seneca4.txt.checkscript' lab5bStudent.copy_file_add_line_numbers(filename, tempfile) answer = '1:1:Line 1\n2:2:Line 2\n3:3:Line 5\n' self.assertEqual(lab5bStudent.read_file_string(tempfile), answer, msg=error_output)
def test_k_function_copy_file_add_line_numbers_correct_output_1(self): """[Lab 5] - [Investigation 1] - [Part 2] - Files - Test for output: ./lab5b.py""" try: import lab5b as lab5bStudent except: self.fail( 'lab5b.py contains errors(HINT: run the function and fix errors' ) error_output = 'incorrect output(HINT: make sure output shows exactly)' filename = 'seneca2.txt.checkscript' tempfile = 'seneca3.txt.checkscript' f = open(tempfile, 'w') f.close() lab5bStudent.copy_file_add_line_numbers(filename, tempfile) answer = '1:Line 1\n2:Line 2\n3:Line 5\n' self.assertEqual(lab5bStudent.read_file_string(tempfile), answer, msg=error_output)
def test_j_function_write_file_list_correct_output_1(self): """[Lab 5] - [Investigation 1] - [Part 2] - Files - Test for output: ./lab5b.py""" try: import lab5b as lab5bStudent except: self.fail( 'lab5b.py contains errors(HINT: run the function and fix errors' ) error_output = 'incorrect output(HINT: make sure output shows exactly)' filename = 'seneca2.txt.checkscript' list1 = ['Line 1', 'Line 2', 'Line 3'] f = open(filename, 'w') f.close() lab5bStudent.write_file_list(filename, list1) answer = 'Line 1\nLine 2\nLine 3\n' self.assertEqual(lab5bStudent.read_file_string(filename), answer, msg=error_output)
def test_i_function_append_file_string_correct_output_2(self): """[Lab 5] - [Investigation 1] - [Part 2] - Files - Test for output: ./lab5b.py""" try: import lab5b as lab5bStudent except: self.fail( 'lab5b.py contains errors(HINT: run the function and fix errors' ) error_output = 'incorrect output(HINT: make sure function is appending and not overwriting)' filename = 'seneca1.txt.checkscript' string1 = 'First Line\nSecond Line\nThird\n' f = open(filename, 'w') f.close() lab5bStudent.append_file_string(filename, string1) lab5bStudent.append_file_string(filename, string1) answer = 'First Line\nSecond Line\nThird\nFirst Line\nSecond Line\nThird\n' self.assertEqual(lab5bStudent.read_file_string(filename), answer, msg=error_output)
def test_a_function_read_file_string(self): """[Lab 5] - [Investigation 1] - [Part 2] - Files - function read_file_string fails without 1 argument""" with self.assertRaises(Exception) as context: import lab5b as lab5bStudent lab5bStudent.read_file_string()