def inner(mock_stat): mock_stat.return_value = (33261, 2245040, long(64770), 1, 0, 0, 25552, 1360831382, 1352194410, 1354626626) t._check_execs() self.assertItemsEqual(mock_stat.call_args_list, [call(e) for e in t.__execs__]) # not executable mock_stat.reset_mock() mock_stat.return_value = (33188, 2245040, long(64770), 1, 0, 0, 25552, 1360831382, 1352194410, 1354626626) self.assertRaises(ToolInstantiationError, t._check_execs) # non-existant mock_stat.reset_mock() mock_stat.side_effect = OSError self.assertRaises(ToolInstantiationError, t._check_execs)
def netmask_itoa(netmask, proto="ipv4"): """ convert an integer netmask (e.g., /16) to dotted-quad notation (255.255.0.0) or IPv6 prefix notation (ffff::) """ if proto == "ipv4": size = 32 family = socket.AF_INET else: # ipv6 size = 128 family = socket.AF_INET6 try: netmask = int(netmask) except ValueError: return netmask if netmask > size: raise ValueError("Netmask too large: %s" % netmask) res = long(0) for i in range(netmask): res |= 1 << (size - i - 1) netmask = socket.inet_ntop(family, pack128(res)) return netmask