def test_systemtools_PersistenceManager_as_pdf_01(): r'''Agent abjad.persists PDF file when no PDF file exists. ''' note = abjad.Note("c'4") with abjad.FilesystemState(remove=paths): result = abjad.persist(note).as_pdf(pdf_path) assert os.path.isfile(pdf_path) assert isinstance(result, tuple)
def test_systemtools_PersistenceManager_as_ly_01(): r'''Agent abjad.persists LilyPond file when no LilyPond file exists. ''' note = abjad.Note("c'4") with abjad.FilesystemState(remove=[ly_path]): result = abjad.persist(note).as_ly(ly_path) assert os.path.isfile(ly_path) assert isinstance(result, tuple)
def test_persist_as_pdf_01(): """ Persists PDF file when no PDF file exists. """ note = abjad.Note("c'4") with abjad.FilesystemState(remove=paths): result = abjad.persist.as_pdf(note, pdf_path) assert os.path.isfile(pdf_path) assert isinstance(result, tuple)
def test_persist_as_ly_01(): """ Persists LilyPond file when no LilyPond file exists. """ note = abjad.Note("c'4") with abjad.FilesystemState(remove=[ly_path]): result = abjad.persist.as_ly(note, ly_path) assert os.path.isfile(ly_path) assert isinstance(result, tuple)
def test_PersistenceManager_as_ly_02(): """ Agent abjad.persists LilyPond file when LilyPond file already exists. """ note = abjad.Note("c'4") with abjad.FilesystemState(remove=[ly_path]): result = abjad.persist(note).as_ly(ly_path) assert isinstance(result, tuple) assert os.path.isfile(ly_path) abjad.persist(note).as_ly(ly_path) assert os.path.isfile(ly_path)
def test_io_compare_files_06(): """ Is true when white space differs. """ with abjad.FilesystemState(remove=[path_1, path_2]): first_lines = ["print 'hello'", "", "", "print 'goodbye'", ""] second_lines = ["", "print 'hello'", "print 'goodbye'"] with open(path_1, "w") as file_pointer: file_pointer.write("\n".join(first_lines)) with open(path_2, "w") as file_pointer: file_pointer.write("\n".join(second_lines)) assert abjad.io._compare_text_files(path_1, path_2)
def test_persist_as_pdf_02(): """ Persists PDF file when equivalent PDF file already exists. """ note = abjad.Note("c'4") with abjad.FilesystemState(remove=paths): result = abjad.persist.as_pdf(note, pdf_path) assert os.path.isfile(pdf_path) assert isinstance(result, tuple) os.remove(ly_path) abjad.persist.as_pdf(note, pdf_path) assert os.path.isfile(pdf_path)
def test_TestManager_compare_files_02(): """ Is true when version strings differ. """ with abjad.FilesystemState(remove=[path_1, path_2]): first_lines = [r'\version "2.19.7"'] + lines second_lines = [r'\version "2.19.8"'] + lines with open(path_1, "w") as file_pointer: file_pointer.write("\n".join(first_lines)) with open(path_2, "w") as file_pointer: file_pointer.write("\n".join(second_lines)) assert abjad.TestManager._compare_lys(path_1, path_2)
def test_io_compare_files_04(): """ False when any other lines differ. """ with abjad.FilesystemState(remove=[path_1, path_2]): first_lines = [r'\version "2.19.7"'] + lines second_lines = [r'\version "2.19.8"'] + lines + ["foo"] with open(path_1, "w") as file_pointer: file_pointer.write("\n".join(first_lines)) with open(path_2, "w") as file_pointer: file_pointer.write("\n".join(second_lines)) assert not abjad.io._compare_lys(path_1, path_2)
def test_TestManager_compare_files_05(): """ Is true when lines are exactly the same. """ with abjad.FilesystemState(remove=[path_1, path_2]): first_lines = ["print 'hello'"] second_lines = first_lines[:] with open(path_1, 'w') as file_pointer: file_pointer.write('\n'.join(first_lines)) with open(path_2, 'w') as file_pointer: file_pointer.write('\n'.join(second_lines)) assert abjad.TestManager._compare_text_files(path_1, path_2)
def test_TestManager_compare_files_04(): """ False when any other lines differ. """ with abjad.FilesystemState(remove=[path_1, path_2]): first_lines = [r'\version "2.19.7"'] + lines second_lines = [r'\version "2.19.8"'] + lines + ['foo'] with open(path_1, 'w') as file_pointer: file_pointer.write('\n'.join(first_lines)) with open(path_2, 'w') as file_pointer: file_pointer.write('\n'.join(second_lines)) assert not abjad.TestManager._compare_lys(path_1, path_2)
def test_io_compare_files_03(): """ Is true when comments differ. """ with abjad.FilesystemState(remove=[path_1, path_2]): first_lines = [r'\version "2.19.7"'] + lines second_lines = ["% 2014-01-01 05:43:01", r'\version "2.19.8"'] + lines with open(path_1, "w") as file_pointer: file_pointer.write("\n".join(first_lines)) with open(path_2, "w") as file_pointer: file_pointer.write("\n".join(second_lines)) assert abjad.io._compare_lys(path_1, path_2)
def test_TestManager_compare_files_03(): """ Is true when comments differ. """ with abjad.FilesystemState(remove=[path_1, path_2]): first_lines = [r'\version "2.19.7"'] + lines second_lines = ['% 2014-01-01 05:43:01', r'\version "2.19.8"'] + lines with open(path_1, 'w') as file_pointer: file_pointer.write('\n'.join(first_lines)) with open(path_2, 'w') as file_pointer: file_pointer.write('\n'.join(second_lines)) assert abjad.TestManager._compare_lys(path_1, path_2)
def test_TestManager_compare_files_01(): """ Is true when lines are exactly the same. """ with abjad.FilesystemState(remove=[path_1, path_2]): first_lines = [r'\version "2.19.7"'] + lines second_lines = first_lines[:] with open(path_1, 'w') as file_pointer: file_pointer.write('\n'.join(first_lines)) with open(path_2, 'w') as file_pointer: file_pointer.write('\n'.join(second_lines)) assert abjad.TestManager._compare_lys(path_1, path_2)
def test_TestManager_compare_files_07(): """ False when any other lines differ. """ with abjad.FilesystemState(remove=[path_1, path_2]): first_lines = ["print 'hello'"] second_lines = ["print 'goodbye'"] with open(path_1, 'w') as file_pointer: file_pointer.write('\n'.join(first_lines)) with open(path_2, 'w') as file_pointer: file_pointer.write('\n'.join(second_lines)) assert not abjad.TestManager._compare_text_files(path_1, path_2)
def test_TestManager_compare_files_06(): """ Is true when white space differs. """ with abjad.FilesystemState(remove=[path_1, path_2]): first_lines = ["print 'hello'", '', '', "print 'goodbye'", ''] second_lines = ['', "print 'hello'", "print 'goodbye'"] with open(path_1, 'w') as file_pointer: file_pointer.write('\n'.join(first_lines)) with open(path_2, 'w') as file_pointer: file_pointer.write('\n'.join(second_lines)) assert abjad.TestManager._compare_text_files(path_1, path_2)
def test_segments_02(directory): # only run on Travis because segment illustration usually takes a while if not os.getenv("TRAVIS"): return with abjad.FilesystemState(keep=[directory]): ly = directory / "illustration.ly" ly_old = directory / "illustration.old.ly" if ly.exists(): shutil.copyfile(ly, ly_old) exit_code = abjad_ide.make_illustration_pdf(directory, open_after=False,) if exit_code != 0: sys.exit(exit_code) if not ly_old.exists(): return assert ly.exists() assert ly_old.exists() if not abjad.TestManager.compare_files(ly_old, ly): ly_old_text = ly_old.read_text().splitlines(keepends=True) ly_text = ly.read_text().splitlines(keepends=True) print("".join(difflib.ndiff(ly_old_text, ly_text))) sys.exit(1)