def test_merge_with(): dicts = {1: 1, 2: 2}, {1: 10, 2: 20} assert merge_with(sum, *dicts) == {1: 11, 2: 22} assert merge_with(tuple, *dicts) == {1: (1, 10), 2: (2, 20)} dicts = {1: 1, 2: 2, 3: 3}, {1: 10, 2: 20} assert merge_with(sum, *dicts) == {1: 11, 2: 22, 3: 3} assert merge_with(tuple, *dicts) == {1: (1, 10), 2: (2, 20), 3: (3,)} assert not merge_with(sum)
def test_merge_with(): dicts = {1: 1, 2: 2}, {1: 10, 2: 20} assert merge_with(sum, *dicts) == {1: 11, 2: 22} assert merge_with(tuple, *dicts) == {1: (1, 10), 2: (2, 20)} dicts = {1: 1, 2: 2, 3: 3}, {1: 10, 2: 20} assert merge_with(sum, *dicts) == {1: 11, 2: 22, 3: 3} assert merge_with(tuple, *dicts) == {1: (1, 10), 2: (2, 20), 3: (3, )} assert not merge_with(sum)
def test_merge_with(self): D, kw = self.D, self.kw dicts = D({1: 1, 2: 2}), D({1: 10, 2: 20}) assert merge_with(sum, *dicts, **kw) == D({1: 11, 2: 22}) assert merge_with(tuple, *dicts, **kw) == D({1: (1, 10), 2: (2, 20)}) dicts = D({1: 1, 2: 2, 3: 3}), D({1: 10, 2: 20}) assert merge_with(sum, *dicts, **kw) == D({1: 11, 2: 22, 3: 3}) assert merge_with(tuple, *dicts, **kw) == D({1: (1, 10), 2: (2, 20), 3: (3,)}) assert not merge_with(sum)
def multiversion_compile( source_bundles: List[SourceBundle], compiler_version_check: bool = True) -> VersionedContractOutputs: """Compile contracts from `source_dirs` and aggregate the resulting source contract outputs by version""" raw_compiler_results: List[CompiledContractOutputs] = list() for bundle in source_bundles: compile_result = compile_sources(source_bundle=bundle, version_check=compiler_version_check) raw_compiler_results.append(compile_result['contracts']) raw_compiled_contracts = itertools.chain.from_iterable( output.values() for output in raw_compiler_results) versioned_contract_outputs = VersionedContractOutputs( merge_with(merge_contract_outputs, *raw_compiled_contracts)) return versioned_contract_outputs
def test_merge_with_non_dict_mappings(): class Foo(Mapping): def __init__(self, d): self.d = d def __iter__(self): return iter(self.d) def __getitem__(self, key): return self.d[key] def __len__(self): return len(self.d) d = Foo({1: 1}) rv = merge(d) assert merge(d) is d or merge(d) == {1: 1} assert merge_with(sum, d) == {1: 1}
def regroup_excels_by_sheet( local_authority_excels: List[Dict[str, pd.DataFrame]] ) -> Dict[str, pd.DataFrame]: return merge_with(list, *local_authority_excels)
def test_merge_with_iterable_arg(self): D, kw = self.D, self.kw dicts = D({1: 1, 2: 2}), D({1: 10, 2: 20}) assert merge_with(sum, *dicts, **kw) == D({1: 11, 2: 22}) assert merge_with(sum, dicts, **kw) == D({1: 11, 2: 22}) assert merge_with(sum, iter(dicts), **kw) == D({1: 11, 2: 22})
def test_merge_with_iterable_arg(): dicts = {1: 1, 2: 2}, {1: 10, 2: 20} assert merge_with(sum, *dicts) == {1: 11, 2: 22} assert merge_with(sum, dicts) == {1: 11, 2: 22} assert merge_with(sum, iter(dicts)) == {1: 11, 2: 22}