def test_reader(self): from clld.lib.dsv import reader lines = ['first\tline', 'sücond\tläneß'] encoded_lines = [l.encode('utf8') for l in lines] csv_lines = [l.replace('\t', ',') for l in lines] def check(r): res = list(r) assert len(res) == 2 assert res[1][1] == 'läneß' check(reader(lines)) for lt in ['\n', '\r\n', '\r']: check(reader(StringIO(str(lt).join(encoded_lines)))) check(reader(TESTS_DIR.joinpath('csv.txt'), delimiter=',')) res = list(reader(TESTS_DIR.joinpath('test.tab'), namedtuples=True)) assert res[0].a_name == 'b' # Missing column values should be set to None: assert res[2].a_name is None r = list(reader(lines, dicts=True)) assert len(r) == 1 and r[0]['first'] == 'sücond' r = list(reader(lines, namedtuples=True)) assert len(r) == 1 and r[0].first == 'sücond' r = list(reader(csv_lines, namedtuples=True, delimiter=',')) assert len(r) == 1 and r[0].first == 'sücond'
def test_setup_session(self): from clld.scripts.util import setup_session res = setup_session( '%s#main' % TESTS_DIR.joinpath('test.ini').as_posix(), create_engine('sqlite://')) self.assertEquals(res, 'tests')
def test_Client(self): from clld.lib.fmpxml import Client r = Mock(text=file(TESTS_DIR.joinpath('fmpxmlresult.xml')).read().decode('utf8')) with patch('clld.lib.fmpxml.requests', Mock(get=lambda *a, **kw: r)): c = Client(None, None, None, None, verbose=False) c.get('stuff') c.get('stuff')
def test_Client(self): from clld.lib.fmpxml import Client r = Mock(text=file(TESTS_DIR.joinpath( 'fmpxmlresult.xml')).read().decode('utf8')) with patch('clld.lib.fmpxml.requests', Mock(get=lambda *a, **kw: r)): c = Client(None, None, None, None, verbose=False) c.get('stuff') c.get('stuff')
def test_Database(self): from clld.lib.bibtex import Record, Database db = Database([]) self.assertEqual(len(db), 0) db = Database([Record('book', 'id')]) self.assertEqual(db[0], db['id']) assert unicode(db) db = Database.from_file('notexisting.bib') self.assertEqual(len(db), 0) db = Database.from_file(TESTS_DIR.joinpath('test.bib')) self.assertEqual(len(db), 1)
def test_Database(self): from clld.lib.bibtex import Record, Database db = Database([]) self.assertEqual(len(db), 0) db = Database([Record('book', 'id')]) self.assertEqual(db[0], db['id']) assert text_type(db) db = Database.from_file('notexisting.bib') self.assertEqual(len(db), 0) db = Database.from_file(TESTS_DIR.joinpath('test.bib')) self.assertEqual(len(db), 1) assert '@' in db[0]['title'] assert [r for r in db] self.assertRaises(NotImplementedError, db.format, 'txt')
def test_add_config_from_file(self): from clld.web.app import add_settings_from_file config = Configurator() add_settings_from_file(config, TESTS_DIR.joinpath('test.ini')) assert 'app:main.use' in config.registry.settings
def test_Result(self): from clld.lib.imeji import file_urls res = list(file_urls(TESTS_DIR.joinpath("imeji_items.xml").as_posix())) self.assertEqual(len(res), 6)
def get_result(self): return TESTS_DIR.joinpath('fmpxmlresult.xml').open(encoding='utf8').read()
def test_get_config(self): from clld.config import get_config cfg = get_config(TESTS_DIR.joinpath('test.ini').as_posix()) self.assertEqual(cfg['app:main.custom_int'], 5)
def test_parsed_args(self): from clld.scripts.util import parsed_args parsed_args(args=[TESTS_DIR.joinpath('test.ini').as_posix()])
def test_Result(self): from clld.lib.imeji import file_urls res = list(file_urls(TESTS_DIR.joinpath('imeji_items.xml').as_posix())) self.assertEqual(len(res), 6)
def test_Result(self): from clld.lib.fmpxml import Result r = Result(file(TESTS_DIR.joinpath('fmpxmlresult.xml')).read())
def test_Result(self): from clld.lib.fmpxml import Result Result(file(TESTS_DIR.joinpath('fmpxmlresult.xml')).read())
def test_add_config_from_file(self): from clld.web.app import add_settings_from_file config = Configurator() add_settings_from_file(config, TESTS_DIR.joinpath("test.ini")) assert "app:main.use" in config.registry.settings
def get_result(self): return TESTS_DIR.joinpath('fmpxmlresult.xml').open( encoding='utf8').read()