Example #1
0
 def test_convert_types_casting(self):
     mapping = {
                 "foo": {"column": "foo", 
                        "datatype": "float"}
               }
     row = {"foo": "5.0"}
     out = types.convert_types(mapping, row)
     assert isinstance(out, dict), out
     assert 'foo' in out, out
     assert out['foo']==5.0
Example #2
0
 def test_convert_types_value(self):
     mapping = {
                 "foo": {"column": "foo", 
                        "datatype": "string"}
               }
     row = {"foo": "bar"}
     out = types.convert_types(mapping, row)
     assert isinstance(out, dict), out
     assert 'foo' in out, out
     assert out['foo']=='bar'
Example #3
0
    def process_line(self, line):
        if self.line_number % 1000 == 0:
            log.info('Imported %s lines' % self.line_number)

        try:
            data = convert_types(self.model['mapping'], line)
            if not self.dry_run:
                self.dataset.load(data)
        except (Invalid, ImporterError) as e:
            if self.raise_errors:
                raise
            else:
                self.add_error(e)
Example #4
0
 def test_convert_types_compound(self):
     mapping = {
                 "foo": {"fields": [
                     {"name": "name", "column": "foo_name", 
                         "datatype": "string"},
                     {"name": "label", "column": "foo_label", 
                         "datatype": "string"}
                     ]
                 }
               }
     row = {"foo_name": "bar", "foo_label": "qux"}
     out = types.convert_types(mapping, row)
     assert isinstance(out, dict), out
     assert 'foo' in out, out
     assert isinstance(out['foo'], dict), out
     assert out['foo']['name']=='bar'
     assert out['foo']['label']=='qux'