def test_errors(f2003_create): '''Check that format specifications not conforming to the C1002 1st clause, raise an NoMatchError exception. ''' for my_input in [None, "", " ", "I2", "F2.3E4", "D2.3E4", "F", "D", "ES", "F2", "F2.", "E2E3", "E2.E3", "E2.3E", "E2.3E4E"]: with pytest.raises(NoMatchError): _ = Data_Edit_Desc_C1002(my_input)
def test_internal_error1(f2003_create, monkeypatch): '''Check that an internal error is raised if the length of the Items list is not 4 as the str() method assumes that it is. ''' my_input = "E1.2E3" ast = Data_Edit_Desc_C1002(my_input) monkeypatch.setattr(ast, "items", [None, None, None]) with pytest.raises(InternalError) as excinfo: str(ast) assert "has '3' items, but expecting 4." in str(excinfo)
def test_internal_error6(f2003_create, monkeypatch): '''Check that an internal error is raised if the descriptor name has an unexpected value. ''' my_input = "E1.2E3" ast = Data_Edit_Desc_C1002(my_input) monkeypatch.setattr(ast, "items", ["INVALID"] + list(ast.items[1:])) with pytest.raises(InternalError) as excinfo: str(ast) assert "Unexpected descriptor name 'INVALID'" in str(excinfo)
def test_wde(f2003_create): '''Check that valid w.dEe format specifications are parsed correctly. Also include an example with spaces and multiple digits with spaces. ''' for descriptor in ["E", "EN", "ES", "G", "e", "en", "En", "eN", "es", "g"]: for my_input in ["{0}2.3E4".format(descriptor), " {0} 2 . 3 E 4 ".format(descriptor), " {0} 2 2 . 3 3 E 4 4 ".format(descriptor)]: ast = Data_Edit_Desc_C1002(my_input) assert str(ast) == my_input.upper().replace(" ", "")
def test_internal_error5(f2003_create, monkeypatch): '''Check that an internal error is raised if the e value (entry 3 of items) has content when the descriptor is F or D as it should be None. ''' for my_input in ["F1.2", "D1.2"]: ast = Data_Edit_Desc_C1002(my_input) monkeypatch.setattr(ast, "items", list(ast.items[0:3]) + ["3"]) with pytest.raises(InternalError) as excinfo: str(ast) assert ("has an exponent value '3' but this is not allowed for 'F' " "and 'D' descriptors" in str(excinfo))
def test_internal_error4(f2003_create, monkeypatch): '''Check that an internal error is raised if the m value (entry 2 of items) is empty or None as the str() method assumes that it is a string with content. ''' my_input = "E1.2E3" ast = Data_Edit_Desc_C1002(my_input) for content in [None, ""]: monkeypatch.setattr( ast, "items", [ast.items[0], ast.items[1], content, ast.items[3]]) with pytest.raises(InternalError) as excinfo: str(ast) assert "should be the m value but is empty or None" in str(excinfo)
def test_internal_error2(f2003_create, monkeypatch): '''Check that an internal error is raised if the descriptor name (entry 0 of items) is empty or None as the str() method assumes that it is a string with content. ''' my_input = "E1.2E3" ast = Data_Edit_Desc_C1002(my_input) for content in [None, ""]: monkeypatch.setattr(ast, "items", [content] + list(ast.items[1:])) with pytest.raises(InternalError) as excinfo: str(ast) assert "should be a descriptor name but is empty or None" \ in str(excinfo)