Best Python code snippet using autotest_python
__init__.py
Source:__init__.py
...108 self.buffer = []109 self.count = 1110 def _line_is_blank(self, msg):111 return len(msg) == 0 or re.match(r'^[ \t]+$', msg)112 def write_logline(self, msg):113 if not self._line_is_blank(msg):114 time_ns = time.time()115 self.logger.info("{} - {} - {} - {:.6f} - {}".format(self.name, self.start_time, self.count, time_ns, msg))116 self.count += 1117 def log(self, msg):118 self.write_logline("SolUpenBmc: {}".format(msg))119 def _is_last_line(self, idx, messages):120 return idx+1 == len(messages)121 def save_to_buffer(self, message):122 self.buffer.append(message)123 def read_from_buffer(self):124 return "".join(self.buffer)125 def clear_buffer(self):126 self.buffer = []127 def write(self, msg):128 """ Redfish data is transfered in frames and sometimes one line comes in 2 messages. We need to buffer them. """129 messages = msg.split("\n")130 for lineno, message in enumerate(messages):131 if self._is_last_line(lineno, messages):132 self.save_to_buffer(message)133 else:134 buffer = self.read_from_buffer()135 self.clear_buffer()136 self.write_logline("{}{}".format(buffer, message))137class UnbufferedRawFileWriter:138 """139 Class that generates file names in the format: $OUTPUT_DIR/$NODE.raw140 """141 def __init__(self, name, output_directory):142 filename = "{}.raw".format(os.path.join(output_directory, name))143 handler = logging.handlers.RotatingFileHandler(filename, mode='a', maxBytes=10485760, backupCount=3)144 self.name = name145 self.start_time = int(time.time())146 self.logger = logging.getLogger("Raw Log: {}".format(self.start_time))147 self.logger.setLevel(logging.INFO)148 self.logger.addHandler(handler)149 def write(self, msg):150 time_ns = time.time()...
monitors_util_unittest.py
Source:monitors_util_unittest.py
...27 self.assertEquals(28 '%s\t%s' % (self.formatted_time_tuple, self.msg), timestamped)29 def test_write_logline_with_timestamp(self):30 logfile = StringIO.StringIO()31 monitors_util.write_logline(logfile, self.msg, self.format)32 logfile.seek(0)33 written = logfile.read()34 self.assertEquals(35 '%s\t%s\n' % (self.formatted_time_tuple, self.msg), written)36 def test_write_logline_without_timestamp(self):37 logfile = StringIO.StringIO()38 monitors_util.write_logline(logfile, self.msg)39 logfile.seek(0)40 written = logfile.read()41 self.assertEquals(42 '%s\n' % self.msg, written)43class AlertHooksTestCase(unittest.TestCase):44 def setUp(self):45 self.msg_template = 'alert yay %s haha %s'46 self.params = ('foo', 'bar')47 self.epoch_seconds = 1225501829.930061148 # Stub out time.time49 self.orig_time = time.time50 time.time = lambda: self.epoch_seconds51 def tearDown(self):52 time.time = self.orig_time...
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!!