Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_filter_context_4(self):
db = LatexContextDb()
db.set_unknown_macro_spec(MacroSpec(''))
db.set_unknown_environment_spec(EnvironmentSpec(''))
db.add_context_category('cat1',
[ std_macro('aaa', '{'), std_macro('bbb', '[{[') ],
[ std_environment('eaaa', '{'), std_environment('ebbb', '[{[') ])
db.add_context_category('cat2',
[ std_macro('aaa', '[{'), std_macro('ccc', None) ],
[ std_environment('eaaa', '[{'), std_environment('eccc', None) ])
db.add_context_category('cat3',
[ std_macro('ccc', '*{'), std_macro('ddd', '{{[') ],
[ std_environment('eccc', '*{'), std_environment('eddd', '{{[') ],
prepend=True)
db2 = db.filter_context(keep_categories=['cat1', 'cat3'], exclude_categories=['cat3'],
keep_which=['environments'])
# no macros should exist any longer
self.assertEqual(db2.get_macro_spec('aaa').macroname, '')
self.assertEqual(db2.get_macro_spec('aaa').args_parser.argspec, '')
self.assertEqual(db2.get_macro_spec('ddd').macroname, '')
self.assertEqual(db2.get_macro_spec('ddd').args_parser.argspec, '')
# this should give 'eaaa' from cat1
self.assertEqual(db2.get_environment_spec('eaaa').environmentname, 'eaaa')
self.assertEqual(db2.get_environment_spec('eaaa').args_parser.argspec, '{')
def test_filter_context_2(self):
db = LatexContextDb()
db.set_unknown_macro_spec(MacroSpec(''))
db.set_unknown_environment_spec(EnvironmentSpec(''))
db.add_context_category('cat1',
[ std_macro('aaa', '{'), std_macro('bbb', '[{[') ],
[ std_environment('eaaa', '{'), std_environment('ebbb', '[{[') ])
db.add_context_category('cat2',
[ std_macro('aaa', '[{'), std_macro('ccc', None) ],
[ std_environment('eaaa', '[{'), std_environment('eccc', None) ])
db.add_context_category('cat3',
[ std_macro('ccc', '*{'), std_macro('ddd', '{{[') ],
[ std_environment('eccc', '*{'), std_environment('eddd', '{{[') ],
prepend=True)
db2 = db.filter_context(keep_categories=['cat1', 'cat3'], exclude_categories=['cat3'])
# this should give 'aaa' from cat1
self.assertEqual(db2.get_macro_spec('aaa').macroname, 'aaa')
self.assertEqual(db2.get_macro_spec('aaa').args_parser.argspec, '{')
# this should no longer exist
self.assertEqual(db2.get_macro_spec('ddd').macroname, '')
self.assertEqual(db2.get_macro_spec('ddd').args_parser.argspec, '')
def test_filter_context_3(self):
db = LatexContextDb()
db.set_unknown_macro_spec(MacroSpec(''))
db.set_unknown_environment_spec(EnvironmentSpec(''))
db.add_context_category('cat1',
[ std_macro('aaa', '{'), std_macro('bbb', '[{[') ],
[ std_environment('eaaa', '{'), std_environment('ebbb', '[{[') ])
db.add_context_category('cat2',
[ std_macro('aaa', '[{'), std_macro('ccc', None) ],
[ std_environment('eaaa', '[{'), std_environment('eccc', None) ])
db.add_context_category('cat3',
[ std_macro('ccc', '*{'), std_macro('ddd', '{{[') ],
[ std_environment('eccc', '*{'), std_environment('eddd', '{{[') ],
prepend=True)
db2 = db.filter_context(keep_categories=['cat1', 'cat3'], exclude_categories=['cat3'],
keep_which=['macros'])
# this should give 'aaa' from cat1
self.assertEqual(db2.get_macro_spec('aaa').macroname, 'aaa')
self.assertEqual(db2.get_macro_spec('aaa').args_parser.argspec, '{')
# this should no longer exist
self.assertEqual(db2.get_macro_spec('ddd').macroname, '')
self.assertEqual(db2.get_macro_spec('ddd').args_parser.argspec, '')
# no environments should exist any longer
self.assertEqual(db2.get_environment_spec('eaaa').environmentname, '')
def test_can_get_environment_spec(self):
db = LatexContextDb()
db.set_unknown_environment_spec(EnvironmentSpec(''))
db.add_context_category('cat1', [],
[ std_environment('eaaa', '{'), std_environment('ebbb', '[{[') ])
db.add_context_category('cat2', [],
[ std_environment('eaaa', '[{'), std_environment('eccc', None) ])
db.add_context_category('cat3', [],
[ std_environment('eccc', '*{'), std_environment('eddd', '{{[') ],
prepend=True)
self.assertEqual(list(db.categories()), ['cat3', 'cat1', 'cat2'])
self.assertEqual(db.get_environment_spec('eaaa').environmentname, 'eaaa')
self.assertEqual(db.get_environment_spec('eaaa').args_parser.argspec, '{')
self.assertEqual(db.get_environment_spec('ebbb').environmentname, 'ebbb')
self.assertEqual(db.get_environment_spec('ebbb').args_parser.argspec, '[{[')
self.assertEqual(db.get_environment_spec('eccc').environmentname, 'eccc')
self.assertEqual(db.get_environment_spec('eccc').args_parser.argspec, '*{')
'environments': [
EnvironmentSpec('verbatim',
args_parser=VerbatimArgsParser(verbatim_arg_type='verbatim-environment')),
],
'specials': [
# optionally users could include the specials "|" like in latex-doc
# for verbatim |\like \this|...
]}),
#
# CATEGORY: theorems
#
('theorems', {
'macros': [],
'environments': [
std_environment('theorem', '['),
std_environment('proposition', '['),
std_environment('lemma', '['),
std_environment('corollary', '['),
std_environment('definition', '['),
std_environment('conjecture', '['),
std_environment('remark', '['),
#
std_environment('proof', '['),
# short names
std_environment('thm', '['),
std_environment('prop', '['),
std_environment('lem', '['),
std_environment('cor', '['),
std_environment('conj', '['),
std_environment('rem', '['),
std_environment('defn', '['),
('theorems', {
'macros': [],
'environments': [
std_environment('theorem', '['),
std_environment('proposition', '['),
std_environment('lemma', '['),
std_environment('corollary', '['),
std_environment('definition', '['),
std_environment('conjecture', '['),
std_environment('remark', '['),
#
std_environment('proof', '['),
# short names
std_environment('thm', '['),
std_environment('prop', '['),
std_environment('lem', '['),
std_environment('cor', '['),
std_environment('conj', '['),
std_environment('rem', '['),
std_environment('defn', '['),
],
'specials': [
]}),
#
# CATEGORY: enumitem
#
('enumitem', {
'macros': [],
'environments': [
std_environment('enumerate', '['),
std_environment('itemize', '['),
'environments': [
std_environment('theorem', '['),
std_environment('proposition', '['),
std_environment('lemma', '['),
std_environment('corollary', '['),
std_environment('definition', '['),
std_environment('conjecture', '['),
std_environment('remark', '['),
#
std_environment('proof', '['),
# short names
std_environment('thm', '['),
std_environment('prop', '['),
std_environment('lem', '['),
std_environment('cor', '['),
std_environment('conj', '['),
std_environment('rem', '['),
std_environment('defn', '['),
],
'specials': [
]}),
#
# CATEGORY: enumitem
#
('enumitem', {
'macros': [],
'environments': [
std_environment('enumerate', '['),
std_environment('itemize', '['),
std_environment('description', '['),
],
std_environment('tabular', '{'),
std_environment('tabular*', '{{'),
std_environment('tabularx', '{[{'),
std_environment('array', '[{'),
std_environment('equation', None, is_math_mode=True),
std_environment('equation*', None, is_math_mode=True),
std_environment('eqnarray', None, is_math_mode=True),
std_environment('eqnarray*', None, is_math_mode=True),
# AMS environments
std_environment('align', None, is_math_mode=True),
std_environment('align*', None, is_math_mode=True),
std_environment('gather', None, is_math_mode=True),
std_environment('gather*', None, is_math_mode=True),
std_environment('flalign', None, is_math_mode=True),
std_environment('flalign*', None, is_math_mode=True),
std_environment('multline', None, is_math_mode=True),
std_environment('multline*', None, is_math_mode=True),
std_environment('alignat', '{', is_math_mode=True),
std_environment('alignat*', '{', is_math_mode=True),
std_environment('split', None, is_math_mode=True),
],
'specials': [
std_specials('&'),
# TODO --- for this, we need to parse their argument but don't use
# the standard args parser because we need to be able to
# accept arguments like "x_\mathrm{initial}"
#
#std_specials('^'),
std_environment('proposition', '['),
std_environment('lemma', '['),
std_environment('corollary', '['),
std_environment('definition', '['),
std_environment('conjecture', '['),
std_environment('remark', '['),
#
std_environment('proof', '['),
# short names
std_environment('thm', '['),
std_environment('prop', '['),
std_environment('lem', '['),
std_environment('cor', '['),
std_environment('conj', '['),
std_environment('rem', '['),
std_environment('defn', '['),
],
'specials': [
]}),
#
# CATEGORY: enumitem
#
('enumitem', {
'macros': [],
'environments': [
std_environment('enumerate', '['),
std_environment('itemize', '['),
std_environment('description', '['),
],
'specials': [
]}),
std_environment('lem', '['),
std_environment('cor', '['),
std_environment('conj', '['),
std_environment('rem', '['),
std_environment('defn', '['),
],
'specials': [
]}),
#
# CATEGORY: enumitem
#
('enumitem', {
'macros': [],
'environments': [
std_environment('enumerate', '['),
std_environment('itemize', '['),
std_environment('description', '['),
],
'specials': [
]}),
#
# CATEGORY: natbib
#
('natbib', {
'macros': [
std_macro('cite', '*[[{'),
std_macro('citet', '*[[{'),
std_macro('citep', '*[[{'),
std_macro('citealt', '*[[{'),
std_macro('citealp', '*[[{'),