def htmleqn(formula, hr=True): """Format a formula to appear as if it would have been outsourced into an external file.""" return '%s\n<p id="%s"><pre>%s</pre></span></p>\n' % ( ("<hr/>" if hr else ""), htmlhandling.gen_id(formula), formula, )
def test_that_link_to_external_image_points_to_file_basepath_and_formula(self): os.mkdir("basepath") with htmlhandling.HtmlImageFormatter("basepath") as img: formatted_img = img.format_excluded(self.pos, "\\tau\\tau", "foo.png") expected_id = htmlhandling.gen_id("\\tau\\tau") # find linked formula path href = re.search('href="(.*?)"', formatted_img) self.assertTrue(href != None) # extract path and id from it self.assertTrue("#" in href.groups()[0]) path, id = href.groups()[0].split("#") self.assertEqual(path, "basepath/" + excl_filename) self.assertEqual(id, expected_id)
def test_that_link_to_external_image_points_to_file_basepath_and_formula(self): os.mkdir('basepath') with htmlhandling.HtmlImageFormatter('basepath') as img: formatted_img = img.format_excluded(self.pos, '\\tau\\tau', 'foo.png') expected_id = htmlhandling.gen_id('\\tau\\tau') external_file = read(os.path.join('basepath', excl_filename), 'r') # find linked formula path href = re.search('href="(.*?)"', formatted_img) self.assertTrue(href != None) # extract path and id from it self.assertTrue('#' in href.groups()[0]) path, id = href.groups()[0].split('#') self.assertEqual(path, 'basepath/' + excl_filename) self.assertEqual(id, expected_id)
def test_that_link_to_external_image_points_to_file_and_formula(self): with htmlhandling.HtmlImageFormatter() as img: formatted_img = img.format_excluded(self.pos, "\\tau\\tau", "foo.png") expected_id = htmlhandling.gen_id("\\tau\\tau") external_file = read(excl_filename, "r", encoding="utf-8") # find linked formula path href = re.search('href="(.*?)"', formatted_img) self.assertTrue(href != None) # extract path and id from it self.assertTrue("#" in href.groups()[0]) path, id = href.groups()[0].split("#") self.assertEqual(path, excl_filename) self.assertEqual(id, expected_id) # check external file self.assertTrue("<p id" in external_file) self.assertTrue('="' + expected_id in external_file)
def test_that_link_to_external_image_points_to_file_and_formula(self): with htmlhandling.HtmlImageFormatter() as img: formatted_img = img.format_excluded(self.pos, '\\tau\\tau', 'foo.png') expected_id = htmlhandling.gen_id('\\tau\\tau') external_file = read(excl_filename, 'r', encoding='utf-8') # find linked formula path href = re.search('href="(.*?)"', formatted_img) self.assertTrue(href != None) # extract path and id from it self.assertTrue('#' in href.groups()[0]) path, id = href.groups()[0].split('#') self.assertEqual(path, excl_filename) self.assertEqual(id, expected_id) # check external file self.assertTrue('<p id' in external_file) self.assertTrue('="'+expected_id in external_file)
def test_id_contains_no_special_characters(self): data = htmlhandling.gen_id('\\tau!\'{}][~^') for character in {'!', "'", '\\', '{', '}'}: self.assertFalse(character in data)
def test_that_ids_start_with_letter(self): id = htmlhandling.gen_id("{}\\[]ÖÖÖö9343...·tau") self.assertTrue(id[0].isalpha())
def test_that_ids_are_max_150_characters_wide(self): id = htmlhandling.gen_id("\\alpha\\cdot\\gamma + " * 999) self.assertTrue(len(id) == 150)
def test_that_same_characters_are_not_repeated(self): id = htmlhandling.gen_id("jo{{{{{{{{ha") self.assertEqual(id, "jo_ha")
def test_formula_can_consist_only_of_numbers_and_id_is_generated(self): data = htmlhandling.gen_id("9*8*7=504") self.assertTrue(data.startswith("form")) self.assertTrue(data.endswith("504"))
def test_id_contains_no_special_characters(self): data = htmlhandling.gen_id("\\tau!'{}][~^") for character in {"!", "'", "\\", "{", "}"}: self.assertFalse(character in data)
def test_formula_can_consist_only_of_numbers_and_id_is_generated(self): data = htmlhandling.gen_id('9*8*7=504') self.assertTrue(data.startswith('form')) self.assertTrue(data.endswith('504'))
def htmleqn(formula, hr=True): """Format a formula to appear as if it would have been outsourced into an external file.""" return '%s\n<p id="%s"><pre>%s</pre></span></p>\n' % (\ ('<hr/>' if hr else ''), htmlhandling.gen_id(formula), formula)
def test_that_ids_are_max_150_characters_wide(self): id = htmlhandling.gen_id('\\alpha\\cdot\\gamma + ' * 999) self.assertTrue(len(id) == 150)
def test_that_ids_start_with_letter(self): id = htmlhandling.gen_id('{}\\[]ÖÖÖö9343...·tau') self.assertTrue(id[0].isalpha())