def test_image_override_config_help_template(mocker, tmpdir): """Test that help_template defined in image.yaml overrides help_template defined in the config""" help_template1 = os.path.join(str(tmpdir), "help1.jinja") with open(help_template1, "w") as fd: fd.write("1") config = setup_config(tmpdir, "[doc]\nhelp_template = {}".format(help_template1)) help_template2 = os.path.join(str(tmpdir), "help2.jinja") with open(help_template2, "w") as fd: fd.write("2") my_image_descriptor = image_descriptor.copy() my_image_descriptor['help'] = {'template': help_template2} mocker.patch.object(sys, 'argv', ['cekit', '-v', '--config', config, 'generate']) with Chdir(str(tmpdir)): with open('image.yaml', 'w') as fd: yaml.dump(my_image_descriptor, fd, default_flow_style=False) c = Cekit().parse() c.configure() try: c.run() except SystemExit: pass with open("target/image/help.md", "r") as fd: contents = fd.read() assert contents == "2"
def test_image_override_help_template(mocker, tmpdir): """Test that help_template defined in image.yaml is used for generating help.md""" help_template = os.path.join(str(tmpdir), "help.jinja") with open(help_template, "w") as fd: fd.write(template_teststr) config = setup_config(tmpdir, "") my_image_descriptor = image_descriptor.copy() my_image_descriptor['help'] = {'template': help_template} mocker.patch.object(sys, 'argv', ['cekit', '-v', '--config', config, 'generate']) with Chdir(str(tmpdir)): with open('image.yaml', 'w') as fd: yaml.dump(my_image_descriptor, fd, default_flow_style=False) c = Cekit().parse() c.configure() try: c.run() except SystemExit: pass with open("target/image/help.md", "r") as fd: contents = fd.read() assert contents.find(template_teststr) >= 0
def run_cekit_return_dockerfile(mocker, workdir, argv, getservbyport=getservbyport_works): """utility function to invoke cekit and return the generated Dockerfile""" mocker.patch.object(sys, 'argv', argv) mocker.patch.object(socket, 'getservbyport', getservbyport) with Chdir(str(workdir)): if os.path.exists('target'): shutil.rmtree('target') c = Cekit().parse() c.configure() try: c.run() except SystemExit: pass with open("target/image/Dockerfile", "r") as fd: return fd.read()
def test_no_override_help_template(mocker, workdir, tmpdir): cleanup(workdir) config = setup_config(tmpdir, "") mocker.patch.object(sys, 'argv', ['cekit', '-v', '--config', config, 'generate']) with Chdir(workdir): c = Cekit().parse() c.configure() try: c.run() except SystemExit: pass with open("target/image/help.md", "r") as fd: contents = fd.read() sys.stderr.write("JMTD: {}\n".format( contents.find(template_teststr))) assert -1 == contents.find(template_teststr)
def test_config_override_help_template(mocker, workdir, tmpdir): cleanup(workdir) help_template = os.path.join(workdir, "help.jinja") with open(help_template, "w") as fd: fd.write(template_teststr) config = setup_config(tmpdir, "[doc]\nhelp_template = {}".format(help_template)) mocker.patch.object(sys, 'argv', ['cekit', '-v', '--config', config, 'generate']) with Chdir(workdir): c = Cekit().parse() c.configure() try: c.run() except SystemExit: pass with open("target/image/help.md", "r") as fd: contents = fd.read() assert contents.find(template_teststr) >= 0
def run_cekit(cwd): with Chdir(cwd): # run cekit and check it exits with 0 with pytest.raises(SystemExit) as system_exit: Cekit().parse().run() assert system_exit.value.code == 0
def run_cekit(cwd): with Chdir(cwd): c = Cekit().parse() c.configure() return c.generator._params['addhelp']