def test_stencil_case_2(): '''test that the metadata name 'go_pointwise' can be provided in lower, or upper case ''' stencil = GOStencil() stencil_string = "go_pOiNtWiSe" parsed_stencil = expr.FORT_EXPRESSION.parseString(stencil_string)[0] stencil.load(parsed_stencil, "kernel_stencil") assert not stencil.has_stencil assert stencil.name == "go_pointwise"
def test_stencil_depth_args(): '''Check that invalid index values for the depth method in an instance of the GOStencil class cause an exception to be raised. ''' stencil = GOStencil() stencil_string = "go_stencil(010,111,010)" parsed_stencil = expr.FORT_EXPRESSION.parseString(stencil_string)[0] stencil.load(parsed_stencil, "kernel_stencil") for i, j in [(-2, 0), (2, 0), (0, -2), (0, 2)]: with pytest.raises(GenerationError) as excinfo: stencil.depth(i, j) assert "must be between -1 and 1 but found ({0},{1})".format(i, j) \ in str(excinfo.value)
def test_stencil_case_1(): '''test that the metadata name 'go_stencil' can be provided in lower, or upper case. ''' stencil = GOStencil() stencil_string = "go_StEnCiL(234,915,876)" parsed_stencil = expr.FORT_EXPRESSION.parseString(stencil_string)[0] stencil.load(parsed_stencil, "kernel_stencil") assert stencil.has_stencil expected = [8, 7, 6, 9, 1, 5, 2, 3, 4] exp_index = 0 for idx2 in range(-1, 2): for idx1 in range(-1, 2): assert stencil.depth(idx1, idx2) == expected[exp_index] exp_index += 1
def test_stencil_case_1(): '''test that the metadata name 'go_stencil' can be provided in lower, or upper case. ''' stencil = GOStencil() stencil_string = "go_StEnCiL(000,011,000)" parsed_stencil = expr.FORT_EXPRESSION.parseString(stencil_string)[0] stencil.load(parsed_stencil, "kernel_stencil") assert stencil.has_stencil for idx2 in range(-1, 2): for idx1 in range(-1, 2): if idx1 in [0, 1] and idx2 == 0: expected_depth = 1 else: expected_depth = 0 assert stencil.depth(idx1, idx2) == expected_depth
def test_stencil_invalid_format_1(): '''Check all the ways in which the 'stencil(...) format can be invalid ''' stencil = GOStencil() # this should cause a general unexpected format error with pytest.raises(ParseError) as excinfo: stencil.load(None, "kernel_stencil") assert "expected either a name or the format 'go_stencil(...)" \ in str(excinfo.value) # this should cause a general unexpected format error with pytest.raises(ParseError) as excinfo: stencil.load(stencil, "kernel_stencil") assert "expected either a name or the format 'go_stencil(...)" \ in str(excinfo.value) # this should cause a general unexpected format error stencil_string = "(a)" parsed_stencil = expr.FORT_EXPRESSION.parseString(stencil_string)[0] with pytest.raises(ParseError) as excinfo: stencil.load(parsed_stencil, "kernel_stencil") assert "expected either a name or the format 'go_stencil(...)" \ in str(excinfo.value) # this should cause an unsupported name error stencil_string = "random_name" parsed_stencil = expr.FORT_EXPRESSION.parseString(stencil_string)[0] with pytest.raises(ParseError) as excinfo: stencil.load(parsed_stencil, "kernel_stencil") assert ("argument is 'random_name' but must be one of ['go_pointwise'] or " "go_stencil(...)") in str(excinfo.value) # this should cause an unsupported name error stencil_string = "stenci(a)" parsed_stencil = expr.FORT_EXPRESSION.parseString(stencil_string)[0] with pytest.raises(ParseError) as excinfo: stencil.load(parsed_stencil, "kernel_stencil") assert "argument is 'stenci' but must be 'go_stencil(...)" \ in str(excinfo.value)
def test_stencil_invalid_format_2(): '''Check all the ways in which the arguments in the 'go_stencil(...) format can be invalid ''' stencil = GOStencil() # this should cause a not-enough-args error stencil_string = "go_stencil(a)" parsed_stencil = expr.FORT_EXPRESSION.parseString(stencil_string)[0] with pytest.raises(ParseError) as excinfo: stencil.load(parsed_stencil, "kernel_stencil") assert "format 'go_stencil(...)', has 1 arguments but should have 3" \ in str(excinfo.value) # this should cause a not-a-number error stencil_string = "go_stencil(a,b,c)" parsed_stencil = expr.FORT_EXPRESSION.parseString(stencil_string)[0] with pytest.raises(ParseError) as excinfo: stencil.load(parsed_stencil, "kernel_stencil") assert "Argument index 0 should be a number but found 'a'" \ in str(excinfo.value) # this should also cause a not-a-number error stencil_string = "go_stencil(000,x00,000)" parsed_stencil = expr.FORT_EXPRESSION.parseString(stencil_string)[0] with pytest.raises(ParseError) as excinfo: stencil.load(parsed_stencil, "kernel_stencil") assert "index 1 should be a number but found 'x00'" \ in str(excinfo.value) # this should cause a not-3-numbers error stencil_string = "go_stencil(012,345,67)" parsed_stencil = expr.FORT_EXPRESSION.parseString(stencil_string)[0] with pytest.raises(ParseError) as excinfo: stencil.load(parsed_stencil, "kernel_stencil") assert "index 2 should consist of 3 digits but found 2" \ in str(excinfo.value) # this should cause an invalid-middle-number error stencil_string = "go_stencil(012,345,678)" parsed_stencil = expr.FORT_EXPRESSION.parseString(stencil_string)[0] with pytest.raises(ParseError) as excinfo: stencil.load(parsed_stencil, "kernel_stencil") assert "index 1 position 1 should be a number from 0-1 but found 4" \ in str(excinfo.value) # this should cause a zero-size-stencil error stencil_string = "go_stencil(000,010,000)" parsed_stencil = expr.FORT_EXPRESSION.parseString(stencil_string)[0] with pytest.raises(ParseError) as excinfo: stencil.load(parsed_stencil, "kernel_stencil") assert ("A zero sized stencil has been specified. This should be " "specified with the 'go_pointwise' keyword") in str(excinfo.value) # lastly, this should work as it is valid stencil_string = "go_stencil(000,011,000)" parsed_stencil = expr.FORT_EXPRESSION.parseString(stencil_string)[0] stencil.load(parsed_stencil, "kernel_stencil")