コード例 #1
0
 def test_text_file_io_empty_text_data_read_without_cache(self):
     tfio = TextFileIO(file_folder_path='.', file_name='READ_TEST')
     with open('READ_TEST', 'w') as f:
         f.write('')
     gdc = tfio.read()
     self.assertIsNotNone(gdc)
     self.assertIsInstance(gdc, GenericDataContainer)
     self.assertIsNotNone(gdc.data)
     self.assertEqual('', gdc.data)
コード例 #2
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)
コード例 #3
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)
コード例 #4
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)
コード例 #5
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'])
コード例 #6
0
 def test_text_file_io_basic_text_data_read_without_cache_with_invalid_read_processor_expect_no_changes_in_input_type(
         self):
     iop = 'Invalid Processor'
     gdc_result = {'Test': 123}
     tfio = TextFileIO(file_folder_path='.', file_name='READ_TEST')
     text_data = '*'
     with open('READ_TEST', 'w') as f:
         f.write(text_data)
     tfio.read(read_processor=iop,
               multiplier=8,
               result_generic_data_container=gdc_result)
     self.assertIsNotNone(gdc_result)
     self.assertIsInstance(gdc_result, dict)
     self.assertEqual(1, len(gdc_result))
     self.assertTrue('Test' in gdc_result)
     self.assertEqual(123, gdc_result['Test'])
コード例 #7
0
 def test_text_file_io_basic_text_data_read_without_cache_with_read_processor(
         self):
     iop = TextMultiplierGenericIOProcessor()
     gdc_result = GenericDataContainer(result_set_name='Result',
                                       data_type=str)
     tfio = TextFileIO(file_folder_path='.', file_name='READ_TEST')
     text_data = '*'
     with open('READ_TEST', 'w') as f:
         f.write(text_data)
     tfio.read(read_processor=iop,
               multiplier=8,
               result_generic_data_container=gdc_result)
     self.assertIsNotNone(gdc_result)
     self.assertIsInstance(gdc_result, GenericDataContainer)
     self.assertIsNotNone(gdc_result.data)
     self.assertEqual('********', gdc_result.data)
コード例 #8
0
 def test_init_text_file_io(self):
     tfio = TextFileIO(file_folder_path='.', file_name='TEST')
     self.assertIsNotNone(tfio)
     self.assertIsInstance(tfio, TextFileIO)
     self.assertEqual('.{}TEST'.format(os.sep), tfio.uri)
     self.assertEqual(0, tfio.cached_data_timestamp)
     self.assertIsNone(tfio.cached_data)
     self.assertEqual(900, tfio.cache_max_age)
     self.assertFalse(tfio.enable_cache)
コード例 #9
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)
コード例 #10
0
 def test_text_file_io_basic_text_data_read_with_cache(self):
     tfio = TextFileIO(file_folder_path='.',
                       file_name='READ_TEST',
                       enable_cache=True)
     text_data = 'TEST'
     with open('READ_TEST', 'w') as f:
         f.write(text_data)
     gdc = tfio.read()
     self.assertIsNotNone(gdc)
     self.assertIsInstance(gdc, GenericDataContainer)
     self.assertIsNotNone(gdc.data)
     self.assertEqual('TEST', gdc.data)
     self.assertTrue(os.path.isfile('READ_TEST'))
     if os.path.isfile('READ_TEST'):
         os.remove('READ_TEST')
     self.assertFalse(os.path.isfile('READ_TEST'))
     gdc_cached_value = tfio.read()
     self.assertIsNotNone(gdc_cached_value)
     self.assertIsInstance(gdc_cached_value, GenericDataContainer)
     self.assertIsNotNone(gdc_cached_value.data)
     self.assertEqual('TEST', gdc_cached_value.data)
コード例 #11
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)