def parse_key_value(args): """ Meant to replace the CriteriaCommand _parse_key_value method. The docstring below was copied from that implementation. parses the raw user input, taken as a list of strings in the format 'name=value', into a list of tuples in the format (name, value). :param args: list of raw strings passed by the user on the command line. :type args: list of basestrings :return: new list of tuples in the format (name, value) """ def translate(key_value_tuple): """ :param key_value_tuple: single key/value tuple to translate :return: new key-value tuple to use """ for orig_key, translated_key in TRANSLATIONS.items(): if key_value_tuple[0] == orig_key: encoded_value = version_utils.encode(key_value_tuple[1]) return translated_key, encoded_value return key_value_tuple base_parsed_list = CriteriaCommand._parse_key_value(args) translated_list = map(translate, base_parsed_list) return translated_list
def parse_key_value(args): """ Meant to replace the CriteriaCommand _parse_key_value method. The docstring below was copied from that implementation. parses the raw user input, taken as a list of strings in the format 'name=value', into a list of tuples in the format (name, value). :param args: list of raw strings passed by the user on the command line. :type args: list of basestrings :return: new list of tuples in the format (name, value) """ def translate(key_value_tuple): """ :param key_value_tuple: single key/value tuple to translate :return: new key-value tuple to use """ for orig_key, translated_key in TRANSLATIONS.items(): if key_value_tuple[0] == orig_key: encoded_value = version_utils.encode(key_value_tuple[1]) return translated_key, encoded_value return key_value_tuple base_parsed_list = CriteriaCommand._parse_key_value(args) translated_list = map(translate, base_parsed_list) return translated_list
def test_basic(self): ret = CriteriaCommand._parse_key_value(['id=repo1']) self.assertEqual(ret, [['id', 'repo1']])
def test_multiple_args(self): ret = CriteriaCommand._parse_key_value(['id=repo1', 'name=foo']) self.assertEqual(ret, [['id', 'repo1'], ['name', 'foo']])
def test_multiple_equals(self): # the second '=' should not be split ret = CriteriaCommand._parse_key_value(['id=repo=1']) self.assertEqual(ret, [['id', 'repo=1']])
def test_multiple_args(self): ret = CriteriaCommand._parse_key_value(['id=repo1', 'name=foo']) self.assertEqual(ret, [['id', 'repo1'], ['name', 'foo']])
def test_multiple_equals(self): # the second '=' should not be split ret = CriteriaCommand._parse_key_value(['id=repo=1']) self.assertEqual(ret, [['id', 'repo=1']])
def test_basic(self): ret = CriteriaCommand._parse_key_value(['id=repo1']) self.assertEqual(ret, [['id', 'repo1']])