Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests and address #36 #37

Merged
merged 13 commits into from
Feb 13, 2021
9 changes: 5 additions & 4 deletions pyxdsm/XDSM.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import numpy as np
import json

import subprocess
from collections import namedtuple

from pyxdsm import __version__ as pyxdsm_version
Expand Down Expand Up @@ -551,10 +551,11 @@ def write(self, file_name, build=True, cleanup=True, quiet=False):
f.write(tex_str)

if build:
command = "pdflatex "
command = ["pdflatex", "-halt-on-error", "-interaction=nonstopmode"]
if quiet:
command += " -interaction=batchmode -halt-on-error "
os.system(command + file_name + ".tex")
command += ["-interaction=batchmode", "-halt-on-error"]
command += [f"{file_name}.tex"]
subprocess.run(command, check=True)
if cleanup:
for ext in ["aux", "fdb_latexmk", "fls", "log"]:
f_name = "{}.{}".format(file_name, ext)
Expand Down
22 changes: 3 additions & 19 deletions pyxdsm/matrix_eqn.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from __future__ import division

import os

import numpy as np

import subprocess
from collections import namedtuple
import numpy as np


# color pallette link: http://paletton.com/#uid=72Q1j0kllllkS5tKC9H96KClOKC
Expand Down Expand Up @@ -241,7 +238,7 @@ def _write_tikz(tikz, out_file, build=True, cleanup=True):
f.write(base_file_end)

if build:
os.system("pdflatex {}.tex".format(out_file))
subprocess.run(["pdflatex", f"{out_file}.tex"], check=True)

if cleanup:
for ext in ["aux", "fdb_latexmk", "fls", "log", "tex"]:
Expand Down Expand Up @@ -582,19 +579,6 @@ def write(self, out_file=None, build=True, cleanup=True):
eqn_tikz = "\n".join(tikz)

if out_file:
# with open('{}.tex'.format(out_file), 'w') as f:
# f.write(base_file_start)
# f.write(eqn_tikz)
# f.write(base_file_end)

# if build:
# os.system('pdflatex {}.tex'.format(out_file))

# if cleanup:
# for ext in ['aux', 'fdb_latexmk', 'fls', 'log', 'tex']:
# f_name = '{}.{}'.format(out_file, ext)
# if os.path.exists(f_name):
# os.remove(f_name)
_write_tikz(eqn_tikz, out_file, build, cleanup)


Expand Down
25 changes: 12 additions & 13 deletions pyxdsm/tests/test_xdsm.py → tests/test_xdsm.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import unittest
import os
from pyxdsm.XDSM import XDSM, __file__, OPT, FUNC, SOLVER
import shutil
import tempfile
import subprocess
from pyxdsm.XDSM import XDSM, OPT, FUNC, SOLVER
from numpy.distutils.exec_command import find_executable

basedir = os.path.dirname(os.path.abspath(__file__))


def filter_lines(lns):
# Empty lines are excluded.
Expand All @@ -13,19 +18,11 @@ def filter_lines(lns):

class TestXDSM(unittest.TestCase):
def setUp(self):
import os
import tempfile

self.startdir = os.getcwd()
self.tempdir = tempfile.mkdtemp(prefix="testdir-")

os.chdir(self.tempdir)

def tearDown(self):
import os
import shutil

os.chdir(self.startdir)
os.chdir(basedir)

try:
shutil.rmtree(self.tempdir)
Expand All @@ -37,18 +34,20 @@ def test_examples(self):
This test just builds the three examples, and assert that the output files exist.
Unlike the other tests, this one requires LaTeX to be available.
"""
os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../examples"))
# we first copy the examples to the temp dir
shutil.copytree(os.path.join(basedir, "../examples"), os.path.join(self.tempdir, "examples"))
os.chdir(os.path.join(self.tempdir, "examples"))

filenames = ["kitchen_sink", "mdf"]
for f in filenames:
os.system("python {}.py".format(f))
subprocess.run(["python", f"{f}.py"], check=True)
self.assertTrue(os.path.isfile(f + ".tikz"))
self.assertTrue(os.path.isfile(f + ".tex"))
# look for the pdflatex executable
pdflatex = find_executable("pdflatex") is not None
# if no pdflatex, then do not assert that the pdf was compiled
self.assertTrue(not pdflatex or os.path.isfile(f + ".pdf"))
os.system("python mat_eqn.py")
subprocess.run(["python", "mat_eqn.py"], check=True)
self.assertTrue(os.path.isfile("mat_eqn_example.pdf"))
# change back to previous directory
os.chdir(self.tempdir)
Expand Down