Example #1
0
    def get_executor_obj(self) -> executor:
        '''Return the code that will actually generate the C++ we need to execute
        here.

        Returns:
            executor: Return the executor
        '''
        return atlas_xaod_executor()
def test_bad_ast_no_call(tmp_path):
    'Pass a really bogus ast to the executor'
    # Get the ast to play with
    q = query_as_ast()
    a = ast.UnaryOp(op=ast.USub(), operand=q.query_ast)

    exe = atlas_xaod_executor()
    with pytest.raises(ValueError) as e:
        exe.write_cpp_files(exe.apply_ast_transformations(a), tmp_path)

    assert 'func_adl ast' in str(e.value)
def test_bad_ast_no_call_to_name(tmp_path):
    'Pass a really bogus ast to the executor'
    # Get the ast to play with
    q = query_as_ast()
    a = ast.Call(func=ast.Attribute(value=ast.Constant(10), attr='fork'),
                 args=[q.query_ast])

    exe = atlas_xaod_executor()
    with pytest.raises(ValueError) as e:
        exe.write_cpp_files(exe.apply_ast_transformations(a), tmp_path)

    assert 'func_adl ast' in str(e.value)
def test_eventinfo_handle_code(tmp_path):
    'Make sure a required library is in the link list'
    # Get the ast to play with
    a = query_as_ast() \
        .Select('lambda e: e.EventInfo("EventInfo").runNumber()') \
        .value()

    exe = atlas_xaod_executor()
    exe.write_cpp_files(exe.apply_ast_transformations(a), tmp_path)

    query = tmp_path / 'query.cxx'
    assert 'const xAOD::EventInfo *' in query.read_text()
def test_xaod_executor(tmp_path):
    'Write out C++ files for a simple query'

    # Get the ast to play with
    a = query_as_ast() \
        .Select('lambda e: e.EventInfo("EventInfo").runNumber()') \
        .value()

    exe = atlas_xaod_executor()
    f_spec = exe.write_cpp_files(exe.apply_ast_transformations(a), tmp_path)
    for name in f_spec.all_filenames:
        assert (tmp_path / name).exists()
def test_xaod_library_there(tmp_path):
    'Make sure a required library is in the link list'
    # Get the ast to play with
    a = query_as_ast() \
        .Select('lambda e: e.EventInfo("EventInfo").runNumber()') \
        .value()

    exe = atlas_xaod_executor()
    exe.write_cpp_files(exe.apply_ast_transformations(a), tmp_path)

    make_list = tmp_path / 'package_CMakeLists.txt'
    assert make_list.exists()
    assert 'xAODEventInfo' in make_list.read_text()
def test_md_job_options(tmp_path):
    'Make sure our job options script appears in the right place'

    # Get the ast to play with
    a = (query_as_ast().MetaData({
        'metadata_type': 'add_job_script',
        'name': 'Vertex',
        'script': [
            '# this is a fork tester',
        ]
    }).Select('lambda e: e.EventInfo("EventInfo").runNumber()').value())

    exe = atlas_xaod_executor()
    exe.write_cpp_files(exe.apply_ast_transformations(a), tmp_path)

    with open(tmp_path / 'ATestRun_eljob.py', 'r') as f:
        lines = [ln.strip() for ln in f.readlines()]
        assert '# this is a fork tester' in lines
def test_md_replaced_collection(tmp_path):
    'When we replace a collection, make sure all goes right'
    # Get the ast to play with
    a = query_as_ast() \
        .MetaData({
            'metadata_type': 'add_atlas_event_collection_info',
            'name': 'EventInfo',
            'include_files': ['xAODEventInfo/versions/EventInfo_v1.h'],
            'container_type': 'xAOD::EventInfo_v1',
            'contains_collection': False,
            'link_libraries': ['xAODEventInfo'],
        }) \
        .Select('lambda e: e.EventInfo("EventInfo").runNumber()') \
        .value()

    exe = atlas_xaod_executor()
    exe.write_cpp_files(exe.apply_ast_transformations(a), tmp_path)

    query = tmp_path / 'query.cxx'
    assert query.exists()
    assert 'const xAOD::EventInfo_v1 *' in query.read_text()
def test_exeuctor_forgets_blocks():
    'An executor must be able to run twice, and forget between'

    from tests.utils.base import dataset, dummy_executor
    from func_adl_xAOD.atlas.xaod.query_ast_visitor import atlas_xaod_query_ast_visitor

    our_exe = atlas_xaod_executor()

    class executor_atlas_holder(dummy_executor):
        def __init__(self):
            super().__init__()

        def get_executor_obj(self) -> atlas_xaod_executor:
            return our_exe

        def get_visitor_obj(self) -> atlas_xaod_query_ast_visitor:
            return atlas_xaod_query_ast_visitor()

    class dataset_xaod(dataset):
        def __init__(self, qastle_roundtrip=False):
            super().__init__(qastle_roundtrip=qastle_roundtrip)

        def get_dummy_executor_obj(self) -> dummy_executor:
            return executor_atlas_holder()

    (dataset_xaod().MetaData({
        'metadata_type': 'add_job_script',
        'name': 'fork',
        'script': ['line1', 'line2'],
    }).SelectMany(lambda e: e.Jets("AntiKt4EMTopoJets")).Select(
        lambda j: j.pt()).value())
    our_exe.reset()
    (dataset_xaod().MetaData({
        'metadata_type': 'add_job_script',
        'name': 'fork',
        'script': ['line3', 'line4'],
    }).SelectMany(lambda e: e.Jets("AntiKt4EMTopoJets")).Select(
        lambda j: j.pt()).value())

    our_exe.add_to_replacement_dict()
def test_ctor():
    'Make sure that the ctor works'
    atlas_xaod_executor()
 async def execute_result_async(self, a: ast.AST, title: str) -> Any:
     if self._dir.exists():
         self._dir.mkdir(parents=True, exist_ok=True)
     exe = atlas_xaod_executor()
     f_spec = exe.write_cpp_files(exe.apply_ast_transformations(a), self._dir)
     return ExecutorInfo(f_spec.main_script, f_spec.result_rep.filename)
Example #12
0
 def get_executor_obj(self) -> atlas_xaod_executor:
     return atlas_xaod_executor()