[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better overall error-handling for parsing, and type errors #3

Open
yanniskatsaros opened this issue Sep 25, 2020 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@yanniskatsaros
Copy link
Owner

Current error-handling is very rough around the edges. In specific, several test cases are also failing due to incorrect error messages for the types of errors that should be occurring (type error vs nullable type error vs parsing error etc.). Furthermore, the current implementation stores all errors until the entire document has been parsed, then raises an exception with the slew of errors. This can be cleaned up.

Failing Test Cases

====================================================================== FAILURES =======================================================================
__________________________________________________ TestFloatDeclarations.test_catch_null_type_error ___________________________________________________

self = <test_fable.TestFloatDeclarations object at 0x10597dd30>

    def test_catch_null_type_error(self):
        s = 'float num null'
        result = parse_variable_declaration(s)
>       assert result.code == ErrorCode.NULLABLE_TYPE_ERROR
E       assert <ErrorCode.TYPE_ERROR: 4> == <ErrorCode.NULLABLE_TYPE_ERROR: 2>
E         +<ErrorCode.TYPE_ERROR: 4>
E         -<ErrorCode.NULLABLE_TYPE_ERROR: 2>

tests/test_fable.py:67: AssertionError
___________________________________________________ TestFloatDeclarations.test_catch_parsing_error ____________________________________________________

self = <test_fable.TestFloatDeclarations object at 0x105a2d4e0>

    def test_catch_parsing_error(self):
        s = 'float num # woops forgot the value'
        result = parse_variable_declaration(s)
>       assert result.code == ErrorCode.PARSING_ERROR
E       assert <ErrorCode.TYPE_ERROR: 4> == <ErrorCode.PARSING_ERROR: 1>
E         +<ErrorCode.TYPE_ERROR: 4>
E         -<ErrorCode.PARSING_ERROR: 1>

tests/test_fable.py:72: AssertionError
_________________________________________________________ TestFloatDeclarations.test_all_nans _________________________________________________________

self = <test_fable.TestFloatDeclarations object at 0x105a25630>

    def test_all_nans(self):
        nans = [
            'float num nan',
            'float num NaN',
            'float num NaN%',
            'float num NAN',
            'float num NaNQ',
            'float num NaNS',
            'float num qNaN',
            'float num sNaN',
            'float num 1.#SNAN',
            'float num 1.#QNAN',
            'float num +nan.0'
        ]
        for nan in nans:
            result = parse_variable_declaration(nan)
>           assert isnan(result.value)
E           AssertionError: assert False
E            +  where False = isnan(1.0)
E            +    where 1.0 = Variable(name='num', value=1.0).value

tests/test_fable.py:95: AssertionError
__________________________________________________ TestFloatDeclarations.test_negative_signed_floats __________________________________________________

self = <test_fable.TestFloatDeclarations object at 0x105931470>

    def test_negative_signed_floats(self):
        cases = [
            'float num -14.51',
            'float num -1.451E01',
            'float num -1.451E+01',
            'float num -1.451e01',
            'float num -1.451e+01'
        ]
        for s in cases:
            result = parse_variable_declaration(s)
            assert result == Variable('num', -14.51)

        cases = [
            'float num -0.001451',
            'float num -1.451E-03',
            'float num -1.451e-03'
        ]
        for s in cases:
            result = parse_variable_declaration(s)
>           assert result == Variable('num', -0.001451, False)
E           TypeError: __init__() takes 3 positional arguments but 4 were given

tests/test_fable.py:168: TypeError
__________________________________________________ TestStringDeclarations.test_catch_null_type_error __________________________________________________

self = <test_fable.TestStringDeclarations object at 0x10592d7b8>

    def test_catch_null_type_error(self):
        s = 'string message null'
        result = parse_variable_declaration(s)
>       assert result.code == ErrorCode.NULLABLE_TYPE_ERROR
E       assert <ErrorCode.TYPE_ERROR: 4> == <ErrorCode.NULLABLE_TYPE_ERROR: 2>
E         +<ErrorCode.TYPE_ERROR: 4>
E         -<ErrorCode.NULLABLE_TYPE_ERROR: 2>

tests/test_fable.py:226: AssertionError
___________________________________________________ TestStringDeclarations.test_catch_parsing_error ___________________________________________________

self = <test_fable.TestStringDeclarations object at 0x105920470>

    def test_catch_parsing_error(self):
        s = 'string message # woops forgot the value'
        result = parse_variable_declaration(s)
>       assert result.code == ErrorCode.PARSING_ERROR
E       assert <ErrorCode.TYPE_ERROR: 4> == <ErrorCode.PARSING_ERROR: 1>
E         +<ErrorCode.TYPE_ERROR: 4>
E         -<ErrorCode.PARSING_ERROR: 1>

tests/test_fable.py:231: AssertionError
_________________________________________________ TestBooleanDeclarations.test_catch_null_type_error __________________________________________________

self = <test_fable.TestBooleanDeclarations object at 0x10591b7f0>

    def test_catch_null_type_error(self):
        s = 'boolean is_happy null'
        result = parse_variable_declaration(s)
>       assert result.code == ErrorCode.NULLABLE_TYPE_ERROR
E       assert <ErrorCode.TYPE_ERROR: 4> == <ErrorCode.NULLABLE_TYPE_ERROR: 2>
E         +<ErrorCode.TYPE_ERROR: 4>
E         -<ErrorCode.NULLABLE_TYPE_ERROR: 2>

tests/test_fable.py:257: AssertionError
__________________________________________________ TestBooleanDeclarations.test_catch_parsing_error ___________________________________________________

self = <test_fable.TestBooleanDeclarations object at 0x1059a37f0>

    def test_catch_parsing_error(self):
        s = 'boolean is_happy # woops forgot the rest'
        result = parse_variable_declaration(s)
>       assert result.code == ErrorCode.PARSING_ERROR
E       assert <ErrorCode.TYPE_ERROR: 4> == <ErrorCode.PARSING_ERROR: 1>
E         +<ErrorCode.TYPE_ERROR: 4>
E         -<ErrorCode.PARSING_ERROR: 1>

tests/test_fable.py:262: AssertionError
=============================================================== short test summary info ===============================================================
FAILED tests/test_fable.py::TestFloatDeclarations::test_catch_null_type_error - assert <ErrorCode.TYPE_ERROR: 4> == <ErrorCode.NULLABLE_TYPE_ERROR: 2>
FAILED tests/test_fable.py::TestFloatDeclarations::test_catch_parsing_error - assert <ErrorCode.TYPE_ERROR: 4> == <ErrorCode.PARSING_ERROR: 1>
FAILED tests/test_fable.py::TestFloatDeclarations::test_all_nans - AssertionError: assert False
FAILED tests/test_fable.py::TestFloatDeclarations::test_negative_signed_floats - TypeError: __init__() takes 3 positional arguments but 4 were given
FAILED tests/test_fable.py::TestStringDeclarations::test_catch_null_type_error - assert <ErrorCode.TYPE_ERROR: 4> == <ErrorCode.NULLABLE_TYPE_ERROR: 2>
FAILED tests/test_fable.py::TestStringDeclarations::test_catch_parsing_error - assert <ErrorCode.TYPE_ERROR: 4> == <ErrorCode.PARSING_ERROR: 1>
FAILED tests/test_fable.py::TestBooleanDeclarations::test_catch_null_type_error - assert <ErrorCode.TYPE_ERROR: 4> == <ErrorCode.NULLABLE_TYPE_ERROR...
FAILED tests/test_fable.py::TestBooleanDeclarations::test_catch_parsing_error - assert <ErrorCode.TYPE_ERROR: 4> == <ErrorCode.PARSING_ERROR: 1>
============================================================ 8 failed, 26 passed in 0.19s =============================================================
@yanniskatsaros yanniskatsaros added the enhancement New feature or request label Sep 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant