Best Python code snippet using robotframework
ssh_runner.py
Source: ssh_runner.py
...65 self.variable_getter = user_options.pop('variable_getter', None)66 if self.variable_getter:67 assert isinstance(self.variable_getter, Variable), "Variable getter vtype error"68 self.parser: Parser = user_options.pop('parser', None)69 self._sudo_expected = is_truthy(user_options.pop('sudo', False))70 self._sudo_password_expected = is_truthy(user_options.pop('sudo_password', False))71 self._start_in_folder = user_options.pop('start_in_folder', None)72 # self._alias = user_options.pop('alias', None)73 self._ssh_options = dict(_normalize_method_arguments(method.__name__, **user_options))74 self._result_template = _ExecutionResult(**self._ssh_options)75 if self.parser:76 assert isinstance(self.parser, Parser), f"Parser type error [Error type: {type(self.parser).__name__}]"77 self._method = method78 self._command = command79 @property80 def command_template(self):81 _command_res = f'cd {self._start_in_folder}; ' if self._start_in_folder else ''82 _command = self._command.format(**self.variable_getter.result) if self.variable_getter else self._command83 if self._sudo_password_expected:84 _command_res += f'echo {{password}} | sudo --stdin --prompt "" {_command}'85 elif self._sudo_expected:86 _command_res += f'sudo {_command}'87 else:88 _command_res += _command89 return _command_res90 def __str__(self):91 return f"{self._method.__name__}: " \92 f"{', '.join([f'{a}' for a in [self._command] + [f'{k}={v}' for k, v in self._ssh_options.items()]])}" \93 f"{'; Parser: '.format(self.parser) if self.parser else ''}"94 def __call__(self, ssh_client: SSHLibrary, **runtime_options) -> Any:95 # ssh_client.switch_connection(str(ssh_client))96 if self._command is not None:97 command = self.command_template.format(**runtime_options)98 logger.debug(99 f"Executing: {self._method.__name__}({command}, "100 f"{', '.join([f'{k}={v}' for k, v in self._ssh_options.items()])})")101 output = self._method(ssh_client, command, **self._ssh_options)102 else:103 logger.debug(f"Executing: {self._method.__name__}"104 f"({', '.join([f'{k}={v}' for k, v in self._ssh_options.items()])})")105 output = self._method(ssh_client, **self._ssh_options)106 if self.parser:107 return self.parser(dict(self._result_template(output)))108 if self.variable_setter:109 self.variable_setter(output)110 return output111class SSHLibraryPlugInWrapper(plugin_runner_abstract, metaclass=ABCMeta):112 def __init__(self, parameters: DotDict, data_handler, *user_args, **user_options):113 self._sudo_expected = is_truthy(user_options.pop('sudo', False))114 self._sudo_password_expected = is_truthy(user_options.pop('sudo_password', False))115 super().__init__(parameters, data_handler, *user_args, **user_options)116 self._execution_counter = 0117 self._ssh = SSHLibrary()118 @property119 def content_object(self):120 return self._ssh121 @property122 def sudo_expected(self):123 return self._sudo_expected124 @property125 def sudo_password_expected(self):126 return self._sudo_password_expected127 def _close_ssh_library_connection_from_thread(self):128 try:...
interpreter.py
Source: interpreter.py
...18 def execute(self, stmt):19 stmt.accept(self)20 def evaluate(self, expr):21 return expr.accept(self)22 def is_truthy(self, obj):23 if not obj: 24 return False25 if isinstance(obj, bool): 26 return obj27 if isinstance(obj, float):28 if obj == 0:29 return False30 else:31 return True32 if isinstance(obj, str):33 if obj == '0':34 return False35 else:36 return True37 return True38 def is_equal(self, a, b):39 if a == None and b == None: return True40 if a == None: return False41 return a == b 42 def visit_expression_stmt(self, stmt):43 value = self.evaluate(stmt.expression)44 if self.verbose:45 print(value)46 return None47 def visit_fn_stmt(self, stmt):48 function = SussFunction(stmt, self.env)49 self.env.define(stmt.name, function)50 return None51 def visit_print_stmt(self, stmt):52 value = self.evaluate(stmt.expression)53 print(value)54 return None55 def visit_return_stmt(self, stmt):56 value = None57 if stmt.value != None:58 value = self.evaluate(stmt.value)59 raise Return(value)60 def visit_block_stmt(self, stmt):61 self.excecute_block(stmt.statements, Environment(self.env))62 return None63 def visit_if_stmt(self, stmt):64 if self.is_truthy(self.evaluate(stmt.condition)):65 self.execute(stmt.then_branch)66 elif stmt.else_branch != None:67 self.execute(stmt.else_branch) 68 return None69 def visit_while_stmt(self, stmt):70 while self.is_truthy(self.evaluate(stmt.condition)):71 self.execute(stmt.body)72 return None73 def excecute_block(self, statements, env):74 previous = self.env75 try:76 self.env = env77 for statement in statements:78 self.execute(statement)79 finally:80 self.env = previous81 def visit_let_stmt(self, stmt):82 value = None83 if stmt.initializer != None:84 value = self.evaluate(stmt.initializer)85 86 self.env.define(stmt.name, value)87 if self.verbose:88 print('%s <- %s' % (stmt.name, value))89 return None90 def visit_literal_expr(self, expr):91 return expr.value92 def visit_group_expr(self, expr):93 return self.evaluate(expr.expression)94 def visit_variable_expr(self, expr):95 return self.env.get(expr.name)96 def visit_assign_expr(self, expr):97 value = self.evaluate(expr.value)98 self.env.assign(expr.name, value)99 return value100 def visit_cast_expr(self, expr):101 value = self.evaluate(expr.name)102 if expr.kind.value == 'str':103 return str(value)104 elif expr.kind.value == 'num':105 return float(value)106 elif expr.kind.value == 'bool':107 value = value.lower()108 return bool(value)109 def visit_call_expr(self, expr):110 callee = self.evaluate(expr.callee)111 arguments = []112 for arg in expr.args:113 arguments.append(self.evaluate(arg))114 if not isinstance(callee, SussFunction):115 print('Error! Only able to call functions!')116 raise RuntimeError117 if len(arguments) != callee.arity():118 print('Expected %s arguments, but got %s.' % (callee.arity(), len(arguments)))119 return callee.call(self, arguments)120 def visit_listed_expr(self, expr):121 results = []122 op = expr.operator123 for child in expr.children:124 results.append(self.evaluate(child))125 126 left = results[0]127 if len(results) > 1:128 right = results[1]129 if op == '~':130 return not self.is_truthy(left)131 elif op == 'and':132 return self.is_truthy(left) and self.is_truthy(right)133 elif op == 'or':134 return self.is_truthy(left) or self.is_truthy(right)135 elif op == '!':136 fac, n = 1, left137 while n > 0:138 fac *= n139 n -= 1140 return fac141 elif op == '+':142 output = results[0]143 if isinstance(output, str):144 for term in results[1:len(results)]:145 output += str(term)146 else: 147 for term in results[1:len(results)]:148 output += term...
test_utils.py
Source: test_utils.py
...117 def test_get_filterset_for_model(self):118 self.assertEqual(get_filterset_for_model(Device), DeviceFilterSet)119 self.assertEqual(get_filterset_for_model(Site), SiteFilterSet)120class IsTruthyTest(TestCase):121 def test_is_truthy(self):122 self.assertTrue(is_truthy("true"))123 self.assertTrue(is_truthy("True"))124 self.assertTrue(is_truthy(True))125 self.assertTrue(is_truthy("yes"))126 self.assertTrue(is_truthy("on"))127 self.assertTrue(is_truthy("y"))128 self.assertTrue(is_truthy("1"))129 self.assertTrue(is_truthy(1))130 self.assertFalse(is_truthy("false"))131 self.assertFalse(is_truthy("False"))132 self.assertFalse(is_truthy(False))133 self.assertFalse(is_truthy("no"))134 self.assertFalse(is_truthy("n"))135 self.assertFalse(is_truthy(0))...
config.py
Source: config.py
1import os2def is_truthy(v):3 """4 Returns True if v is a true-like value, or False otherwise.5 >>> is_truthy(True)6 True7 >>> is_truthy("True")8 True9 >>> is_truthy("true")10 True11 >>> is_truthy("Yes")12 True13 >>> is_truthy("y")14 True15 >>> is_truthy(None)16 False17 >>> is_truthy(False)18 False19 >>> is_truthy("False")20 False21 >>> is_truthy("n")22 False23 >>> is_truthy("literally anything else")24 False25 """26 return (isinstance(v, bool) and bool(v)) or (27 isinstance(v, str) and v.lower() in ("1", "yes", "y", "true", "t")28 )29# when DEBUG is true, uvicorn will run in debug mode with autoreload enabled30DEBUG = is_truthy(os.environ.get("DEBUG", False))31# the set of corpora in the data folder32CORPORA_SET = ('abstracts', 'fulltexts')33# if env var USE_MEMMAP is truthy, loads word2vec models using the mmap='r' flag,34# which largely keeps them on disk and keeps a single copy when sharing between35# processes36USE_MEMMAP = is_truthy(os.environ.get("USE_MEMMAP", True))37# if env var MATERIALIZE_MODELS is truthy, load the models into memory once38# (this requires a pretty big instance, as we're looking at ~20GB of RAM)39MATERIALIZE_MODELS = is_truthy(os.environ.get("MATERIALIZE_MODELS", True))40# if WARM_CACHE is truthy, warms the model cache when this module is first imported41# (requires that MATERIALIZE_MODELS is true, since otherwise there's no cache to warm)42WARM_CACHE = MATERIALIZE_MODELS and is_truthy(os.environ.get("WARM_CACHE", True))43# if PARALLELIZE_QUERY is truthy or unspecified, queries year models in parallel44PARALLELIZE_QUERY = is_truthy(os.environ.get("PARALLELIZE_QUERY", False))45# integer number of pools to use for parallel year queries, default 446PARALLEL_POOLS = int(os.environ.get("PARALLEL_POOLS", 4))47# controls what backend joblib uses to start parallel jobs48# options are listed here: https://joblib.readthedocs.io/en/latest/generated/joblib.Parallel.html49PARALLEL_BACKEND = os.environ.get("PARALLEL_BACKEND", "loky")50# number of rq workers available, read from the environment51RQ_CONCURRENCY = int(os.environ.get("RQ_CONCURRENCY", -1))52def get_config_values():53 return {54 "DEBUG": DEBUG,55 "CORPORA_SET": CORPORA_SET,56 "USE_MEMMAP": USE_MEMMAP,57 "MATERIALIZE_MODELS": MATERIALIZE_MODELS,58 "WARM_CACHE": WARM_CACHE,...
Check out the latest blogs from LambdaTest on this topic:
When most firms employed a waterfall development model, it was widely joked about in the industry that Google kept its products in beta forever. Google has been a pioneer in making the case for in-production testing. Traditionally, before a build could go live, a tester was responsible for testing all scenarios, both defined and extempore, in a testing environment. However, this concept is evolving on multiple fronts today. For example, the tester is no longer testing alone. Developers, designers, build engineers, other stakeholders, and end users, both inside and outside the product team, are testing the product and providing feedback.
Agile project management is a great alternative to traditional methods, to address the customer’s needs and the delivery of business value from the beginning of the project. This blog describes the main benefits of Agile for both the customer and the business.
As everyone knows, the mobile industry has taken over the world and is the fastest emerging industry in terms of technology and business. It is possible to do all the tasks using a mobile phone, for which earlier we had to use a computer. According to Statista, in 2021, smartphone vendors sold around 1.43 billion smartphones worldwide. The smartphone penetration rate has been continuously rising, reaching 78.05 percent in 2020. By 2025, it is expected that almost 87 percent of all mobile users in the United States will own a smartphone.
Software testing is fueling the IT sector forward by scaling up the test process and continuous product delivery. Currently, this profession is in huge demand, as it needs certified testers with expertise in automation testing. When it comes to outsourcing software testing jobs, whether it’s an IT company or an individual customer, they all look for accredited professionals. That’s why having an software testing certification has become the need of the hour for the folks interested in the test automation field. A well-known certificate issued by an authorized institute kind vouches that the certificate holder is skilled in a specific technology.
It’s strange to hear someone declare, “This can’t be tested.” In reply, I contend that everything can be tested. However, one must be pleased with the outcome of testing, which might include failure, financial loss, or personal injury. Could anything be tested when a claim is made with this understanding?
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!!