def test_output_rendered_in_html(self): stream = StringIO() stream.write(u'A,B,C'.encode('utf-8')) stream.write(u'ő,ú,á'.encode('utf-8')) stream.write(u'é,ű,í'.encode('utf-8')) stream.seek(0) db = module.Database(stream) dct = { 'database': db, 'document_template': Template('{% for entry in entries %}{{entry}}{% endfor %}'), 'entry_template': Template('{{A}}, {{B}}, {{C}}'), 'output': StringIO(), 'encoding': 'html' } conf = module.Configuration(dct) document = conf.render_document() try: document.decode('ascii') except Exception: self.fail('Could not decode string as ascii.')
def test_returns_unicode_values(self): stream = StringIO() stream.write(u'A,B\nszőlőfeldolgozó,üzem'.encode('utf-8')) stream.seek(0) db = module.Database(stream) record = list(db.read())[0] for value in record.values(): self.assertIsInstance(value, unicode)
def test_returns_unicode_keys(self): stream = StringIO() stream.write(u'szőlőfeldolgozó,üzem\n1,2'.encode('utf-8')) stream.seek(0) db = module.Database(stream) record = list(db.read())[0] for key in record.keys(): self.assertIsInstance(key, unicode)
def test_render_document(self): db = module.Database(StringIO()) dct = { 'database': db, 'document_template': Template('A document.'), 'entry_template': Template(''), 'output': StringIO() } conf = module.Configuration(dct) self.assertEqual(conf.render_document(), 'A document.')
def test_entry_template_is_compiled(self): db = module.Database(StringIO()) dct = { 'database': db, 'document_template': Template(''), 'entry_template': Template(''), 'output': StringIO() } conf = module.Configuration(dct) self.assertIsInstance(conf.entry_template, Template)
def test_configuration_accepts_dictionary(self): db = module.Database(StringIO()) dct = { 'database': db, 'document_template': Template(''), 'entry_template': Template(''), 'output': StringIO() } conf = module.Configuration(dct) self.assertIsInstance(conf, module.Configuration)
def test_write_document(self): db = module.Database(StringIO()) output = StringIO() dct = { 'database': db, 'document_template': Template('A document.'), 'entry_template': Template(''), 'output': output } conf = module.Configuration(dct) conf.write_document() output.seek(0) self.assertEqual(output.read(), 'A document.')
def test_read_entries(self): stream = StringIO() stream.write('''A,B,C 1,2,3 4,5,6''') stream.seek(0) db = module.Database(stream) dct = { 'database': db, 'document_template': Template('A document.'), 'entry_template': Template(''), 'output': StringIO() } conf = module.Configuration(dct) [ self.assertIsInstance(entry, module.Entry) for entry in conf.read_entries() ]
def test_entry_has_filters(self): stream = StringIO() stream.write('''A,B,C 1,2,3 4,5,6''') stream.seek(0) db = module.Database(stream) dct = { 'database': db, 'document_template': Template('A document.'), 'entry_template': Template(''), 'output': StringIO(), 'filters': { 'A': ['split', 'join'] } } conf = module.Configuration(dct) self.assertDictEqual(conf.read_entries()[0].filters, {'A': ['split', 'join']})
def test_known_values(self): tmpf = self.create_test_file() db = list(module.Database(tmpf).read()) self.assertDictEqual(db[0], dict(A='1', B='2', C='3')) self.assertDictEqual(db[1], dict(A='2', B='4', C='6'))
def test_reader_preserves_order(self): tmpf = self.create_test_file() db = list(module.Database(tmpf).read()) self.failUnless(db[1]['A'] > db[0]['A'])
def test_accepts_stream(self): tmpf = self.create_test_file() db = module.Database(tmpf) self.assertIsInstance(db, module.Database)
def test_dictreader_is_returned(self): tmpf = self.create_test_file() db = module.Database(tmpf) self.assertIsInstance(db.read(), DictReader)
def test_accepts_utf8(self): stream = StringIO() stream.write(u'szőlőfeldolgozó,üzem\n1,2'.encode('utf-8')) stream.seek(0) db = module.Database(stream) self.assertIsInstance(db, module.Database)