def test_test(): from jinja2 import contextfilter @contextfilter def url(context, base): return base + "/" + context["project"] + "/" + context["version"] + "/" def is_fiveOrAbove(val): return int(val.split(".")[0]) >= 5 context = {"version": "5.0.1", "project": "yinja"} yaml_text = """ yinja: text: project text2: version url: {{ 'http://example.com'|url if version is above5 else 'http://example.com' }} """ env = dict(filters=dict(url=url), tests=dict(above5=is_fiveOrAbove)) result = load(yaml_text, context, jinja_env=env, patchable=False) result = result["yinja"] assert result["text"] == "project" assert result["text2"] == "version" assert result["url"] == "http://example.com/yinja/5.0.1/" context["version"] = "3.0.0" result = load(yaml_text, context, jinja_env=env, patchable=False) result = result["yinja"] assert result["text"] == "project" assert result["text2"] == "version" assert result["url"] == "http://example.com"
def test_patch_level2_no_patching(): p2a = load(p2.path, patchable=False) assert "patches" in p2a assert_dotted_key_matches("config.env", p2d, p2a) assert_dotted_key_matches("config.branch", p2d, p2a) assert_dotted_key_matches("projects.comp2.version_type", p2d, p2a) assert_dotted_key_matches("projects.comp3.version_type", p2d, p2a) assert_dotted_key_matches("projects.comp1.version_type", ConfigDict(), p2a)
def test_patch_level2(): p2a = load(p2.path) assert "patches" not in p2a assert_dotted_key_matches("config.env", p2d, p2a) assert_dotted_key_matches("config.branch", p2d, p2a) assert_dotted_key_matches("projects.comp1.version_type", p1d, p2a) assert_dotted_key_matches("projects.comp2.version_type", p2d, p2a) assert_dotted_key_matches("projects.comp3.version_type", p2d, p2a)
def test_context(): context = {"version": "5.0.1", "project": "yinja"} yaml_text = """ yinja: text: project text2: version url: http://{{ project }}.com/v{{ version }} """ result = load(yaml_text, context, patchable=False) result = result["yinja"] assert result["text"] == "project" assert result["text2"] == "version" assert result["url"] == "http://yinja.com/v5.0.1"
def test_filter(): from jinja2 import contextfilter @contextfilter def url(context, base): return base + "/" + context["project"] + "/" + context["version"] + "/" context = {"version": "5.0.1", "project": "yinja"} yaml_text = """ yinja: text: project text2: version url: {{ 'http://example.com'|url }} """ env = dict(filters=dict(url=url)) result = load(yaml_text, context, jinja_env=env, patchable=False) result = result["yinja"] assert result["text"] == "project" assert result["text2"] == "version" assert result["url"] == "http://example.com/yinja/5.0.1/"
def _load(cls, project_name, env='build', context=None, conf_path=None): if project_name in __PROJECTS__: return __PROJECTS__[project_name] settings = __ENV__.get(env, None) if not settings: file_name = env + '.yaml' if conf_path: file_name = Folder(conf_path).child(file_name) settings = yinja.load(file_name, context=context) __ENV__[env] = settings config = ConfigDict() config.update(settings.config) config.patch(settings.projects.get(project_name, dict())) project_type = config.get('type_name', 'gitbot.lib.build.Project') project_class = load_python_object(project_type) project = project_class(project_name, config, env, settings, context, conf_path) __PROJECTS__[project_name] = project return project
def test_load(): assert compare(p0d, load(p0.path))