def test_gen_stencil_2(parser): '''Check the gen_stencil function raises an exception when a node of the wrong type is provided. ''' schedule = get_schedule(parser, CODE) with pytest.raises(VisitorError) as excinfo: _ = gen_stencil(schedule) assert "gen_stencil expected an Array as input" in str(excinfo.value)
def test_gen_stencil_1(parser): '''Check the gen_stencil function produces the expected dimension strings. ''' for form, expected in [("i,j,k,l,m", "[0, 0, 0, 0, 0]"), ("i+1,j-1", "[1, -1]"), ("m+7", "[7]"), (" i + 1 , j , k - 1 ", "[1, 0, -1]"), ("i+1,j-2,k+3,l-4", "[1, -2, 3, -4]"), ("i+(1), j-(2)", "[1, -2]")]: code = CODE.replace("a(i,j,k)", "a({0})".format(form)) lhs = get_lhs(parser, code) result = gen_stencil(lhs) assert result == expected
def test_gen_stencil_3(parser): '''Check the gen_stencil function raises an exception when an unsupported form of indexing is found. Currently only "var +/- int" is supported. ''' for form in ["1", "1+i", "-1+i", "i+j", "i+1+1", "i+(1+1)", "i*2"]: code = CODE.replace("a(i,j,k)", "a({0},j,k)".format(form)) lhs = get_lhs(parser, code) with pytest.raises(VisitorError) as excinfo: _ = gen_stencil(lhs) if form in ["1"]: error = "unsupported (non-stencil) index found" elif form in ["i*2"]: error = "unsupported stencil operator found" else: error = "unsupported stencil index found" assert error in str(excinfo.value)