The boundary function is used in a DirichletBC object as follows:
# Define essential boundary
def boundary(x):
return x[1] < DOLFIN_EPS or x[1] > 1.0 - DOLFIN_EPS
bc = DirichletBC(W.sub(0), G, boundary)
Thus it will be evaluated only on top and bottom boundaries, where the normal is +/- (0, 1). If you also print n[1] you will see that it is nonzero.