Showing
1 changed file
with
42 additions
and
0 deletions
1 | +# -*- coding: utf-8 - | ||
2 | +import os | ||
3 | +from munch import munchify, Munch, fromYAML | ||
4 | +from json import load | ||
5 | +from robot.output import LOGGER | ||
6 | +from robot.output.loggerhelper import Message | ||
7 | +from robot.libraries.BuiltIn import BuiltIn | ||
8 | + | ||
9 | + | ||
10 | +from .initial_data import ( | ||
11 | + test_tender_data, test_question_data, test_question_answer_data, | ||
12 | + test_bid_data | ||
13 | +) | ||
14 | + | ||
15 | + | ||
16 | +def log_object_data(data, file_name="", format="yaml"): | ||
17 | + if not isinstance(data, Munch): | ||
18 | + data = munchify(data) | ||
19 | + if format == 'json': | ||
20 | + data = data.toJSON(indent=2) | ||
21 | + else: | ||
22 | + data = data.toYAML(allow_unicode=True, default_flow_style=False) | ||
23 | + format = 'yaml' | ||
24 | + LOGGER.log_message(Message(data, "INFO")) | ||
25 | + if file_name: | ||
26 | + output_dir = BuiltIn().get_variable_value("${OUTPUT_DIR}") | ||
27 | + with open(os.path.join(output_dir, file_name + '.' + format), "w") as file_obj: | ||
28 | + file_obj.write(data) | ||
29 | + | ||
30 | + | ||
31 | +def load_initial_data_from(file_name): | ||
32 | + if not os.path.exists(file_name): | ||
33 | + file_name = os.path.join(os.path.dirname(__file__), 'data/{}'.format(file_name)) | ||
34 | + with open(file_name) as file_obj: | ||
35 | + if file_name.endswith(".json"): | ||
36 | + return Munch.fromDict(load(file_obj)) | ||
37 | + elif file_name.endswith(".yaml"): | ||
38 | + return fromYAML(file_obj) | ||
39 | + | ||
40 | + | ||
41 | +def prepare_test_tender_data(): | ||
42 | + return munchify({'data': test_tender_data}) |
Please
register
or
login
to post a comment