def test_reversed(): try: from collections import OrderedDict except: # skip on python 2.6 return for items in _ITEMSETS: omd = OMD(items) od = OrderedDict(items) for ik, ok in zip(reversed(od), reversed(omd)): assert ik == ok r100 = range(100) omd = OMD(zip(r100, r100)) for i in r100: omd.add(i, i) r100 = list(reversed(r100)) assert list(reversed(omd)) == r100 omd = OMD() assert list(reversed(omd)) == list(reversed(omd.keys())) for i in range(20): for j in range(i): omd.add(i, i) assert list(reversed(omd)) == list(reversed(omd.keys()))
def get_all_secret_names(self): "return a map of secret names to names of domains that contain that secret" res = OMD() for domain_name, domain in self._domains.items(): secrets_dict = domain._secrets for secret_name in secrets_dict: res.add(secret_name, domain_name) return dict(res)
def _get_pkg_info(plist, project, repo_dir): # snap: search for snapcraft.yaml # appimage: find -iname "appimage" -type d # flatpak: find -iname "flatpak" -type d # maybe exclude test dirs, e.g., what ansible has # docker: find -name "Dockerfile" ret = {} container_stacks = OMD() for path in iter_find_files(repo_dir, CONTAINER_FILES, include_dirs=True): container_stacks.add( os.path.splitext(os.path.basename(path))[0].lower(), path) #if container_stacks: # print(container_stacks.todict()) has_docker = bool(container_stacks.pop('dockerfile', None)) container_stack = first(container_stacks.keys(), None) or ('docker' if has_docker else '') ret['container'] = container_stack # TODO: split into mac/windows/linux? for linux I'll need to look # at deb/rpm, and I'm not sure the best strategy there. rpm maybe # .spec files? might have to check inside as other tools # (pyinstaller) uses .spec, too. # freezers -> pyInstaller, cx_Freeze, py2exe, py2app, pynsist # (bbFreeze phased out, osnap/constructor not yet adopted, harder # to search for). conda and omnibus also not adopted. freezer_res_map = OMD() for freezer_name in FREEZERS: search_output = search_files(freezer_name, '*', repo_dir) if search_output: freezer_res_map.add(freezer_name, len(search_output.splitlines())) if freezer_res_map: top, top_res = sorted(freezer_res_map.items(), key=lambda x: x[1])[-1] ret['freezer'] = top return ret
def test_pop(): omd = OMD() omd.add('even', 0) omd.add('odd', 1) omd.add('even', 2) assert omd.pop('odd') == 1 assert omd.pop('odd', 99) == 99 try: omd.pop('odd') assert False except KeyError: pass assert len(omd) == 1 assert len(omd.items(multi=True)) == 2
def test_pop(): omd = OMD() omd.add('even', 0) omd.add('odd', 1) omd.add('even', 2) assert omd.pop('odd') == 1 assert omd.pop('odd', 99) == 99 try: omd.pop('odd') import pdb;pdb.set_trace() assert False except KeyError: pass assert len(omd) == 1 assert len(omd.items(multi=True)) == 2
def test_pop_all(): omd = OMD() omd.add('even', 0) omd.add('odd', 1) omd.add('even', 2) assert omd.popall('odd') == [1] assert len(omd) == 1 try: omd.popall('odd') assert False except KeyError: pass assert omd.popall('odd', None) is None assert omd.popall('even') == [0, 2] assert len(omd) == 0 assert omd.popall('nope', None) is None
def test_pop_all(): omd = OMD() omd.add("even", 0) omd.add("odd", 1) omd.add("even", 2) assert omd.popall("odd") == [1] assert len(omd) == 1 try: omd.popall("odd") assert False except KeyError: pass assert omd.popall("odd", None) is None assert omd.popall("even") == [0, 2] assert len(omd) == 0 assert omd.popall("nope", None) is None
def test_pop(): omd = OMD() omd.add("even", 0) omd.add("odd", 1) omd.add("even", 2) assert omd.pop("odd") == 1 assert omd.pop("odd", 99) == 99 try: omd.pop("odd") import pdb pdb.set_trace() assert False except KeyError: pass assert len(omd) == 1 assert len(omd.items(multi=True)) == 2