def test_merge_dtypes_one_given(self): """ test merging of list of 1 dtype dict """ dtypes1 = {v: "float" for v in 'ACD'} ref = dtypes1 merged_dtypes = csvutils.merge_dtypes([dtypes1]) assert ref == merged_dtypes
def merge_dtype_test_types_different(self, type): """ test merge dtypes that are different """ dtypes1 = {v: type for v in 'ACD'} dtypes2 = {v: type for v in 'ACDEF'} ref = {v: type for v in set(dtypes1.keys()).union(set(dtypes2.keys()))} merged_dtypes = csvutils.merge_dtypes([dtypes1, dtypes2]) assert ref == merged_dtypes
def merge_dtype_test_types_mixed(self): """ test merge dtypes that have mixed typing """ types = ["int", "float", "bool", "str"] dtypes1 = {v: random.choice(types) for v in "ACD"} dtypes2 = {v: random.choice(types) for v in "ACD"} ref = {v: type for v in set(dtypes1.keys()).union(set(dtypes2.keys()))} merged_dtypes = csvutils.merge_dtypes([dtypes1, dtypes2]) assert ref == merged_dtypes
def test_merge_dtypes(self): """ basic sanity check - test merging of two dtype dicts """ dtypes1 = {v: "float" for v in 'ACD'} dtypes2 = {v: "float" for v in 'ACDEF'} ref = { v: "float" for v in set(dtypes1.keys()).union(set(dtypes2.keys())) } merged_dtypes = csvutils.merge_dtypes([dtypes1, dtypes2]) assert ref == merged_dtypes
def test_merge_dtypes_multiple_given(self, n_dtypes): """ test merging of n_dtypes dtype dicts :param n_dtypes: number of dtypes to merge """ dtypes = [{v: "int" for v in "".join(self._str_list(3, "A"))} for _ in range(n_dtypes)] # taken from https://stackoverflow.com/questions/9819602/union-of-dict-objects-in-python ref = dict(itertools.chain.from_iterable(dct.items() for dct in dtypes)) merged_dtypes = csvutils.merge_dtypes(dtypes) assert ref == merged_dtypes