def test_example1(self): testdir = path(l2dndmod.__file__).parent / 'testtex' fn = testdir / 'quadratic.tex' print("=" * 70) print("file %s" % fn) with make_temp_directory() as tmdir: nfn = '%s/%s' % (tmdir, fn.basename()) os.system('cp %s/* %s' % (testdir, tmdir)) os.chdir(tmdir) l2dnd = LatexToDragDrop(nfn, verbose=True, randomize_solution_filename=False) pre = nfn[:-4] auxfn = pre + ".aux" self.assertTrue(os.path.exists(auxfn)) files = [ 'quadratic_dnd_label1.png', 'quadratic_dnd.xml', 'quadratic_dnd.xml', 'quadratic_dnd_sol.png' ] for fn in files: self.assertTrue(os.path.exists(path(tmdir) / fn)) xfn = path(tmdir) / 'quadratic_dnd.xml' xml = open(xfn).read() self.assertIn( '<img src="/static/images/quadratic/quadratic_dnd_sol.png"/>', xml) self.assertIn( '<draggable id="term2" icon="/static/images/quadratic/quadratic_dnd_label3.png"/>', xml)
def test_gravity_with_options(self): testdir = path(l2dndmod.__file__).parent / 'testtex' fn = testdir / 'gravity2.tex' print("=" * 70) print("file %s" % fn) with make_temp_directory() as tmdir: nfn = '%s/%s' % (tmdir, fn.basename()) os.system('cp %s/* %s' % (testdir, tmdir)) os.chdir(tmdir) l2dnd = LatexToDragDrop(nfn, verbose=True, randomize_solution_filename=False) self.assertTrue(len(l2dnd.test_results) == 3) pre = nfn[:-4] auxfn = pre + ".aux" self.assertTrue(os.path.exists(auxfn)) files = [ 'gravity2_dnd_label1.png', 'gravity2_dnd.xml', 'gravity2_dnd.xml', 'gravity2_dnd_sol.png' ] for fn in files: self.assertTrue(os.path.exists(path(tmdir) / fn)) xfn = path(tmdir) / 'gravity2_dnd.xml' xml = open(xfn).read() self.assertIn("'hide_formula_input': True", xml) tfn = path(tmdir) / 'gravity2_dnd_tests.json' self.assertTrue(os.path.exists(tfn))
def test_gravity(self): testdir = path(l2dndmod.__file__).parent / 'testtex' fn = testdir / 'gravity.tex' print("=" * 70) print("file %s" % fn) with make_temp_directory() as tmdir: nfn = '%s/%s' % (tmdir, fn.basename()) os.system('cp %s/* %s' % (testdir, tmdir)) os.chdir(tmdir) l2dnd = LatexToDragDrop(nfn, verbose=True, randomize_solution_filename=False) pre = nfn[:-4] auxfn = pre + ".aux" self.assertTrue(os.path.exists(auxfn)) files = [ 'gravity_dnd_label1.png', 'gravity_dnd.xml', 'gravity_dnd.xml', 'gravity_dnd_sol.png' ] for fn in files: self.assertTrue(os.path.exists(path(tmdir) / fn)) xfn = path(tmdir) / 'gravity_dnd.xml' xml = open(xfn).read() self.assertIn( '<img src="/static/images/gravity/gravity_dnd_sol.png"/>', xml) self.assertIn("samples = 'G,m_1,m_2,d@1,1,1,1:20,20,20,20#40'", xml)
def test_gravity_with_expected_answer_error(self): testdir = path(l2dndmod.__file__).parent / 'testtex' fn = testdir / 'gravity_bad3.tex' print("=" * 70) print("file %s" % fn) with make_temp_directory() as tmdir: nfn = '%s/%s' % (tmdir, fn.basename()) os.system('cp %s/* %s' % (testdir, tmdir)) os.chdir(tmdir) err = None try: l2dnd = LatexToDragDrop(nfn, verbose=True) except Exception as err: print("Error = %s" % str(err)) self.assertTrue('DDformula test [1] ERROR!' in str(err))
def test_custom_cfn2(self): testdir = path(l2dndmod.__file__).parent / 'testtex' fn = testdir / 'gravity_cfn.tex' print("=" * 70) print("file %s" % fn) with make_temp_directory() as tmdir: nfn = '%s/%s' % (tmdir, fn.basename()) os.system('cp %s/* %s' % (testdir, tmdir)) os.chdir(tmdir) l2dnd = LatexToDragDrop(nfn, verbose=True, custom_cfn='testcfn') pre = nfn[:-4] auxfn = pre + ".aux" self.assertTrue(os.path.exists(auxfn)) xfn = path(tmdir) / 'gravity_cfn_dnd.xml' xml = open(xfn).read() self.assertIn('<customresponse cfn="testcfn">', xml)