def test_parse_hashes_allow_empty(): "strings.parse_hashes allow empty" keys = [u'name', u'age'] dicts = [ { u'name': u'Gabriel', u'age': u'22' }, { u'name': u'', u'age': u'33' }, { u'name': u'Dave', u'age': u'' } ] table = [ u"| name | age |\n", u"| Gabriel | 22 |\n", u"| | 33 |\n", u"| Dave | |\n", ] got_keys, got_dicts = strings.parse_hashes(table) assert_equals(keys, got_keys) assert_equals(dicts, got_dicts)
def test_parse_hashes(): "strings.parse_hashes" keys = ['name', 'age'] dicts = [ { 'name': 'Gabriel Falcão', 'age': '22' }, { 'name': 'Miguel', 'age': '33' } ] table = [ "| name | age |\n", "| Gabriel Falcão | 22 |\n", "| Miguel | 33 |\n", ] got_keys, got_dicts = strings.parse_hashes(table) assert_equals(keys, got_keys) assert_equals(dicts, got_dicts)
def test_parse_hashes_escapes_pipes(): "strings.parse_hashes escapes pipe" keys = [u'name', u'age'] dicts = [ { u'name': u'Gabriel | Falcão', u'age': u'22' }, { u'name': u'Miguel | Silva', u'age': u'33' } ] table = [ u"| name | age |\n", u"| Gabriel \| Falcão | 22 |\n", u"| Miguel \| Silva | 33 |\n", ] got_keys, got_dicts = strings.parse_hashes(table) assert_equals(keys, got_keys) assert_equals(dicts, got_dicts)
def from_string(new_scenario, string, with_file=None, original_string=None, language=None): """ Creates a new scenario from string""" if not language: language = Language() splitted = strings.split_wisely(string, u"(%s):" % language.examples, True) string = splitted[0] keys = [] outlines = [] if len(splitted) > 1: part = splitted[-1] keys, outlines = strings.parse_hashes(strings.get_stripped_lines(part)) lines = strings.get_stripped_lines(string) scenario_line = lines.pop(0) for repl in (language.scenario_outline, language.scenario): scenario_line = strings.remove_it(scenario_line, u"(%s): " % repl) scenario = new_scenario( name=scenario_line, remaining_lines=lines, keys=keys, outlines=outlines, with_file=with_file, original_string=original_string, language=language ) return scenario
def from_string(new_scenario, string, with_file=None, original_string=None, language=None): """ Creates a new scenario from string""" # ignoring comments string = "\n".join(strings.get_stripped_lines(string, ignore_lines_starting_with='#')) if not language: language = Language() splitted = strings.split_wisely(string, u"(%s):" % language.examples, True) string = splitted[0] keys = [] outlines = [] if len(splitted) > 1: parts = [l for l in splitted[1:] if l not in language.examples] part = "".join(parts) keys, outlines = strings.parse_hashes(strings.get_stripped_lines(part)) lines = strings.get_stripped_lines(string) scenario_line = lines.pop(0) for repl in (language.scenario_outline, language.scenario): scenario_line = strings.remove_it(scenario_line, u"(%s): " % repl) scenario = new_scenario( name=scenario_line, remaining_lines=lines, keys=keys, outlines=outlines, with_file=with_file, original_string=original_string, language=language ) return scenario
def test_parse_hashes_allow_empty(): "strings.parse_hashes allow empty" keys = [u"name", u"age"] dicts = [{u"name": u"Gabriel", u"age": u"22"}, {u"name": u"", u"age": u"33"}, {u"name": u"Dave", u"age": u""}] table = [u"| name | age |\n", u"| Gabriel | 22 |\n", u"| | 33 |\n", u"| Dave | |\n"] got_keys, got_dicts = strings.parse_hashes(table) assert_equals(keys, got_keys) assert_equals(dicts, got_dicts)
def test_parse_hashes_escapes_pipes(): "strings.parse_hashes escapes pipe" keys = [u"name", u"age"] dicts = [{u"name": u"Gabriel | Falcão", u"age": u"22"}, {u"name": u"Miguel | Silva", u"age": u"33"}] table = [u"| name | age |\n", u"| Gabriel \| Falcão | 22 |\n", u"| Miguel \| Silva | 33 |\n"] got_keys, got_dicts = strings.parse_hashes(table) assert_equals(keys, got_keys) assert_equals(dicts, got_dicts)
def from_string(new_scenario, string, with_file=None, original_string=None, language=None, previous_scenario=None): """ Creates a new scenario from string""" # ignoring comments string = "\n".join( strings.get_stripped_lines(string, ignore_lines_starting_with='#')) if not language: language = Language() splitted = strings.split_wisely(string, u"(%s):" % language.examples, True) string = splitted[0] keys = [] outlines = [] if len(splitted) > 1: parts = [l for l in splitted[1:] if l not in language.examples] part = "".join(parts) keys, outlines = strings.parse_hashes( strings.get_stripped_lines(part)) lines = strings.get_stripped_lines(string) scenario_line = lines.pop(0).strip() for repl in (language.scenario_outline, language.scenario): scenario_line = strings.remove_it(scenario_line, u"(%s): " % repl).strip() scenario = new_scenario( name=scenario_line, remaining_lines=lines, keys=keys, outlines=outlines, with_file=with_file, original_string=original_string, language=language, previous_scenario=previous_scenario, ) return scenario
def test_parse_hashes(): "strings.parse_hashes" keys = ['name', 'age'] dicts = [{ 'name': 'Gabriel Falcão', 'age': '22' }, { 'name': 'Miguel', 'age': '33' }] table = [ "| name | age |\n", "| Gabriel Falcão | 22 |\n", "| Miguel | 33 |\n", ] got_keys, got_dicts = strings.parse_hashes(table) assert_equals(keys, got_keys) assert_equals(dicts, got_dicts)
def _parse_remaining_lines(self, lines): multiline = strings.parse_multiline(lines) keys, hashes = strings.parse_hashes(lines) non_unique_keys, columns = strings.parse_as_json(lines) return keys, hashes, multiline, columns, non_unique_keys
def _parse_remaining_lines(self, lines): multiline = strings.parse_multiline(lines) keys, hashes = strings.parse_hashes(lines) return keys, hashes, multiline
def _parse_remaining_lines(self, lines): return strings.parse_hashes(lines)