Esempio n. 1
0
def test_strict_no_error(not_thunk):
    """Does not through error if require=False"""
    try:
        strict(not_thunk, require=False)
        strict(not_thunk)  # require=False is default
    except TypeError:
        pytest.fail("Unexpected TypeError ..")
Esempio n. 2
0
def test_strict(simple_function):
    thunk = Thunk(simple_function)
    # no call before strict
    assert simple_function.call_count == 0
    assert strict(thunk) == 38
    assert simple_function.call_count == 1
    # only one call after more than one strict
    assert strict(thunk) == 38
    assert simple_function.call_count == 1
Esempio n. 3
0
 def __call__(self, position: Element) \
         -> Tuple[None, Element]:  # noqa: D102
     try:
         # Element is really a Thunk[Element] so we need to cast it and
         # force it's evaluation to determine if a parse error is thrown,
         # indicating the end of the current level of elements.
         yzal.strict(cast(yzal.Thunk[Element], position))
     except LocalParseFailure:
         return None, position
     raise LocalParseFailure(position.file, position.closing_line,
                             'Expected end of element.')
Esempio n. 4
0
 def __call__(self, position: Element) \
         -> Tuple[Element, Element]:  # noqa: D102
     if position.tag == self._name:
         return yzal.strict(position), next_element(position)
     raise LocalParseFailure(position.file, position.opening_line)
Esempio n. 5
0
 def __call__(self, position: Element) \
         -> Tuple[Element, Element]:  # noqa: D102
     return yzal.strict(position), next_element(position)
Esempio n. 6
0
def test_strict(thunk):
    assert thunk.__strict__.call_count == 0
    assert strict(thunk) == 4
    assert thunk.__strict__.call_count == 1
    assert strict(thunk) == 4
    assert thunk.__strict__.call_count == 2
Esempio n. 7
0
def test_strict_error(not_thunk):
    """Throws TypeError if __strict__ method does not exist and require=True"""
    with pytest.raises(TypeError):
        strict(not_thunk, require=True)