| Home | Trees | Index | Help |
|---|
| Package Pootle :: Package storage :: Module test_ddtp |
|
| Function Summary | |
|---|---|
Some setup: | |
Tests for DDTPModule.parse_template. | |
Tests for DDTPModule.parse_translation(). | |
Tests for importing RFC822-style package info. | |
Tests for importing RFC822-style package info. | |
Test of DDTPStore.load() | |
| Variable Summary | |
|---|---|
str |
sample_template = '\nPackage: abook\nPriority: optional\...
|
str |
sample_translation = '\nPackage: sample\nDescription-md5...
|
| Function Details |
|---|
test_DDTP_import_template()
>>> from Pootle.storage.ddtp import DDTPModule
>>> template = StringIO(sample_template)
Some setup:
>>> from Pootle.storage.memory import Database
>>> db = Database()
>>> folder = db.root.subfolders.add('ddtp')
>>> ddtpmodule = DDTPModule(folder)
Do the import:
>>> ddtpmodule.import_template(template)
The strings have ended up in the template:
>>> modulename = folder.modules.keys()[0]
>>> module = folder.modules[modulename]
>>> for unit in module.template: ... msgid, translation = unit.trans[0] ... print unit.comments['automatic'] ... print msgid[:20], '... -', translation and translation[:20] ... # doctest: +REPORT_UDIFF ['abook (1/2) MD5: b3df98dd5a16801ef603bb31eff45bf6'] text-based ncurses a ... - None ['abook (2/2) MD5: b3df98dd5a16801ef603bb31eff45bf6'] abook is a text-base ... - None ['aap (1/2) MD5: 709f30bc0912c0a4fd248e9ba50e6c78'] make-like "expert sy ... - None ['aap (2/2) MD5: 709f30bc0912c0a4fd248e9ba50e6c78'] A-A-P is a dependenc ... - NoneNow, let's import a few translations:
>>> trans = StringIO(sample_translation)
>>> ddtpmodule.import_translations([trans])
Now let's look at the translation:
>>> module.keys() ['de'] >>> for unit in module['de']: ... msgid, translation = unit.trans[0] ... print unit.comments['automatic'] ... print msgid[:20], '... -', translation and translation[:20] ['abook (1/2) MD5: b3df98dd5a16801ef603bb31eff45bf6'] text-based ncurses a ... - Ein textbasiertes Ad ['abook (2/2) MD5: b3df98dd5a16801ef603bb31eff45bf6'] abook is a text-base ... - Abook ist ein textba ['aap (1/2) MD5: 709f30bc0912c0a4fd248e9ba50e6c78'] make-like "expert sy ... - None ['aap (2/2) MD5: 709f30bc0912c0a4fd248e9ba50e6c78'] A-A-P is a dependenc ... - None |
test_DDTPModule_parse_template()Tests for DDTPModule.parse_template. Let's parse some samples from a typical Packages listing:
>>> from Pootle.storage.ddtp import DDTPModule
>>> module = DDTPModule(None)
>>> f = StringIO(sample_template)
>>> result = module.parse_template(f)
>>> for (name, md5sum, description) in result: ... print '%s (MD5: %s)' % (name, md5sum) ... print description abook (MD5: b3df98dd5a16801ef603bb31eff45bf6) text-based ncurses address book application abook is a text-based ncurses address book application. It provides many different fields of user info. abook is designed for use with mutt, but can be used independently. <BLANKLINE> aap (MD5: 709f30bc0912c0a4fd248e9ba50e6c78) make-like "expert system" for building software A-A-P is a dependency rule-based software build system like make. It eliminates many of the warts of GNU Make and can evaluate Python code embedded in the scripts. <BLANKLINE> |
test_DDTPModule_parse_translation()Tests for DDTPModule.parse_translation(). Let's parse a German translation
>>> from Pootle.storage.ddtp import DDTPModule
>>> module = DDTPModule(None)
>>> f = StringIO(sample_translation)
>>> lang, result = module.parse_translation(f) >>> lang 'de' >>> for (name, md5sum, description) in result: ... print '%s (MD5: %s)' % (name, md5sum) ... print description.encode('utf-8') sample (MD5: f00f00f00f00f00f00f00f00f00f00f0) Beispiel Eines kleines Beispiel. <BLANKLINE> abook (MD5: b3df98dd5a16801ef603bb31eff45bf6) Ein textbasiertes Adressbuch-Programm mit ncurses Abook ist ein textbasiertes Adressbuch-Programm mit ncurses. Es stellt viele verschiedene Felder von Benutzerinformationen zur Verfügung. Abook wurde für die Verwendung mit mutt entwickelt, aber kann auch unabhängig davon benutzt werden. <BLANKLINE> |
test_DDTPPackage_export()
Tests for importing RFC822-style package info.
A simple case:
>>> from Pootle.storage.ddtp import DDTPPackage
>>> package = DDTPPackage('pack', '123abc',
... [('short', 'kurz'), ('detailed', 'zugeteilt')])
>>> print package.export('zz')
Package: pack
Description-md5: 123abc
Description-zz: kurz
zugeteilt
<BLANKLINE>
Test paragraph wrapping:
>>> package.paras = [('', 'short'),
... ('', 'This is a ' + 'long ' * 30 + 'paragraph.')]
>>> print package.export('zz')
Package: pack
Description-md5: 123abc
Description-zz: short
This is a long long long long long long long long long long long long long
long long long long long long long long long long long long long long long
long long paragraph.
<BLANKLINE>
Description
-----------
Formatting the description is a little problematic. We'll test some
corner cases:
>>> package._export_description([" don't\n touch\n this"])
" don't\n touch\n this"
>>> package._export_description([" don't\n touch\n this either," +
... " understand?" * 10])
" don't\n touch\n this either, understand? understand? understand? understand? understand? understand? understand? understand? understand? understand?"
TODO: Is this really the behaviour we want (the documentation seems
to imply so)? Should we wrap the long line instead?
>>> print package._export_description(
... ["wrap " + "this line " * 10 + "\n"
... " but not" + " this one" * 10 + ",\n"
... "but this one" + " too" * 50])
... # doctest: +REPORT_UDIFF
wrap this line this line this line this line this line this line this line
this line this line this line
but not this one this one this one this one this one this one this one this one this one this one,
but this one too too too too too too too too too too too too too too too
too too too too too too too too too too too too too too too too too too too
too too too too too too too too too too too too too too too too
Silly example:
>>> print package._export_description(['', '', ''])
<BLANKLINE>
.
<BLANKLINE>
.
<BLANKLINE>
|
test_DDTPPackage_import_descriptions()Tests for importing RFC822-style package info.
>>> from Pootle.storage.ddtp import DDTPPackage
>>> package = DDTPPackage('pack', '123abc')
Simple case:
>>> package.import_description(u'pack\n some package\n', ... u'pak\n som pakag\n') >>> package.paras [(u'pack', u'pak'), (u'some package', u'som pakag')]No translation: >>> package.import_description(u'pack\n some package\n', None) >>> package.paras [(u'pack', None), (u'some package', None)]Check validation: >>> package.import_description(u'pack\n some package\n', ... u'pak\n too\n many\n .\n pakag\n') Traceback (most recent call last): ... AssertionError: [u'pak', u'too many', u'pakag']Let's test the _split() method more carefully: >>> package._split('short\n one\n wrapped\n sentence.\n') ['short', 'one wrapped sentence.'] >>> package._split('short\n' ... ' first\n' ... ' paragraph.\n' ... ' .\n' ... ' second paragraph.\n') ['short', 'first paragraph.', 'second paragraph.']Indented lines are not reformatted: >>> package._split('short\n' ... ' As for this:\n' ... ' leave\n' ... ' it\n' ... ' be,\n' ... ' but unwrap\n' ... ' this too.\n') ['short', 'As for this:\n leave\n it\n be, but unwrap this too.']TODO: Do we really want to connect "be," with "but unwrap" here? Docs would seem to indicate otherwise, but, e.g., the description of gnome-terminal would use this behaviour. |
test_DDTPStore_load()Test of DDTPStore.load()
>>> from Pootle.storage.ddtp import DDTPModule, DDTPStore
>>> from Pootle.storage.memory import Database
>>> folder = Database().root.subfolders.add('ddtp')
We will need to plant some information in the folder:
>>> module = folder.modules.add('a')
>>> store = module.add('de')
Some drudgery for a couple examples:
>>> units = []
>>> def addunit(package, desc, trans, i, total, md5):
... unit = store.makeunit([(desc, trans)])
... comment = '%s (%s/%s) MD5: %s' % (package, i, total, md5)
... unit.comments.add('automatic', comment)
... units.append(unit)
>>> addunit('kitchen', 'stool', 'der Stuhl', 1, 3, 'f00f00')
>>> addunit('kitchen', 'table', 'der Tisch', 2, 3, 'f00f00')
>>> addunit('kitchen', 'glass', 'das Glas', 3, 3, 'f00f00')
>>> addunit('bedroom', 'bed', 'das Bett', 1, 1, 'faafaafaa')
>>> store.fill(units)
Do the import:
>>> ddtpmodule = DDTPModule(folder)
>>> ddtpstore = DDTPStore(ddtpmodule, 'de')
>>> ddtpstore.load()
>>> for package in ddtpstore.list_packages(): ... print package.name, ' MD5:', package.md5sum ... print package.paras bedroom MD5: faafaafaa [('bed', 'das Bett')] kitchen MD5: f00f00 [('stool', 'der Stuhl'), ('table', 'der Tisch'), ('glass', 'das Glas')] |
| Variable Details |
|---|
sample_template
|
| Home | Trees | Index | Help |
|---|
| Generated by Epydoc 2.1 on Tue Aug 22 04:29:46 2006 | http://epydoc.sf.net |