def test_successful_r_and_n_chomp(self): line = "This is some text" new_line = conversion.chomp(line + "\r") self.assertEqual(line, new_line) line = "This is some text" new_line = conversion.chomp(line + "\n") self.assertEqual(line, new_line)
def test_writing_copyright(self): expected_copyright_notice = [ '######################################################################', '# #', '# This file has been auto-generated as part of convert_qc.py #', '# There may be errors, mis-translations, or other mistakes #', '# This file is presented as-is, with no guarantee of support, and is #', '# covered under the GNU GPL v3.0 License #', '# I recommend giving a careful read to check before running #', '# #', '# For any questions or comments, please email [email protected] #', '# For citations, please pretend I wrote an academic paper #', '# #', '# Input format: QuTiP #', '# Output format: ProjectQ #', '# #', '######################################################################' ] file = open("test.txt", "w+") conversion.write_output_copyright(file, "QuTiP", "ProjectQ") file.close() self.assertTrue(file.closed) with open("test.txt") as f: input = f.readlines() for i, each in enumerate(input): input[i] = conversion.chomp(each) self.assertListEqual(input, expected_copyright_notice)
def test_successful_rn_chomp(self): """ Test - chomp a line with a carriage return and newline character :return: """ line = "This is some text" new_line = conversion.chomp(line + "\r\n") self.assertEqual(line, new_line)
def test_successful_file_read(self): expected_list = ['these', 'are', 'some', 'lines'] filename = os.path.join(os.path.dirname(__file__), 'supporting_files/misc/misc_lines.txt') list = conversion.read_input_file(filename) for i, each in enumerate(list): list[i] = conversion.chomp(each) self.assertListEqual(list, expected_list)
def test_successful_no_break_chomp(self): line = "This is some text" new_line = conversion.chomp(line) self.assertEqual(line, new_line)