def parse_unit(item, logical_system=None): unit = { 'unit': item['name'], 'description': item.get('description'), 'vlanid': item.get('vlan-id'), 'address': find_all('name', find_all('address', item)), } if logical_system: unit['logical_system'] = logical_system return unit
def testExcludesMissing(self): """Test that missing files and dirs are excluded from results.""" fakedir = os.path.join(self.dtc, 'FAKERY') fakefile = os.path.join(self.dblah, 'FAKERY2.spam') files = utils.find_all([self.dsub, fakedir, fakefile, self.ftc_fs], pattern='*.spam') ideal = [self.fsub_fs, self.ftc_fs] self.assertEqual(sorted(files), sorted(ideal))
def testFindFoldersHasOnlyUnique(self): """Test that if we pass in multiple folders, some of which are under each other, we don't get duplicate files. """ files = utils.find_all([self.dtc, self.dsub], pattern='*.spam') ideal = [self.ftc_fs, self.fbar_fs, self.fblah_fs, self.fsub_fs] print files print ideal self.assertEqual(sorted(files), sorted(ideal))
def test_nested(self): data = { 'test': [ {'hest': 1}, {'hest': 2}, ], 'hest': 3, } self.assertEqual(set(find_all('hest', data)), set([1, 2, 3]))
def get_rid_of_commands(prefixes, template): result = template for prefix in prefixes: parens = utils.find_parens(result) prefix_indexes = utils.find_all(result, prefix) subs = {} for index in prefix_indexes: start = index end = parens[start] command = result[start:end + 1] subs[command] = "" result = utils.substitute(result, subs) return result
def replaceChars(token, subData): subProb = subData["count"] subMatrix = subData["subs"] appliable = {k: subProb[k] for k in subProb.keys() if k in token} subCandidates = list(appliable.keys()) shuffle(subCandidates) tokenBitMask = [0 for char in token] for sub in subCandidates: subProb = appliable[sub] subWith = weighted_choice(subMatrix[sub]) for start in find_all(token, sub): if sum(tokenBitMask[start:start + len(sub)] ) == 0 and probability_boolean(subProb): token = token[:start] + subWith + token[start + len(sub):] tokenBitMask = tokenBitMask[:start] + \ [1 for c in subWith] + tokenBitMask[start+len(sub):] return token
def testFindMixed(self): """Test when given files and folders, resolves properly.""" files = utils.find_all([self.dsub, self.fbar_bh, self.fblah_fs], pattern='*.ham') ideal = [self.fsub_bh, self.fsub_fh, self.fbar_bh] self.assertEqual(sorted(files), sorted(ideal))
def testFindFoldersOnly(self): """Test when given a collection of paths, resolves properly.""" files = utils.find_all([self.dblah, self.dbar], pattern="*.spam") ideal = [self.fblah_fs, self.fsub_fs, self.fbar_fs] self.assertEqual(sorted(files), sorted(ideal))
def testFindsFilesOnly(self): """Test when given a collection of files, resolves properly.""" files = utils.find_all([self.ftc_bh, self.ftc_bh, self.ftc_fs, self.fsub_fh, self.fsub_fs], pattern="*.ham") #Make sure we don't have .spam files ideal = [self.ftc_bh, self.ftc_bh, self.fsub_fh] self.assertEqual(sorted(files), sorted(ideal))
def test_direct(self): data = { 'test': 'best', } self.assertEqual(find_all('test', data), ['best'])