コード例 #1
0
 def test_text_file_io_basic_text_data_write_without_cache(self):
     tfio = TextFileIO(file_folder_path='.', file_name='WRITE_TEST')
     gdc = GenericDataContainer(result_set_name=tfio.uri, data_type=str)
     gdc.store(data='Some More Test Data')
     tfio.write(data=gdc)
     with open('WRITE_TEST', 'r') as f:
         text_data = f.readline()
         self.assertIsNotNone(text_data)
         self.assertIsInstance(text_data, str)
         self.assertEqual('Some More Test Data', text_data)
コード例 #2
0
 def test_text_file_io_basic_text_data_write_with_cache(self):
     tfio = TextFileIO(file_folder_path='.',
                       file_name='WRITE_TEST',
                       enable_cache=True)
     text_data = 'TEST'
     gdp = GenericDataContainer(data_type=str)
     gdp.store(data=text_data)
     tfio.write(data=gdp)
     os.remove('WRITE_TEST')
     result = tfio.read()
     self.assertIsNotNone(result)
     self.assertIsInstance(result, GenericDataContainer)
     self.assertEqual('TEST', result.data)
コード例 #3
0
 def test_text_file_io_basic_text_data_write(self):
     tfio = TextFileIO(file_folder_path='.', file_name='WRITE_TEST')
     text_data = 'TEST'
     gdp = GenericDataContainer(data_type=str)
     gdp.store(data=text_data)
     tfio.write(data=gdp)
     result = ''
     lines = list()
     with open('WRITE_TEST', 'r') as f:
         lines = f.readlines()
     result = ''.join(lines)
     self.assertIsNotNone(result)
     self.assertIsInstance(result, str)
     self.assertEqual('TEST', result)
コード例 #4
0
 def test_text_file_io_basic_text_data_write_dict_as_json(self):
     tfio = TextFileIO(file_folder_path='.', file_name='WRITE_TEST')
     gdp = GenericDataContainer(data_type=dict)
     gdp.store(data=True, key='DidItWork')
     tfio.write(data=gdp)
     lines = list()
     with open('WRITE_TEST', 'r') as f:
         lines = f.readlines()
     result = json.loads(''.join(lines))
     self.assertIsNotNone(result)
     self.assertIsInstance(result, dict)
     self.assertEqual(1, len(result))
     self.assertTrue('DidItWork' in result)
     self.assertIsInstance(result['DidItWork'], bool)
     self.assertTrue(result['DidItWork'])
コード例 #5
0
 def test_text_file_io_basic_text_data_write_list_as_string(self):
     tfio = TextFileIO(file_folder_path='.', file_name='WRITE_TEST')
     gdp = GenericDataContainer(data_type=list)
     gdp.store(data=1)
     gdp.store(data=2)
     gdp.store(data=3)
     tfio.write(data=gdp)
     lines = list()
     with open('WRITE_TEST', 'r') as f:
         lines = f.readlines()
     result = ''.join(lines)
     self.assertIsNotNone(result)
     self.assertIsInstance(result, str)
     self.assertTrue('[' in result)
     self.assertTrue(']' in result)
     self.assertTrue('1' in result)
     self.assertTrue('2' in result)
     self.assertTrue('3' in result)
     self.assertTrue(',' in result)
コード例 #6
0
 def test_text_file_io_basic_text_data_write_without_cache_with_invalid_write_processor(
         self):
     iop = 'This is not a real processor'
     gdc_result = GenericDataContainer(result_set_name='Result',
                                       data_type=str)
     tfio = TextFileIO(file_folder_path='.', file_name='WRITE_TEST')
     text_data = '*'
     gdp = GenericDataContainer(data_type=str)
     gdp.store(data=text_data)
     tfio.write(data=gdp,
                write_processor=iop,
                multiplier=8,
                result_generic_data_container=gdc_result)
     result = ''
     lines = list()
     with open('WRITE_TEST', 'r') as f:
         lines = f.readlines()
     result = ''.join(lines)
     self.assertEqual(text_data, result)
     self.assertIsNotNone(gdc_result)
     self.assertIsInstance(gdc_result, GenericDataContainer)
     self.assertEqual('', gdc_result.data)