コード例 #1
0
ファイル: test_block.py プロジェクト: v-legoff/croissant
 def test_sub_blocks(self):
     """Test that an indented content creates sub-blocks."""
     content = CONTENT_WITH_INDENTATION
     block = Block.build(content)
     self.assertEqual(len(block), 5)
     self.assertEqual(block[0], "We now try a different content")
     self.assertEqual(block[3][2], "Let's try it")
コード例 #2
0
ファイル: test_block.py プロジェクト: v-legoff/croissant
 def test_hierarchy(self):
     """Test the hierarchy consistence, parent, children and siblings."""
     content = CONTENT_WITH_INDENTATION
     block = Block.build(content)
     self.assertIs(block[0].parent, block)
     self.assertIs(block[1], block[0].next)
     self.assertIs(block[1].previous, block[0])
     self.assertIs(block[3][0].next, block[3][1])
     self.assertIs(block[3][0], block[3][1].previous)
コード例 #3
0
ファイル: story.py プロジェクト: v-legoff/croissant
    def parse(cls, path, content, father=None):
        """Parse a file and create the corresponding story.

        The path should be the path leading to the story file.
        If mentioned, the father argument should be the story set
        that will add this story when it will be parsed.

        """
        story = cls(path=path, father=father)
        block = Block.build(content)

        # The first line should contain the title
        if len(block) == 0:
            # The file is empty
            raise EmptyFile("the story file {} is empty".format(
                    repr(path)))

        try:
            block_title = block[0]
        except IndexError:
            raise MissingKeyword("the {} keyword should be the " \
                    "first line of your {} file".format(
                    repr(keyword.languages[symbol]), repr(file)))

        symbol = "en"
        title = block_title.display(indentation=False)
        keyword = keywords["story.title"]
        story.title = keyword.parse(symbol, title)
        if story.title is None:
            raise MissingKeyword(path, block.start_at + 1, symbol, keyword)

        # The description should be slightly indented then (2nd block)
        try:
            description_block = block[1]
        except IndexError:
            raise StructureError("the descrption couldn't be read " \
                    "from {}".format(repr(path)))

        story.description = description_block.display(indentation=False)
        scenario_blocks = block[2:]
        title = None
        for sub_block in scenario_blocks:
            if title:
                title._children.append(sub_block)
                scenario = Scenario.parse(title, story)
                story.add_scenario(scenario)
                title = None
            else:
                title = sub_block

        return story
コード例 #4
0
ファイル: test_block.py プロジェクト: v-legoff/croissant
 def test_nb_lines(self):
     """Test that the number of lines of a given content is consistent."""
     content = CONTENT_WITHOUT_INDENTATION
     block = Block.build(content)
     self.assertEqual(block.nb_lines, len(content.splitlines()))