def test_reads_unicode(self): reader = udr.UnicodeDictReader(h.fixture_file('simple.csv')) lines = [ l for l in reader ] h.assert_true(isinstance(lines[0].keys()[0], unicode), "Keys in UnicodeDictReader dicts should be unicode.") h.assert_true(isinstance(lines[0].values()[0], unicode), "Values in UnicodeDictReader dicts should be unicode.")
from openspending.lib import ckan from openspending.lib import json from openspending.test import TestCase, helpers as h MOCK_REGISTRY = json.load(h.fixture_file('mock_ckan.json')) class TestCkan(TestCase): def setup(self): super(TestCkan, self).setup() self.patcher = h.patch('openspending.lib.ckan.CkanClient', spec=ckan.CkanClient) self.MockCkanClient = self.patcher.start() self.MockCkanClient.return_value = self.c = h.mock_ckan(MOCK_REGISTRY) def teardown(self): self.patcher.stop() super(TestCkan, self).teardown() def test_make_client(self): h.assert_equal(ckan.make_client(), self.c) self.MockCkanClient.return_value = None h.assert_equal(ckan.make_client(), None) def test_get_client(self): h.assert_equal(ckan.get_client(), self.c) # singleton now created, so this should have no effect. self.MockCkanClient.return_value = None h.assert_equal(ckan.get_client(), self.c) def test_package_init(self):
def test_reads_simple_csv(self): reader = udr.UnicodeDictReader(h.fixture_file('simple.csv')) lines = [ l for l in reader ] h.assert_equal(lines[0], {'a': '1', 'b': '2', 'c': 'foo'}) h.assert_equal(lines[1], {'a': '3', 'b': '4', 'c': 'bar'})
def test_raises_on_empty_csv(self): reader = udr.UnicodeDictReader(h.fixture_file('empty.csv')) lines = [ l for l in reader ]