use mock.patch to control patch state; improve tests