2013-06-14 23:49:11 +03:00
|
|
|
#!/usr/bin/env python2.7
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
from unittest import TestCase
|
|
|
|
|
|
|
|
import output
|
|
|
|
|
2013-06-15 00:05:42 +03:00
|
|
|
class FakeTemplates(object):
|
|
|
|
def __init__(self, d):
|
|
|
|
self.d = d
|
|
|
|
|
|
|
|
def get(self, name):
|
|
|
|
if name in self.d:
|
|
|
|
return self.d[name]
|
|
|
|
else:
|
|
|
|
return ''
|
|
|
|
|
2013-06-14 23:49:11 +03:00
|
|
|
class TestOutputFormat(TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_create(self):
|
2013-06-15 00:05:42 +03:00
|
|
|
of = output.OutputFormat(FakeTemplates({}), str)
|
|
|
|
|
2013-06-15 00:24:43 +03:00
|
|
|
def test_format_begin(self):
|
2013-06-15 00:05:42 +03:00
|
|
|
of = output.OutputFormat(FakeTemplates({'begin' : 'b %(max)d'}), str)
|
2013-06-15 00:24:43 +03:00
|
|
|
self.assertEqual(of.format_begin({'max' : 2}), 'b 2')
|
2013-06-14 23:49:11 +03:00
|
|
|
|
|
|
|
class TestReferenceFormatter(TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_create(self):
|
2013-06-20 23:59:25 +03:00
|
|
|
rf = output.ReferenceFormatter(1, {}, None, "", str)
|
2013-06-14 23:49:11 +03:00
|
|
|
|
|
|
|
def test_get_item(self):
|
2013-06-20 23:59:25 +03:00
|
|
|
rf = output.ReferenceFormatter(1, {'a' : 1, 'b' : 2}, None,
|
|
|
|
"%(nr)d", int)
|
2013-06-14 23:49:11 +03:00
|
|
|
self.assertEqual(rf['nr'], 1)
|
|
|
|
|
|
|
|
def test_get_quoted_item(self):
|
2013-06-20 23:59:25 +03:00
|
|
|
rf = output.ReferenceFormatter(1, {'a' : 1, 'b' : 2}, None,
|
|
|
|
"%(nr)d", str)
|
2013-06-14 23:49:11 +03:00
|
|
|
self.assertEqual(rf['nr'], '1')
|
|
|
|
|
|
|
|
def test_get_reference(self):
|
2013-06-20 23:59:25 +03:00
|
|
|
rf = output.ReferenceFormatter(1, {'a' : 1, 'b' : 2}, None,
|
2013-06-14 23:49:11 +03:00
|
|
|
"%(from_nr)d to %(nr)d", None)
|
|
|
|
self.assertEqual(rf['b'], '1 to 2')
|
|
|
|
self.assertEquals(rf.found, set(['1 to 2']))
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|