def test_initialize_for_multiple_args(self): parser = ArgsParser( '(v|version):string; (r|red):boolean; (a|amount):numeric') expected_schema = { List(['v', 'version']): 'string', List(['r', 'red']): 'boolean', List(['a', 'amount']): 'numeric' } self.assertDictEqual(parser.schema, expected_schema)
def test_wrong_hash(self): hash_list = List(self.list) actual_hash = hash(hash_list) expected_hash = hash('wrong string') self.assertNotEqual(actual_hash, expected_hash)
def test_right_hash(self): hash_list = List(self.list) actual_hash = hash(hash_list) expected_hash = hash('|'.join(hash_list)) self.assertEqual(actual_hash, expected_hash)
def parse_template(template: str) -> dict: key_pattern = '\\(\S*\|\S*\\)' value_pattern = '(boolean|string|numeric)' template_pattern = f'{key_pattern}:{value_pattern}' match = match_re(template_pattern, template) if match is None: raise ParseError('Incorrect template.') # hint how to loop through reg_exp # https://stackoverflow.com/questions/12870178/looping-through-python-regex-matches keys = List() for key in findall_re(key_pattern, template): short, long = key.strip('()').split('|') l = List((short, long)) print(l) keys.append(l) values = findall_re(value_pattern, template) return dict(zip(keys, values))
def test_full_list_representation(self): full_list = List(self.list) self.assertEqual(repr(full_list), 't|test')
def test_empty_list_representation(self): empty_list = List() self.assertEqual(repr(empty_list), '')
def test_initialization_for_one_arg(self): parser = ArgsParser('(v|version):string') expected_schema = {List(['v', 'version']): 'string'} print(parser.schema) self.assertDictEqual(parser.schema, expected_schema)