示例#1
0
 def test_date_format_invalid_specification(self, mocker,
                                            invalid_dateformat):
     with patch('builtins.open',
                mock_open(read_data=json.dumps(invalid_dateformat))):
         handler = BaseHandler()
         with pytest.raises(ValueError):
             handler.valid_specification('')
示例#2
0
    def test_basehandler_no_dataset_locale(self, invalid_no_locale_dataset):
        handler = BaseHandler()
        with open('invalid_spec.json', 'w') as f:
            json.dump(invalid_no_locale_dataset, f)

        with pytest.raises(ValueError):
            handler.valid_specification('invalid_spec.json')
        remove('invalid_spec.json')
示例#3
0
    def test_basehandler_no_dataset(self, no_datasets_specification):
        handler = BaseHandler()
        with open('invalid_spec.json', 'w') as f:
            json.dump(no_datasets_specification, f)

        with pytest.raises(ValueError):
            handler.valid_specification('invalid_spec.json')
        remove('invalid_spec.json')
示例#4
0
    def test_basehandler_valid(self, valid_specification):
        handler = BaseHandler()

        with open('valid_spec.json', 'w') as f:
            json.dump(valid_specification, f)

        config = handler.valid_specification('valid_spec.json')

        assert valid_specification == config

        remove('valid_spec.json')
示例#5
0
    def test_basehandler_invalid_replace_without_sqltype(
            self, invalid_spec_for_replace_rules_without_sqltype):
        handler = BaseHandler()

        with open('invalid_spec_for_replace_rules_without_sqltype.json',
                  'w') as f:
            json.dump(invalid_spec_for_replace_rules_without_sqltype, f)
        with pytest.raises(ValueError):
            handler.valid_specification(
                'invalid_spec_for_replace_rules_without_sqltype.json')

        remove('invalid_spec_for_replace_rules_without_sqltype.json')
示例#6
0
    def test_basehandler_valid_replace(self, valid_spec_for_replace_rules):
        handler = BaseHandler()

        with open('valid_spec_for_replace_rules.json', 'w') as f:
            json.dump(valid_spec_for_replace_rules, f)

        config = handler.valid_specification(
            'valid_spec_for_replace_rules.json')

        assert valid_spec_for_replace_rules == config

        remove('valid_spec_for_replace_rules.json')
示例#7
0
    def test_float_dataframe(self, mocker, float_specification):
        mock = mocker.patch \
                     .object(BaseHandler, 'valid_specification')
        mock.return_value = float_specification
        handler = BaseHandler()
        specification = handler.valid_specification()
        dataframe = handler.generate_dataframe(specification,
                                               float_specification['size'])

        assert isinstance(dataframe, DataFrame) is True
        assert dataframe.shape[0] == float_specification['size']
        for field in float_specification['fields']:
            assert dataframe[field['name']].dtype.name == field['expected']
示例#8
0
    def test_bool_dataframe(self, mocker, bool_specification):
        with patch('builtins.open',
                   mock_open(read_data=json.dumps(bool_specification))):
            dataset = bool_specification['datasets']['sample']
            expected_size = dataset['size']
            expected_fields = dataset['fields']

            handler = BaseHandler()
            dataframe = handler.generate_dataframe(dataset, dataset['size'])

            assert isinstance(dataframe, DataFrame) is True
            assert dataframe.shape[0] == expected_size
            for field in expected_fields:
                assert dataframe[field['name']].dtype.name == field['expected']
示例#9
0
 def test_unknown_type(self, mocker, unknown_type_spec):
     with patch('builtins.open',
                mock_open(read_data=json.dumps(unknown_type_spec))):
         handler = BaseHandler()
         with pytest.raises(ValueError):
             handler.valid_specification('')
示例#10
0
 def test_malformed_json(self, mocker, malformed_json):
     with patch('builtins.open', mock_open(read_data=malformed_json)):
         handler = BaseHandler()
         with pytest.raises(ValueError):
             handler.valid_specification('')