def assert_subclass_parse(source, base_type, actual_type=None, expected_str=None): '''Assert that the given source matches the given ``base_type`` and optionally the specific type that it should produce. :param source: The Fortran source to be parsed. :type source: str or :py:class:`FortranReaderBase` :param base_type: the base type from which a match is expected to be found :type base_type: :py:class:`fortran.two.Fortran2003.Base` subclass :param actual_type: The actual type matched by the parser. :type actual_type: :py:class:`fortran.two.Fortran2003.Base` subclass :param str expected_str: The expected ``str(result)`` of the parsed result ''' obj = f2003.Primary(source) # Note: Check that the type exists in the possible types, rather than # checking the type is an instance of one of the possible types (and # all of its ancestor types). This is a much more targetted test as a # result. assert type(obj) in possible_subclasses(base_type) if actual_type: assert isinstance(obj, actual_type) else: assert isinstance(obj, base_type) if expected_str: assert expected_str == str(obj)
def test_c702_no_assumed_size_array(f2003_create): '''Test C702 (R701) The designator shall not be a whole assumed-size array. This test cannot be passed without more parse context of things like defined types. ''' context = f2003.Type_Declaration_Stmt("integer(*) :: assumed_size_array") with pytest.raises(fparser.two.utils.NoMatchError): f2003.Primary('assumed_size_array', ) # context)
def test_c701_no_assumed_size_array(f2003_create): '''Test C701 (R701) The type-param-name shall be the name of a type. This test cannot be passed without more parse context of things like defined types. ''' context = f2003.Type_Declaration_Stmt("INTEGER :: not_a_type") with pytest.raises(fparser.two.utils.NoMatchError): f2003.Primary('not_a_type', ) # context)
def test_no_match(f2003_create): '''Test that a NoMatchError is raised if we provide code that isn't allowed as a Primary type (e.g. a comment). ''' with pytest.raises(fparser.two.utils.NoMatchError): _ = f2003.Primary('! A comment')
def test_no_match(): '''Test that a NoMatchError is raised if we provide code that isn't allowed as a Primary type (e.g. a comment). ''' with pytest.raises(NoMatchError): _ = f2003.Primary('! A comment')