Ejemplo n.º 1
0
    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.convert_rows_to_dictionary(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
Ejemplo n.º 2
0
def test_convert_rows_to_dictionary_escapes_pipes():
    "strings.convert_rows_to_dictionary 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.convert_rows_to_dictionary(table)

    assert_equals(keys, got_keys)
    assert_equals(dicts, got_dicts)
Ejemplo n.º 3
0
    def __init__(self, sentence, remaining_lines, line=None, filename=None):
        self.sentence = sentence
        self.original_sentence = sentence

        self._remaining_lines = remaining_lines

        self.rows = strings.convert_rows_to_list(remaining_lines)

        row_keys, rows_as_dict = strings.convert_rows_to_dictionary(remaining_lines)  
        self.row_keys = tuple(row_keys)
        self.rows_as_dict = list(rows_as_dict)

        column_keys, columns_as_dict = strings.convert_columns_to_dictionary(remaining_lines)
        self.column_keys = tuple(column_keys)
        self.columns_as_dict = list(columns_as_dict)

        # reintroduced hashes for backwards compatibility
        self.keys = self.row_keys
        self.hashes = self.rows_as_dict

        self.described_at = StepDescription(line, filename)

        self.proposed_method_name, self.proposed_sentence = self.propose_definition()