def test_save_plot(self): fig = Figure() name = "test" plt.figure() plt.plot(x, y) fig._save_plot(name) # check if graph was saved path = fig._absolute_inner_path(f"{name}.jpg") self.assertTrue(os.path.isfile(path))
def test_texinput(self): fig = Figure() name = "test_tex" caption = "caption" plt.figure() plt.plot(x, y) input_tex = fig.create_input_latex(name, caption=caption, above=False) # create document for testing input statement doc = Document() doc.append(input_tex) doc.preamble.append(NoEscape(r"\usepackage{graphicx}")) doc.preamble.append(NoEscape(r"\usepackage{zref-user}")) doc.generate_pdf("Latex/test_tex", clean_tex=False)
def test_add_plot(self): fig = Figure() name = "test" plt.figure() plt.plot(x, y) fig.add_plot(name) # check if correct latex output is produced self.assertEqual( fig.dumps(), ("\\begin{figure}%\n\\centering%\n\\includegraphics[width=0.8" + "\\textwidth]{Graphs/test.jpg}%\n\\end{figure}"), ) plt.close()
def test_two(self): doc = Document() fig = Figure() with doc.create(Figure()) as fig: with fig.create( SubFigure(width=NoEscape(r"0.48\textwidth"))) as left: name = "left" plt.figure() plt.plot(x, y, label="l") plt.legend() left.add_plot(name, caption=name) plt.close() with fig.create( SubFigure(width=NoEscape(r"0.48\textwidth"))) as right: name = "right" plt.figure() plt.plot(x, y, label="r") plt.legend() right.add_plot(name, caption=name) plt.close() fig.add_caption_label("full", "full", above=False) self.assertEqual( fig.dumps(), ("\\begin{figure}%\n\\begin{subfigure}{0.48\\textwidth}%" + "\n\\caption{left}%\n\\zlabel{fig:left}%\n\\includegraphics[width=\\linewidth]" + "{Graphs/left.jpg}%\n\\end{subfigure}%\n\\begin{subfigure}{0.48\\textwidth}%" + "\n\\caption{right}%\n\\zlabel{fig:right}%\n\\includegraphics[width=" + "\\linewidth]{Graphs/right.jpg}%\n\\end{subfigure}%\n\\caption{full}%\n" + "\\zlabel{fig:full}%\n\\end{figure}"), ) doc.generate_tex("Latex/twosubfigures")
def test_reset(self): fig = Figure() # figure 1 for i in range(1, 3): name = f"test{i}" plt.figure() plt.plot(x, y, label=i) fig.add_plot(name) # check if correct latex output is produced self.assertEqual( fig.dumps(), (f"\\begin{{figure}}%\n\\centering%\n\\includegraphics[width=0.8\\textwidth]" + f"{{Graphs/test{i}.jpg}}%\n\\end{{figure}}"), ) fig.reset(show=False, close=True)
def test_four(self): doc = Document() with doc.create(Figure()) as fig: with fig.create( SubFigure(width=NoEscape(r"0.48\textwidth"))) as left: name = "left" plt.figure() plt.plot(x, y, label="l") plt.legend() left.add_plot(name, caption=name) plt.close() with fig.create( SubFigure(width=NoEscape(r"0.48\textwidth"))) as right: name = "right" plt.figure() plt.plot(x, y, label="r") plt.legend() right.add_plot(name, caption=name) plt.close() fig.append("\n") with fig.create( SubFigure(width=NoEscape(r"0.48\textwidth"))) as left2: name = "left2" plt.figure() plt.plot(x, y, label="l2") plt.legend() left2.add_plot(name, caption=name) plt.close() with fig.create( SubFigure(width=NoEscape(r"0.48\textwidth"))) as right2: name = "right2" plt.figure() plt.plot(x, y, label="r2") plt.legend() right2.add_plot(name, caption=name) plt.close() fig.add_caption("full") doc.generate_tex("Latex/foursubfigures")
def test_position(self): position = "h" fig = Figure(position=position) self.assertEqual(fig.options, position)
def test_outer_folder(self): folder = "Outer_test" fig = Figure(outer_folder_name=folder) self.assertEqual(fig._outer_folder_name, folder)
def test_inner_folder(self): folder = "Inner_test" fig = Figure(inner_folder_name=folder) self.assertEqual(fig._inner_folder_name, folder)
def test_path(self): path = "./Latex/test_path/" fig = Figure(folders_path=path) self.assertEqual(fig._folders_path, path)