def test_retrieving_all_compiled_templates(template_directory, tmpdir): """Compile actions should return all compiled templates.""" target1, target2 = Path(tmpdir) / 'target.tmp', Path(tmpdir) / 'target2' targets = [target1, target2] template = Path('no_context.template') compile_dict = { 'content': str(template), 'target': '{target}', } # First replace {target} with target1, then with target2, by doing some # trickery with the replacer function. compile_action = CompileAction( options=compile_dict, directory=template_directory, replacer=lambda x: x.format(target=targets.pop(), ) if x == '{target}' else x, context_store={}, ) assert compile_action.performed_compilations() == {} compile_action.execute() assert compile_action.performed_compilations() == { template_directory / template: {target2}, } compile_action.execute() assert compile_action.performed_compilations() == { template_directory / template: {target1, target2}, }
def test_that_dry_run_skips_compilation(template_directory, tmpdir, caplog): """If dry_run is True, skip compilation of template""" compilation_target = Path(tmpdir, 'target.tmp') template = template_directory / 'no_context.template' compile_dict = { 'content': 'no_context.template', 'target': str(compilation_target), } compile_action = CompileAction( options=compile_dict, directory=template_directory, replacer=lambda x: x, context_store={}, ) caplog.clear() compilations = compile_action.execute(dry_run=True) # Check that the "compilation" is actually logged assert 'SKIPPED:' in caplog.record_tuples[0][2] assert str(template) in caplog.record_tuples[0][2] assert str(compilation_target) in caplog.record_tuples[0][2] # The template should still be returned assert template in compilations # And the compilation pair should be persisted assert compile_action.performed_compilations() == { template: {compilation_target}, } # But the file should not be compiled assert not compilations[template].exists()