Best Python code snippet using avocado_python
data_dir.py
Source:data_dir.py
...43USER_BASE_DIR = os.path.expanduser('~/avocado')44USER_TEST_DIR = os.path.join(USER_BASE_DIR, 'tests')45USER_DATA_DIR = os.path.join(USER_BASE_DIR, 'data')46USER_LOG_DIR = os.path.join(USER_BASE_DIR, 'job-results')47def _get_settings_dir(dir_name):48 """49 Returns a given "datadir" directory as set by the configuration system50 """51 return settings.settings.get_value('datadir.paths', dir_name, 'path')52def _get_rw_dir(settings_location, system_location, user_location):53 if utils_path.usable_rw_dir(settings_location):54 return settings_location55 if utils_path.usable_rw_dir(system_location):56 return system_location57 user_location = os.path.expanduser(user_location)58 if utils_path.usable_rw_dir(user_location):59 return user_location60def get_base_dir():61 """62 Get the most appropriate base dir.63 The base dir is the parent location for most of the avocado other64 important directories.65 Examples:66 * Log directory67 * Data directory68 * Tests directory69 """70 return _get_rw_dir(_get_settings_dir('base_dir'),71 SYSTEM_BASE_DIR, USER_BASE_DIR)72def get_test_dir():73 """74 Get the most appropriate test location.75 The test location is where we store tests written with the avocado API.76 The heuristics used to determine the test dir are:77 1) If an explicit test dir is set in the configuration system, it78 is used.79 2) If user is running Avocado out of the source tree, the example80 test dir is used81 3) System wide test dir is used82 4) User default test dir (~/avocado/tests) is used83 """84 configured = _get_settings_dir('test_dir')85 if utils_path.usable_ro_dir(configured):86 return configured87 if settings.settings.intree:88 return _IN_TREE_TESTS_DIR89 if utils_path.usable_ro_dir(SYSTEM_TEST_DIR):90 return SYSTEM_TEST_DIR91 if utils_path.usable_ro_dir(USER_TEST_DIR):92 return USER_TEST_DIR93def get_data_dir():94 """95 Get the most appropriate data dir location.96 The data dir is the location where any data necessary to job and test97 operations are located.98 Examples:99 * ISO files100 * GPG files101 * VM images102 * Reference bitmaps103 """104 return _get_rw_dir(_get_settings_dir('data_dir'),105 SYSTEM_DATA_DIR, USER_DATA_DIR)106def get_datafile_path(*args):107 """108 Get a path relative to the data dir.109 :param args: Arguments passed to os.path.join. Ex ('images', 'jeos.qcow2')110 """111 new_args = tuple([get_data_dir()] + list(args))112 return os.path.join(*new_args)113def get_logs_dir():114 """115 Get the most appropriate log dir location.116 The log dir is where we store job/test logs in general.117 """118 return _get_rw_dir(_get_settings_dir('logs_dir'),119 SYSTEM_LOG_DIR, USER_LOG_DIR)120def create_job_logs_dir(logdir=None, unique_id=None):121 """122 Create a log directory for a job, or a stand alone execution of a test.123 :param logdir: Base log directory, if `None`, use value from configuration.124 :param unique_id: The unique identification. If `None`, create one.125 :rtype: basestring126 """127 start_time = time.strftime('%Y-%m-%dT%H.%M')128 if logdir is None:129 logdir = get_logs_dir()130 if not os.path.exists(logdir):131 utils_path.init_dir(logdir)132 # Stand alone tests handling...
json_manipulator.py
Source:json_manipulator.py
1import json2import os3def _get_settings_dir():4 current_dir = os.path.abspath(__file__).split('/')5 relativ_dir = 'settings/io_devices.json'6 current_dir = current_dir[:-2]7 current_dir.append(relativ_dir)8 settings_dir = '/'.join(current_dir)9 return settings_dir10class DevicesIO:11 path = _get_settings_dir()12 def __init__(self):13 with open(self.path, "r") as read_file:14 self.data = json.load(read_file)15 def __str__(self):16 return str(self.data)17 def write_to_disc(self):18 with open(self.path, "w") as write_file:19 json.dump(self.data, write_file)20 def set_input(self, value):21 self.data['input'] = value22 self.write_to_disc()23 def set_output(self, value):24 self.data['output'] = value25 self.write_to_disc()...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!