Beispiel #1
0
 def test_generic_data_container_tuple_with_string_validator_and_unsupported_data_expecting_exception(
         self):
     gdc = GenericDataContainer(result_set_name='Test',
                                data_type=tuple,
                                data_validator=StringDataValidator())
     with self.assertRaises(Exception):
         gdc.store(data='This must fail', start_with_alpha=False)
Beispiel #2
0
 def test_generic_data_container_decimal_with_no_validator_and_valid_str(
         self):
     gdc = GenericDataContainer(result_set_name='Test', data_type=Decimal)
     l = '1001.005'
     result = gdc.store(data=l)
     self.assertEqual(1, result)
     self.assertEqual(0, Decimal(l).compare(gdc.data))
Beispiel #3
0
 def test_validate_file_exists_io_processor_test_invalid_generic_data_container_value_type_expect_exception(
         self):
     gdc = GenericDataContainer(result_set_name='Test', data_type=list)
     gdc.store(data=['somefile.txt'])
     fp = ValidateFileExistIOProcessor()
     with self.assertRaises(Exception):
         fp.process(data=gdc)
Beispiel #4
0
 def test_validate_file_exists_io_processor_test_non_existing_file_expect_exception(
         self):
     gdc = GenericDataContainer(result_set_name='Test', data_type=str)
     gdc.store(data='null_file.txt')
     fp = ValidateFileExistIOProcessor()
     with self.assertRaises(Exception):
         fp.process(data=gdc)
Beispiel #5
0
 def test_generic_data_container_string_with_no_validator_and_valid_string(
         self):
     gdc = GenericDataContainer(result_set_name='Test', data_type=str)
     gdc.store(data='abc')
     self.assertIsNotNone(gdc.data)
     self.assertIsInstance(gdc.data, str)
     self.assertEqual('abc', gdc.data)
Beispiel #6
0
 def test_generic_data_container_float_with_validator_and_valid_float(self):
     gdc = GenericDataContainer(result_set_name='Test',
                                data_type=float,
                                data_validator=NumberDataValidator())
     l = 1001.001
     result = gdc.store(data=l, min_value=0.0, max_value=9999.0)
     self.assertEqual(1, result)
Beispiel #7
0
 def test_generic_data_container_float_with_invalid_validator_expect_exception(
         self):
     gdc = GenericDataContainer(result_set_name='Test',
                                data_type=float,
                                data_validator=StringDataValidator())
     l = 1001.001
     with self.assertRaises(Exception):
         gdc.store(data=l, min_value=0.0, max_value=3000.0)
Beispiel #8
0
 def test_generic_data_container_string_with_string_validator_and_valid_string(
         self):
     gdc = GenericDataContainer(result_set_name='Test',
                                data_type=str,
                                data_validator=StringDataValidator())
     input_str = 'abc'
     gdc.store(data=input_str, start_with_alpha=True)
     self.assertEqual(gdc.data, 'abc')
Beispiel #9
0
 def test_generic_data_container_string_with_string_validator_and_invalid_string_must_raise_exception(
         self):
     gdc = GenericDataContainer(result_set_name='Test',
                                data_type=str,
                                data_validator=StringDataValidator())
     input_str = ' abc'
     with self.assertRaises(Exception):
         gdc.store(data=input_str, start_with_alpha=True)
Beispiel #10
0
 def test_generic_data_container_int_with_no_validator_and_invalid_input_type(
         self):
     gdc = GenericDataContainer(result_set_name='Test',
                                data_type=int,
                                data_validator=NumberDataValidator())
     l = 1001
     with self.assertRaises(Exception):
         gdc.store(data=Decimal(l), min_value=2000, max_value=3000)
Beispiel #11
0
 def test_string_data_validator_data_container_all_defaults(self):
     self.data_container = GenericDataContainer(
         result_set_name='Test',
         data_type=str,
         data_validator=StringDataValidator())
     result = self.data_container.store(data=self.short_str)
     self.assertIsNotNone(result)
     self.assertIsInstance(result, int)
     self.assertEqual(len(self.short_str), result)
Beispiel #12
0
 def test_generic_data_container_list_with_string_validator_and_one_invalid_object_must_raise_exception(
         self):
     gdc = GenericDataContainer(result_set_name='Test',
                                data_type=list,
                                data_validator=StringDataValidator())
     l = ['Item 1', 1, 'This item will be ignored']
     result = gdc.store(data=l[0], start_with_alpha=False)
     self.assertEqual(1, result)
     with self.assertRaises(Exception):
         result = gdc.store(data=l[1], start_with_alpha=False)
Beispiel #13
0
 def test_generic_data_container_decimal_with_invalid_validator_and_valid_decimal_expect_exception(
         self):
     gdc = GenericDataContainer(result_set_name='Test',
                                data_type=Decimal,
                                data_validator=StringDataValidator())
     l = Decimal(1001.01)
     with self.assertRaises(Exception):
         gdc.store(data=l,
                   min_value=Decimal(0.0),
                   max_value=Decimal(9999.0))
Beispiel #14
0
 def test_generic_data_container_list_no_validator_list_contains_various_types(
         self):
     gdc = GenericDataContainer(result_set_name='Test', data_type=list)
     l = ['Item 1', 1, Decimal('0.0')]
     qty = 0
     for item in l:
         qty = qty + 1
         result = gdc.store(data=item, start_with_alpha=False)
         self.assertEqual(qty, result,
                          'Item "{}" failed to be stored'.format(qty))
Beispiel #15
0
 def process(self, data: GenericDataContainer, **kwarg):
     multiplier = 2
     if 'multiplier' in kwarg:
         multiplier = kwarg['multiplier']
     result_generic_data_container = GenericDataContainer(
         result_set_name='TEST', data_type=str)
     if 'result_generic_data_container' in kwarg:
         result_generic_data_container = kwarg[
             'result_generic_data_container']
     result_generic_data_container.store(data=data.data * multiplier)
Beispiel #16
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)
Beispiel #17
0
 def test_generic_data_container_tuple_with_no_validator_and_valid_list(
         self):
     gdc = GenericDataContainer(result_set_name='Test', data_type=tuple)
     l = [
         'Item 1',
         'Item 2',
     ]
     result = gdc.store(data=l, start_with_alpha=False)
     self.assertEqual(len(l), result,
                      'Item "{}" failed to be stored'.format(len(l)))
Beispiel #18
0
 def test_generic_data_container_decimal_with_validator_and_valid_decimal(
         self):
     gdc = GenericDataContainer(result_set_name='Test',
                                data_type=Decimal,
                                data_validator=NumberDataValidator())
     l = Decimal(1001.01)
     result = gdc.store(data=l,
                        min_value=Decimal(0.0),
                        max_value=Decimal(9999.0))
     self.assertEqual(1, result)
     self.assertEqual(0, l.compare(gdc.data))
Beispiel #19
0
 def test_generic_data_container_tuple_with_string_validator_and_valid_strings(
         self):
     gdc = GenericDataContainer(result_set_name='Test',
                                data_type=tuple,
                                data_validator=StringDataValidator())
     l = (
         'Item 1',
         'Item 2',
     )
     result = gdc.store(data=l, start_with_alpha=False)
     self.assertEqual(len(l), result,
                      'Item "{}" failed to be stored'.format(len(l)))
Beispiel #20
0
 def test_generic_data_container_tuple_with_string_validator_and_data_validation_fail_expecting_exception(
         self):
     gdc = GenericDataContainer(result_set_name='Test',
                                data_type=tuple,
                                data_validator=StringDataValidator())
     l = (
         'Item 1',
         'Item 2',
         3,
     )
     with self.assertRaises(Exception):
         gdc.store(data=l, start_with_alpha=False)
Beispiel #21
0
 def test_generic_io_processor_process_expect_exception(self):
     giop = GenericIOProcessor()
     gdc = GenericDataContainer(result_set_name='Test',
                                data_type=Decimal,
                                data_validator=NumberDataValidator())
     l = Decimal(1001.01)
     result = gdc.store(data=l,
                        min_value=Decimal(0.0),
                        max_value=Decimal(9999.0))
     self.assertEqual(1, result)
     with self.assertRaises(Exception):
         giop.process(data=gdc)
Beispiel #22
0
 def test_generic_data_container_list_with_string_validator_and_valid_strings(
         self):
     gdc = GenericDataContainer(result_set_name='Test',
                                data_type=list,
                                data_validator=StringDataValidator())
     l = ['Item 1', 'Item 2']
     qty = 0
     for item in l:
         qty = qty + 1
         result = gdc.store(data=item, start_with_alpha=False)
         self.assertEqual(qty, result,
                          'Item "{}" failed to be stored'.format(qty))
Beispiel #23
0
 def test_generic_data_container_dict_override_key_with_new_value(self):
     gdc = GenericDataContainer(result_set_name='Test', data_type=dict)
     self.assertEqual('dict', gdc.data_type.__name__)
     d = {
         'TestKey1': 1001,
         'TestKey2': 'Test Value',
         'TestKey3': Decimal('100'),
     }
     for key, val in d.items():
         result = gdc.store(data=val, key=key)
     result = gdc.store(data='New Value', key='TestKey1')
     self.assertTrue(result == 3)
     self.assertEqual('New Value', gdc.data['TestKey1'])
Beispiel #24
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)
Beispiel #25
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)
Beispiel #26
0
 def test_generic_data_container_tuple_with_no_validator_and_valid_list_add_another_item_expecting_exception(
         self):
     gdc = GenericDataContainer(result_set_name='Test', data_type=tuple)
     l = [
         'Item 1',
         'Item 2',
     ]
     l2 = [
         'Item 3',
         'Item 4',
     ]
     result = gdc.store(data=l, start_with_alpha=False)
     with self.assertRaises(Exception):
         gdc.store(data=l2, start_with_alpha=False)
Beispiel #27
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'])
Beispiel #28
0
 def test_generic_data_container_dict_with_dict_validator_not_of_the_expected_type_must_raise_exception(
         self):
     with self.assertRaises(Exception):
         gdc = GenericDataContainer(
             result_set_name='Test',
             data_type=dict,
             data_validator='Definitely an invalid validator instance!')
Beispiel #29
0
class TestValidateFileExistIOProcessor(unittest.TestCase):
    def setUp(self):
        self.gdc = GenericDataContainer(result_set_name='Test', data_type=str)
        self.gdc.store(data='somefile.txt')
        with open(self.gdc.data, 'w') as f:
            f.write('TEST')

    def tearDown(self):
        os.remove(self.gdc.data)

    def test_init_validate_file_exists_io_processor(self):
        fp = ValidateFileExistIOProcessor()
        self.assertIsNotNone(fp)
        self.assertIsInstance(fp, ValidateFileExistIOProcessor)
        self.assertIsNotNone(fp.logger)

    def test_validate_file_exists_io_processor_test_file(self):
        fp = ValidateFileExistIOProcessor()
        exception_raised = False
        try:
            fp.process(data=self.gdc)
        except:  # pragma: no cover
            exception_raised = True  # pragma: no cover
        self.assertFalse(exception_raised)

    def test_validate_file_exists_io_processor_test_non_existing_file_expect_exception(
            self):
        gdc = GenericDataContainer(result_set_name='Test', data_type=str)
        gdc.store(data='null_file.txt')
        fp = ValidateFileExistIOProcessor()
        with self.assertRaises(Exception):
            fp.process(data=gdc)

    def test_validate_file_exists_io_processor_test_invalid_generic_data_container_expect_exception(
            self):
        fp = ValidateFileExistIOProcessor()
        with self.assertRaises(Exception):
            fp.process(data='somefile.txt')

    def test_validate_file_exists_io_processor_test_invalid_generic_data_container_value_type_expect_exception(
            self):
        gdc = GenericDataContainer(result_set_name='Test', data_type=list)
        gdc.store(data=['somefile.txt'])
        fp = ValidateFileExistIOProcessor()
        with self.assertRaises(Exception):
            fp.process(data=gdc)
Beispiel #30
0
 def test_init_generic_data_container(self):
     gdc = GenericDataContainer(result_set_name='Test')
     self.assertIsNotNone(gdc)
     self.assertIsInstance(gdc, GenericDataContainer)
     self.assertEqual('Test', gdc.result_set_name)
     self.assertIsInstance(gdc.data_type, type)
     self.assertEqual('str', gdc.data_type.__name__)
     self.assertIsNone(gdc.data_validator)