예제 #1
0
def test_failover_in_case_of_exception():
    class Iterator(object):
        def __iter__(self):
            raise FileNotFoundError()

    file = Substitute()
    file.yields(Iterator())
    hosts = Hostnames(config=file, default=['a', 'b'])
    assert_equal(list(hosts._hosts()), ['a', 'b'])
예제 #2
0
def test_yields():
    '''Substitute: How to provide data for iteration'''

    # System under Test
    substitute = Substitute()

    # Act: Configure
    substitute.yields(['a', 'b', 'c'])

    # Act: Run
    result = list(substitute)

    # Assert
    assert_equal(result, ['a', 'b', 'c'])
예제 #3
0
def test_ignore_tokens():
    lexer = Substitute()
    lexer.yields([Number(3.1415), NewLine(), Comment('Test'), Number(3.1415)])

    expected_tokens = [
        Number(3.1415),
        Number(3.1415),
    ]

    # System under Test
    tokens = IgnoreTokens(lexer, tokens=[Comment, NewLine])

    # Assert
    tokens = list(tokens)
    assert_equal(tokens, expected_tokens)