Пример #1
0
 def test_can_write_delimited_data_to_path(self):
     delimited_data_format = data.DataFormat(data.FORMAT_DELIMITED)
     delimited_data_format.set_property(data.KEY_ENCODING, 'utf-8')
     delimited_data_format.validate()
     delimited_path = dev_test.path_to_test_result('test_can_write_delimited_to_path.csv')
     with io.open(delimited_path, 'w', newline='', encoding=delimited_data_format.encoding) as delimited_target_stream:
         with rowio.DelimitedRowWriter(delimited_target_stream, delimited_data_format) as delimited_writer:
             delimited_writer.write_row(['a', 'b', _EURO_SIGN])
             delimited_writer.write_row([])
             delimited_writer.write_row([1, 2, 'end'])
     with io.open(delimited_path, 'r', encoding=delimited_data_format.encoding) as delimited_source_stream:
         # Note: all kinds of newline characters are translated to '\n' because of newline=None.
         data_written = delimited_source_stream.read()
     self.assertEqual('%r' % data_written, '%r' % 'a,b,\u20ac\n\n1,2,end\n')
Пример #2
0
 def test_fails_on_unicode_error_during_fixed_write(self):
     fixed_data_format = data.DataFormat(data.FORMAT_FIXED)
     fixed_data_format.set_property(data.KEY_ENCODING, 'ascii')
     fixed_data_format.validate()
     fixed_path = dev_test.path_to_test_result('test_fails_on_unicode_error_during_fixed_write.txt')
     with rowio.FixedRowWriter(fixed_path, fixed_data_format, [('x', 1)]) as fixed_writer:
         fixed_writer.write_row(['a'])
         try:
             fixed_writer.write_row([_EURO_SIGN])
             self.fail()
         except errors.DataError as anticipated_error:
             anticipated_error_message = str(anticipated_error)
             dev_test.assert_fnmatches(
                 self, anticipated_error_message, "*.txt (R2C1): cannot write data row: *; row=*")
Пример #3
0
 def test_fails_on_unicode_error_during_delimited_write(self):
     delimited_data_format = data.DataFormat(data.FORMAT_DELIMITED)
     delimited_data_format.set_property(data.KEY_ENCODING, 'ascii')
     delimited_data_format.validate()
     delimited_path = dev_test.path_to_test_result('test_fails_on_unicode_error_during_delimited_write.csv')
     with io.open(delimited_path, 'w', newline='', encoding=delimited_data_format.encoding) as delimited_target_stream:
         with rowio.DelimitedRowWriter(delimited_target_stream, delimited_data_format) as delimited_writer:
             try:
                 delimited_writer.write_row(['a'])
                 delimited_writer.write_row(['b', _EURO_SIGN])
                 self.fail()
             except errors.DataError as anticipated_error:
                 anticipated_error_message = str(anticipated_error)
                 dev_test.assert_fnmatches(
                     self, anticipated_error_message, "*.csv (R2C1): cannot write data row: *; row=*'b', *")
Пример #4
0
 def test_fails_on_broken_sheet(self):
     source_ods_path = dev_test.path_to_test_data('valid_customers.ods')
     target_path = dev_test.path_to_test_result('valid_customers_from__ods.csv')
     self.assertRaises(SystemExit, _ods.main, ['--sheet=x', source_ods_path, target_path])
     self.assertRaises(SystemExit, _ods.main, ['--sheet=0', source_ods_path, target_path])
     self.assertRaises(SystemExit, _ods.main, ['--sheet=17', source_ods_path, target_path])
Пример #5
0
 def test_fails_on_kinky_file_name(self):
     source_ods_path = dev_test.path_to_test_data('valid_customers.ods')
     target_path = dev_test.path_to_test_result('kinky_file_name//\\:^$\\::/')
     self.assertRaises(SystemExit, _ods.main, [source_ods_path, target_path])
Пример #6
0
 def test_can_convert_ods_to_rst(self):
     source_ods_path = dev_test.path_to_test_data('valid_customers.ods')
     target_path = dev_test.path_to_test_result('valid_customers_from__ods.rst')
     _ods.main(['--format=rst', source_ods_path, target_path])
Пример #7
0
 def test_can_convert_ods_to_csv(self):
     source_ods_path = dev_test.path_to_test_data('valid_customers.ods')
     target_path = dev_test.path_to_test_result('valid_customers_from__ods.csv')
     _ods.main([source_ods_path, target_path])