Exemple #1
0
def test_story_from_stream(patch, magic):
    patch.init(Story)
    patch.object(Story, 'clean_source')
    stream = magic()
    result = Story.from_stream(stream)
    Story.clean_source.assert_called_with(stream.read())
    Story.__init__.assert_called_with(Story.clean_source())
    assert isinstance(result, Story)
Exemple #2
0
def test_story_init_clean_source(patch):
    """
    Ensures Story.clean_source is called for new stories
    """
    patch.object(Story, 'clean_source')
    source = 'my story'
    story = Story(source)
    Story.clean_source.assert_called_with(source)
    assert story.story == Story.clean_source(source)
Exemple #3
0
def test_story_read(patch):
    """
    Ensures Story.read can read a story
    """
    patch.object(io, 'open')
    patch.object(Story, 'clean_source')
    result = Story.read('hello.story')
    io.open.assert_called_with('hello.story', 'r')
    Story.clean_source.assert_called_with(io.open().__enter__().read())
    assert result == Story.clean_source()
Exemple #4
0
def test_story_clean_source(patch):
    """
    Ensures that a story is cleaned correctly
    """
    patch.object(re, 'sub')
    patch.object(Story, 'remove_comments')
    patch.object(Story, 'delete_line')
    result = Story.clean_source('source')
    re.sub.assert_called_with(r'###[^#]+###', Story.delete_line,
                              Story.remove_comments())
    assert result == re.sub()