How to use load_report_from_file method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

xml.py

Source:xml.py Github

copy

Full Screen

...259 if xml_teardown is not None:260 report.test_session_teardown = Result()261 _unserialize_result(xml_teardown, report.test_session_teardown)262 return report263def load_report_from_file(filename):264 try:265 with open(filename, "r") as fh:266 xml = ET.parse(fh)267 except ET.LxmlError as e:268 raise ReportLoadingError(str(e))269 except IOError as e:270 raise e # re-raise as-is271 try:272 root = xml.getroot().xpath("/lemoncheesecake-report")[0]273 except IndexError:274 raise ReportLoadingError("Cannot find lemoncheesecake-report element in XML")275 report_version = float(root.attrib["report-version"])276 if report_version >= 2.0:277 raise ReportLoadingError("Incompatible report version: got %s while 1.x is supported" % report_version)278 return _unserialize_report(root)279class XmlBackend(FileReportBackend, ReportUnserializerMixin):280 def __init__(self):281 self.indent_level = DEFAULT_INDENT_LEVEL282 def get_name(self):283 return "xml"284 def is_available(self):285 return LXML_IS_AVAILABLE286 def get_report_filename(self):287 return "report.xml"288 def save_report(self, filename, report):289 save_report_into_file(report, filename, self.indent_level)290 def load_report(self, path):291 report = load_report_from_file(path)292 report.bind(self, path)...

Full Screen

Full Screen

json_.py

Source:json_.py Github

copy

Full Screen

...205 if "test_session_teardown" in json_report:206 report.test_session_teardown = Result()207 _unserialize_result(json_report["test_session_teardown"], report.test_session_teardown)208 return report209def load_report_from_file(filename):210 try:211 with open(filename, "r") as fh:212 js_content = fh.read()213 except IOError as e:214 raise e # re-raise as-is215 js_content = re.sub("^" + JS_PREFIX, "", js_content)216 try:217 js = json.loads(js_content)218 except ValueError as e:219 raise ReportLoadingError(str(e))220 report_version = js.get("report_version")221 if report_version is None:222 raise ReportLoadingError("Cannot find 'report_version' in JSON")223 if report_version >= 2.0:224 raise ReportLoadingError("Incompatible report version: got %s while 1.x is supported" % report_version)225 return _unserialize_report(js)226class JsonBackend(FileReportBackend, ReportUnserializerMixin):227 def __init__(self, javascript_compatibility=True, pretty_formatting=False):228 self.javascript_compatibility = javascript_compatibility229 self.pretty_formatting = pretty_formatting230 def get_name(self):231 return "json"232 def get_report_filename(self):233 return "report.js"234 def save_report(self, filename, report):235 save_report_into_file(236 report, filename,237 javascript_compatibility=self.javascript_compatibility, pretty_formatting=self.pretty_formatting238 )239 def load_report(self, path):240 report = load_report_from_file(path)241 report.bind(self, path)...

Full Screen

Full Screen

test_report_backend.py

Source:test_report_backend.py Github

copy

Full Screen

1import time2import pytest3from lemoncheesecake.reporting import Report, XmlBackend, JsonBackend, load_report, load_reports_from_dir4from lemoncheesecake.reporting.backends.xml import \5 save_report_into_file as save_xml, \6 load_report_from_file as load_xml7from lemoncheesecake.reporting.backends.json_ import \8 save_report_into_file as save_json, \9 load_report_from_file as load_json10from lemoncheesecake.reporting.backend import get_reporting_backend_names, parse_reporting_backend_names_expression11from helpers.report import assert_report12@pytest.fixture()13def sample_report():14 report = Report()15 ts = time.time()16 report.start_time = ts17 report.end_time = ts18 report.saving_time = ts19 return report20def _test_save_report(tmpdir, sample_report, backend, load_func):21 filename = tmpdir.join("report").strpath22 backend.save_report(filename, sample_report)23 report = load_func(filename)24 assert_report(report, sample_report)25def test_save_report_json(tmpdir, sample_report):26 _test_save_report(tmpdir, sample_report, JsonBackend(), load_json)27def _test_load_report(tmpdir, sample_report, save_func):28 filename = tmpdir.join("report").strpath29 save_func(sample_report, filename)30 report = load_report(filename)31 assert_report(report, sample_report)32def test_load_report_json(tmpdir, sample_report):33 _test_load_report(tmpdir, sample_report, save_json)34def test_save_loaded_report(tmpdir, sample_report):35 filename = tmpdir.join("report").strpath36 save_json(sample_report, filename)37 loaded_report = load_report(filename)38 loaded_report.end_time += 139 loaded_report.save()40 reloaded_report = load_report(filename)41 assert reloaded_report.end_time == loaded_report.end_time42try:43 import lxml44except ImportError:45 pass46else:47 def test_load_report_xml(tmpdir, sample_report):48 _test_load_report(tmpdir, sample_report, save_xml)49 def test_save_report_xml(tmpdir, sample_report):50 _test_save_report(tmpdir, sample_report, XmlBackend(), load_xml)51 def test_load_reports_from_dir(tmpdir, sample_report):52 save_xml(sample_report, tmpdir.join("report.xml").strpath)53 save_json(sample_report, tmpdir.join("report.js").strpath)54 tmpdir.join("report.txt").write("foobar")55 reports = list(load_reports_from_dir(tmpdir.strpath))56 assert_report(reports[0], sample_report)57 assert_report(reports[1], sample_report)58 assert "json" in [r.backend.get_name() for r in reports]59 assert "xml" in [r.backend.get_name() for r in reports]60def _test_get_reporting_backend_names(specified, expected):61 assert get_reporting_backend_names(("console", "html", "json"), specified) == expected62def test_reporting_fixed_one():63 _test_get_reporting_backend_names(("console",), ("console",))64def test_reporting_fixed_two():65 _test_get_reporting_backend_names(("html", "json"), ("html", "json"))66def test_reporting_fixed_turn_on():67 _test_get_reporting_backend_names(("+junit",), ("console", "html", "json", "junit"))68def test_reporting_fixed_turn_off():69 _test_get_reporting_backend_names(("^console",), ("html", "json"))70def test_reporting_fixed_turn_on_and_off():71 _test_get_reporting_backend_names(("+junit", "^console"), ("html", "json", "junit"))72def test_reporting_fixed_invalid_mix():73 with pytest.raises(ValueError):74 get_reporting_backend_names(("console", "html", "json"), ("console", "+junit"))75def test_reporting_fixed_invalid_turn_off():76 with pytest.raises(ValueError):77 get_reporting_backend_names(("console", "html", "json"), ("^unknown",))78def test_parse_reporting_backend_names_expression():...

Full Screen

Full Screen

test_report_serialization_xml.py

Source:test_report_serialization_xml.py Github

copy

Full Screen

...19 def test_load_report_non_xml(tmpdir):20 file = tmpdir.join("report.xml")21 file.write("foobar")22 with pytest.raises(ReportLoadingError):23 load_report_from_file(file.strpath)24 def test_load_report_bad_xml(tmpdir):25 file = tmpdir.join("report.xml")26 file.write("<value>foobar</value>")27 with pytest.raises(ReportLoadingError):28 load_report_from_file(file.strpath)29 def test_load_report_incompatible_version(report_in_progress, tmpdir):30 filename = tmpdir.join("report.xml").strpath31 save_report_into_file(report_in_progress, filename)32 with open(filename, "r") as fh:33 xml = ET.parse(fh)34 root = xml.getroot().xpath("/lemoncheesecake-report")[0]35 root.attrib["report-version"] = "2.0"36 if six.PY3:37 xml_content = ET.tostring(root, pretty_print=True, encoding="unicode")38 else:39 xml_content = ET.tostring(root, pretty_print=True, xml_declaration=True, encoding="utf-8")40 with open(filename, "w") as fh:41 fh.write(xml_content)42 with pytest.raises(ReportLoadingError, match="Incompatible"):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Lemoncheesecake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful