def test_valid_content_strs_html(self): doc = common.MockDoc('html') span = pf.Span(pf.Str('a'), pf.Str('b'), pf.Str('c'), classes=['gloss']) gloss.parse(span, doc) self.assertEqual(pf.stringify(span), 'a<br/>b<br/>c')
def test_valid_content_strs(self): doc = common.MockDoc('html') span = pf.Span(pf.Str('a'), pf.Str('b'), pf.Str('c'), pf.Str('d'), classes=['phonrule']) phonrule.parse(span, doc) self.assertEqual(pf.stringify(span), 'a -> b/c_d')
def test_valid_content_strs_and_spans_latex(self): doc = common.MockDoc('latex') span1 = pf.Span(pf.Str('a')) str1 = pf.Str('b') span2 = pf.Span(pf.Str('c')) str2 = pf.Str('d') span = pf.Span(span1, str1, span2, str2, classes=['phonrule']) phonrule.parse(span, doc) self.assertEqual(pf.stringify(span), '\\phonb{a}{b}{c}{d}')
def test_valid_content_strs_and_spans_latex(self): doc = common.MockDoc('latex') span1 = pf.Span(pf.Str('a')) str1 = pf.Str('b') span2 = pf.Span(pf.Str('c')) span = pf.Span(span1, str1, span2, classes=['gloss']) gloss.parse(span, doc) self.assertEqual( pf.stringify(span), '\\begin{exe}\n\\ex\n\\gll a\\\\\nb\\\\\n\\trans c\n\\end{exe}')
def test_single_line(self): doc = common.MockDoc('html') filename = os.path.join('linguafilter', 'test_lexicon.csv') attributes = {'file': filename} div = pf.Div(pf.Para(pf.Str('{field1}, {field2}, and {field3}')), attributes=attributes, classes=['lexicon']) lexicon.parse(div, doc) self.assertEqual( pf.stringify(div), 'r1f1, r1f2, and r1f3\n\nr2f1, r2f2, a field, and r2f3\n\nr3f1, r3f2, and r3f3\n\n' )
def test_merge_root_multiple_nodes(self): doc = common.MockDoc('html') filename = os.path.join('linguafilter', 'test_lexicon.csv') attributes = {'file': filename, 'merge_root': 'foo'} div = pf.Div(pf.Para(pf.Str('{field1}')), pf.Para(pf.Str('{field2}')), attributes=attributes, classes=['lexicon']) with self.assertRaisesRegexp( Exception, 'if merge_root is specified, there can be only one node under the lexicon div' ): lexicon.parse(div, doc)
def test_invalid_content(self): doc = common.MockDoc('html') span = pf.Span(classes=['gloss']) with self.assertRaisesRegexp(Exception, 'invalid gloss syntax'): gloss.parse(span, doc) span = pf.Span(pf.Str('a'), pf.Str('b'), classes=['gloss']) with self.assertRaisesRegexp(Exception, 'invalid gloss syntax'): gloss.parse(span, doc) span = pf.Span(pf.Str('a'), pf.Str('b'), pf.Str('c'), pf.Str('d'), classes=['gloss']) with self.assertRaisesRegexp(Exception, 'invalid gloss syntax'): gloss.parse(span, doc)
def test_empty(self): doc = common.MockDoc('html') filename = os.path.join('linguafilter', 'test_lexicon.csv') div = pf.Div(attributes={'file': filename}, classes=['lexicon']) lexicon.parse(div, doc) self.assertEqual(pf.stringify(div), '')
def test_empty_html(self): doc = common.MockDoc('html') span = pf.Span(classes=['phonfeat']) phonfeat.parse(span, doc) self.assertEqual(pf.stringify(span), '[]')
def test_three_strs_latex(self): doc = common.MockDoc('latex') span = pf.Span(pf.Str('a'), pf.Str('b'), pf.Str('c'), classes=['phonfeat']) phonfeat.parse(span, doc) self.assertEqual(pf.stringify(span), '\\phonfeat{a \\\\ b \\\\ c}')
def test_empty_latex(self): doc = common.MockDoc('latex') span = pf.Span(classes=['phonfeat']) phonfeat.parse(span, doc) self.assertEqual(pf.stringify(span), '\\phonfeat{}')
def test_three_strs_html(self): doc = common.MockDoc('html') span = pf.Span(pf.Str('a'), pf.Str('b'), pf.Str('c'), classes=['phonfeat']) phonfeat.parse(span, doc) self.assertEqual(pf.stringify(span), '[a, b, c]')
def test_latex_with_space(self): doc = common.MockDoc('latex') span = pf.Span(pf.Str('A'), pf.Space(), pf.Str('B'), classes=['ipa']) ipa.parse(span, doc) self.assertEqual(pf.stringify(span), '\\textipa{A} \\textipa{B}')
def test_str(self): doc = common.MockDoc('html') span = pf.Span(pf.Str('A'), classes=['ipa']) ipa.parse(span, doc) self.assertEqual(pf.stringify(span), 'ɑ')
def test_no_str(self): doc = common.MockDoc('html') span = pf.Span(classes=['ipa']) ipa.parse(span, doc) self.assertEqual(pf.stringify(span), '')