

def execute_antlr_test(self, expected_package, target_workdir_fun=None):
    target = self.get_antlr_target()
    context = self.create_context()
    task = self.prepare_execute(context)
    target_workdir_fun = (target_workdir_fun or (lambda x: safe_mkdtemp(dir=x)))
    target_workdir = target_workdir_fun(self.build_root)
    task.execute_codegen(target, target_workdir)
    syn_target = task._inject_synthetic_target(target, target_workdir)
    actual_sources = [s for s in Fileset.rglobs('*.java', root=target_workdir)]
    expected_sources = syn_target.sources_relative_to_source_root()
    self.assertEquals(set(expected_sources), set(actual_sources))

    def get_package(path):
        with open(path) as fp:
            for line in fp:
                match = self.PACKAGE_RE.match(line)
                if match:
                    return match.group('package_name')
            return None
    for source in syn_target.sources_relative_to_source_root():
        source_path = os.path.join(target_workdir, task)
        self.assertTrue(os.path.isfile(source_path), '{0} is not the source root for {1}'.format(target_workdir, source))
        self.assertEqual(expected_package, get_package(source_path))
        self.assertIn(syn_target, context.targets())
    return syn_target

dataset/ETHPy150Open pantsbuild/pants/tests/python/pants_test/backend/codegen/tasks/test_antlr_gen.py AntlrGenTest.execute_antlr_test/VarMisuse@208/299 `source`->`task`