allpy
changeset 853:6cc007e68af6
Allow markup to be tagged as saved / not saved (closes #83)
To tag markup as non-saved, add markup.save = False anywhere.
(You may add the attribute to a class to tag all markups of the
class as non-saved).
Also added some tests for this behaviour.
author | Daniil Alexeyevsky <dendik@kodomo.fbb.msu.ru> |
---|---|
date | Thu, 21 Jul 2011 13:12:54 +0400 |
parents | 077e5e18a600 |
children | 2f742e5de06b |
files | allpy/base.py allpy/fileio.py test/test_markups.py |
diffstat | 3 files changed, 13 insertions(+), 1 deletions(-) [+] |
line diff
1.1 --- a/allpy/base.py Wed Jul 20 20:44:59 2011 +0400 1.2 +++ b/allpy/base.py Thu Jul 21 13:12:54 2011 +0400 1.3 @@ -560,7 +560,10 @@ 1.4 """ 1.5 1.6 name = None 1.7 - """Name of markup elements""" 1.8 + """Name of markup elements.""" 1.9 + 1.10 + save = True 1.11 + """If set to false, fileio should not save this markup.""" 1.12 1.13 def __init__(self, container, name, **kwargs): 1.14 """Markup takes mandatory container and name and optional kwargs.
2.1 --- a/allpy/fileio.py Wed Jul 20 20:44:59 2011 +0400 2.2 +++ b/allpy/fileio.py Thu Jul 21 13:12:54 2011 +0400 2.3 @@ -153,6 +153,8 @@ 2.4 def write_markups(self, markups, type, pre_record={}): 2.5 """Write a dictionary of markups as series of records.""" 2.6 for name, markup in markups.items(): 2.7 + if not markup.save: 2.8 + continue 2.9 record = markup.to_record() 2.10 record.update(pre_record) 2.11 record['type'] = type
3.1 --- a/test/test_markups.py Wed Jul 20 20:44:59 2011 +0400 3.2 +++ b/test/test_markups.py Thu Jul 21 13:12:54 2011 +0400 3.3 @@ -82,6 +82,10 @@ 3.4 m2 = aln.add_markup('m2') 3.5 m2[c[5]] = 5 3.6 m2[c[6]] = 6 3.7 + m3 = aln.add_markup('m3', markup_class=MyAlignmentMarkup) 3.8 + m3.save = False 3.9 + m3[c[1]] = "hello" 3.10 + m4 = aln.add_markup('m4', markup_class=MyAlignmentMarkup) 3.11 3.12 file = StringIO() 3.13 aln.to_file(file, format='markup') 3.14 @@ -103,4 +107,7 @@ 3.15 assert s[5].m1 == 5 and s[3].m1 == 3 3.16 assert out.markups['m2'][c[5]] == 5 and out.markups['m2'][c[6]] == 6 3.17 3.18 + assert 'm3' not in out.markups 3.19 + assert out.markups['m4'].__class__ is MyAlignmentMarkup 3.20 + 3.21 # vim: set ts=4 sts=4 sw=4 et: