def test_record_with_tuple(self): record = (5, 'pikos', 'apikos') output = '5,pikos,apikos\r\n' recorder = CSVRecorder(self.temp) recorder.prepare(tuple) recorder.record(record) self.assertMultiLineEqual(self.temp.getvalue(), output)
def test_record_with_namedtuple(self): record = DummyRecord(5, 'pikos', 'apikos') output = 'one,two,three\r\n5,pikos,apikos\r\n' recorder = CSVRecorder(self.temp) recorder.prepare(DummyRecord) recorder.record(record) self.assertMultiLineEqual(self.temp.getvalue(), output)
def test_record(self): fields = ('one', 'two','three') values = (5, 'pikos','apikos') output = 'one,two,three\r\n5,pikos,apikos\r\n' recorder = CSVRecorder(self.temp) recorder.prepare(fields) recorder.record(values) self.assertMultiLineEqual(self.temp.getvalue(), output)
def test_record(self): fields = ('one', 'two', 'three') values = (5, 'pikos', 'apikos') output = 'one,two,three\r\n5,pikos,apikos\r\n' recorder = CSVRecorder(self.temp) recorder.prepare(fields) recorder.record(values) self.assertMultiLineEqual(self.temp.getvalue(), output)
def test_dialect(self): fields = ('one', 'two','three') values = [(5, 'pikos','apikos'), (12, 'emilios','milo')] output = 'one,two,three^5,pikos,apikos^12,emilios,milo^' recorder = CSVRecorder(self.temp, lineterminator='^') recorder.prepare(fields) for record in values: recorder.record(record) self.assertMultiLineEqual(self.temp.getvalue(), output)
def test_exception_when_no_prepare(self): values = [(5, 'pikos', 'apikos')] recorder = CSVRecorder(self.temp) with self.assertRaises(RecorderError): recorder.record(values) with self.assertRaises(RecorderError): recorder.finalize()
def test_dialect(self): fields = ('one', 'two', 'three') values = [(5, 'pikos', 'apikos'), (12, 'emilios', 'milo')] output = 'one,two,three^5,pikos,apikos^12,emilios,milo^' recorder = CSVRecorder(self.temp, lineterminator='^') recorder.prepare(fields) for record in values: recorder.record(record) self.assertMultiLineEqual(self.temp.getvalue(), output)
def test_exception_when_no_prepare(self): values = [(5, 'pikos', 'apikos')] recorder = CSVRecorder(self.temp) with self.assertRaises(RecorderError): recorder.record(values) with self.assertRaises(RecorderError): recorder.finalize()
def test_exceptions(self): fields = ('one', 'two','three') values = [(5, 'pikos','apikos')] recorder = CSVRecorder(self.temp) with self.assertRaises(RecorderError): recorder.record(values) with self.assertRaises(RecorderError): recorder.finalize()
def test_dialect(self): records = [ DummyRecord(5, 'pikos', 'apikos'), DummyRecord(12, 'emilios', 'milo')] output = 'one,two,three^5,pikos,apikos^12,emilios,milo^' recorder = CSVRecorder(self.temp, lineterminator='^') recorder.prepare(DummyRecord) for record in records: recorder.record(record) self.assertMultiLineEqual(self.temp.getvalue(), output)
def test_filter(self): fields = ('one', 'two','three') values = [(5, 'pikos','apikos'), (12, 'emilios','milo')] output = 'one,two,three\r\n12,emilios,milo\r\n' def not_pikos(values): return not 'pikos' in values recorder = CSVRecorder(self.temp, filter_=not_pikos) recorder.prepare(fields) for record in values: recorder.record(record) self.assertMultiLineEqual(self.temp.getvalue(), output)
def test_filter(self): fields = ('one', 'two', 'three') values = [(5, 'pikos', 'apikos'), (12, 'emilios', 'milo')] output = 'one,two,three\r\n12,emilios,milo\r\n' def not_pikos(values): return not 'pikos' in values recorder = CSVRecorder(self.temp, filter_=not_pikos) recorder.prepare(fields) for record in values: recorder.record(record) self.assertMultiLineEqual(self.temp.getvalue(), output)
def test_filter(self): records = [ DummyRecord(5, 'pikos', 'apikos'), DummyRecord(12, 'emilios', 'milo')] output = 'one,two,three\r\n12,emilios,milo\r\n' def not_pikos(records): return all('pikos' != record for record in records) recorder = CSVRecorder(self.temp, filter_=not_pikos) recorder.prepare(DummyRecord) for record in records: recorder.record(record) self.assertMultiLineEqual(self.temp.getvalue(), output)