Beispiel #1
0
def test_database_handler():
    dburl = get_tmp_sqlite_db_url()
    s = Storage(dburl)
    name = "_test"
    handler = get_handler(DatabaseTableFormat, s.storage_engine)
    handler().create_empty(name, s, test_records_schema)
    s.get_api().bulk_insert_records(name, test_records)
    assert list(handler().infer_field_names(name, s)) == list(test_records[0].keys())
    assert handler().infer_field_type(name, s, "f1") == Text()
    assert handler().infer_field_type(name, s, "f2") == Integer()
    assert handler().infer_field_type(name, s, "f3") == DEFAULT_FIELD_TYPE
    assert handler().infer_field_type(name, s, "f4") == Date()
    assert handler().infer_field_type(name, s, "f5") == DEFAULT_FIELD_TYPE
Beispiel #2
0
def test_memory_handlers(fmt: DataFormat, obj: Any):
    s = Storage("python://test")
    name = "_test"
    s.get_api().put(name, obj())
    handler = get_handler(fmt, s.storage_engine)
    assert list(handler().infer_field_names(name, s)) == list(test_records[0].keys())
    assert handler().infer_field_type(name, s, "f1") == Text()
    assert handler().infer_field_type(name, s, "f2") == Integer()
    assert handler().infer_field_type(name, s, "f3") == DEFAULT_FIELD_TYPE
    assert handler().infer_field_type(name, s, "f4") == Date()
    assert handler().infer_field_type(name, s, "f5") == DEFAULT_FIELD_TYPE

    handler().cast_to_field_type(name, s, "f4", Text())
    handler().cast_to_field_type(name, s, "f4", Date())
    round_trip_object = s.get_api().get(name)
    assert_objects_equal(round_trip_object, obj())
Beispiel #3
0
def test_records_to_file():
    dr = tempfile.gettempdir()
    s: Storage = Storage.from_url(f"file://{dr}")
    fs_api: FileSystemStorageApi = s.get_api()
    mem_s = new_local_python_storage()
    mem_api: PythonStorageApi = mem_s.get_api()
    name = f"_test_{rand_str()}"
    obj = [{"f1": "hi", "f2": 2}]
    mem_api.put(name, obj)
    req = CopyRequest(name, mem_s, name, s, CsvFileFormat)
    RecordsToCsvFile().copy(req)
    with fs_api.open(name, newline="") as f:
        recs = list(read_csv(f))
        handler = get_handler(RecordsFormat, mem_s.storage_engine)
        mem_api.put(
            "output",
            recs,
        )
        handler().cast_to_schema("output", mem_s, schema=test_records_schema)
        recs = mem_api.get("output")
        assert recs == obj
Beispiel #4
0
Datei: base.py Projekt: kvh/dcp
 def to_format_handler(self) -> FormatHandler:
     return get_handler(self.get_to_format(),
                        self.to_storage.storage_engine)()
Beispiel #5
0
Datei: base.py Projekt: kvh/dcp
 def from_format_handler(self) -> FormatHandler:
     return get_handler(self.from_format,
                        self.from_storage.storage_engine)()