def test_data_edit_descriptor(f2003_create): '''Check that basic format specifications are parsed correctly for a data edit descriptor. The description is tested in more detail by the associated class. ''' # No R for my_input in ["F2.2", " F2.2 "]: ast = Format_Item(my_input) assert my_input.replace(" ", "") in str(ast) assert repr(ast) == ("Format_Item(None, Data_Edit_Desc_C1002('F'," " Digit_String('2', None), Int_Literal_Constant(" "'2', None), None))") # R for my_input in ["2F2.2", " 2 F2.2 "]: ast = Format_Item(my_input) assert my_input.replace(" ", "") in str(ast) assert repr(ast) == ("Format_Item(Digit_String('2', None), Data_Edit" "_Desc_C1002('F', Digit_String('2', None), " "Int_Literal_Constant('2', None), None))") # Multi-R for my_input in ["22F2.2", " 2 2 F2.2 "]: ast = Format_Item(my_input) assert my_input.replace(" ", "") in str(ast) assert repr(ast) == ("Format_Item(Digit_String('22', None), Data_Edit" "_Desc_C1002('F', Digit_String('2', None), " "Int_Literal_Constant('2', None), None))")
def test_errors(f2003_create): '''test some list errors. Individual item errors will be picked up by the subclasses. ''' for my_input in [None, "", " ", "2", "2 ", "(", ")"]: with pytest.raises(NoMatchError): _ = Format_Item(my_input)
def test_char_edit_descriptor(f2003_create): '''Check that basic format specifications are parsed correctly for a char string edit descriptor. The description is tested in more detail by the associated class. ''' for my_input in ["'hello'", " 'hello' "]: ast = Format_Item(my_input) assert my_input.strip() in str(ast) assert repr(ast) == ("Char_Literal_Constant(\"'hello'\", None)")
def test_control_edit_descriptor(f2003_create): '''Check that basic format specifications are parsed correctly for a control edit descriptor. The description is tested in more detail by the associated class. ''' for my_input in ["2P", " 2P "]: ast = Format_Item(my_input) assert my_input.strip() in str(ast) assert repr(ast) == ("Control_Edit_Desc(Signed_Int_Literal_Constant(" "'2', None), 'P')")
def test_internal_errors1(f2003_create, monkeypatch): '''Check that an internal error is raised if the length of the Items list is not 2 as the str() method assumes that it is. ''' line = "2F2.2" ast = Format_Item(line) monkeypatch.setattr(ast, "items", [None, None, None]) with pytest.raises(InternalError) as excinfo: str(ast) assert "should be of length 2 but found '3'" in str(excinfo.value)
def test_hollerith_item(f2003_create, monkeypatch): '''Check that a hollerith item is parsed correctly. The description is tested in more detail by the associated class. ''' from fparser.two import utils monkeypatch.setattr(utils, "EXTENSIONS", ["hollerith"]) for my_input in ["2H12", " 2H12 "]: ast = Format_Item(my_input) assert my_input.strip() in str(ast) assert repr(ast) == ("Hollerith_Item('12')")
def test_internal_errors2(f2003_create, monkeypatch): '''Check that an internal error is raised if the descriptor item (first entry of items) is empty or None as the str() method assumes that it has content. ''' ast = Format_Item("F2.2") monkeypatch.setattr(ast, "items", [ast.items[0], None]) with pytest.raises(InternalError) as excinfo: str(ast) assert ("items list second entry should be a valid descriptor but it " "is empty or None") in str(excinfo.value)