def test_that_file_names_are_correctly_picked(self): formulas = [mk_eqn('\\tau')] write('eqn000.svg') write('eqn001.svg') c = cachedconverter.CachedConverter('') to_convert = c._get_formulas_to_convert(formulas) self.assertTrue(len(to_convert), 1) self.assertEqual(to_convert[0][2], 'eqn002.svg')
def test_that_invalid_caches_get_removed_if_specified(self): formulas = [mk_eqn('tau')] with open('gladtex.cache', 'w') as f: f.write('invalid cache') c = cachedconverter.CachedConverter('.', keep_old_cache=False) c.convert_all(formulas) # cache got overridden with open('gladtex.cache') as f: self.assertFalse('invalid' in f.read())
def test_that_invalid_caches_get_removed_if_specified(self): formulas = [mk_eqn("tau")] with open("gladtex.cache", "w") as f: f.write("invalid cache") c = cachedconverter.CachedConverter(".", keep_old_cache=False) c.convert_all(formulas) # cache got overridden with open("gladtex.cache") as f: self.assertFalse("invalid" in f.read())
def test_that_subdirectory_is_created(self): c = cachedconverter.CachedConverter('subdirectory') formula = ({}, True, '\\textbf{FOO!}') c.convert_all([formula]) # one directory exists self.assertEqual(get_number_of_files('.'), 1, "Found the following files, expected only 'subdirectory': " + \ ', '.join(os.listdir('.'))) # subdirectory contains 1 image and a cache self.assertEqual(get_number_of_files('subdirectory'), 2, "expected two"+\ " files, found instead " + repr(os.listdir('subdirectory')))
def test_that_inline_math_and_display_math_results_in_different_formulas( self): # two formulas, second is displaymath formula = r'\sum_{i=0}^n x_i' formulas = [((1, 1), False, formula), ((3, 1), True, formula)] c = cachedconverter.CachedConverter('.') c.convert_all(formulas) # expect all formulas and a gladtex cache to exist self.assertEqual(get_number_of_files('.'), len(formulas) + 1, "present files:\n%s" % ', '.join(os.listdir('.')))
def test_that_all_converted_formulas_are_in_cache_and_meta_info_correct( self): formulas = [ mk_eqn('a_{%d}' % i, pos=(i, i), count=i) for i in range(4) ] c = cachedconverter.CachedConverter('.') c.convert_all(formulas) # expect all formulas and a gladtex cache to exist self.assertEqual(get_number_of_files('.'), len(formulas) + 1, "present files:\n" + ', '.join(os.listdir('.'))) for pos, dsp, formula in formulas: data = c.get_data_for(formula, False) self.assertEqual(data['pos'], { 'depth': 9, 'height': 8, 'width': 7 }, "expected the pos as defined in the dummy class")
def test_that_all_converted_formulas_are_in_cache_and_meta_info_correct( self): formulas = [ mk_eqn("a_{%d}" % i, pos=(i, i), count=i) for i in range(4) ] c = cachedconverter.CachedConverter(".") c.convert_all(formulas) # expect all formulas and a gladtex cache to exist self.assertEqual( get_number_of_files("."), len(formulas) + 1, "present files:\n" + ", ".join(os.listdir(".")), ) for pos, dsp, formula in formulas: data = c.get_data_for(formula, False) self.assertEqual( data["pos"], { "depth": 9, "height": 8, "width": 7 }, "expected the pos as defined in the dummy class", )
def test_that_invalid_caches_trigger_error_by_default(self): with open('gladtex.cache', 'w') as f: f.write('invalid cache') with self.assertRaises(JsonParserException): c = cachedconverter.CachedConverter('')
def test_that_unknown_options_trigger_exception(self): c = cachedconverter.CachedConverter('subdirectory') self.assertRaises(ValueError, c.set_option, 'cxzbiucxzbiuxzb', 'muh')
def test_that_converted_formulas_are_cached(self): formulas = [mk_eqn('\\tau')] c = cachedconverter.CachedConverter('.') c.convert_all(formulas) self.assertTrue(c.get_data_for('\\tau', False))
def test_that_unknown_options_trigger_exception(self): c = cachedconverter.CachedConverter("subdirectory") self.assertRaises(ValueError, c.set_option, "cxzbiucxzbiuxzb", "muh")