utiliser un formatage de chaîne compatible python2
This commit is contained in:
parent
ade2b385f0
commit
0375220258
|
@ -75,7 +75,7 @@ class ExpectationCollection:
|
||||||
def add_expectation(self, expectation):
|
def add_expectation(self, expectation):
|
||||||
if expectation.get_pattern() in self.expectations_lookup:
|
if expectation.get_pattern() in self.expectations_lookup:
|
||||||
if expectation.context in [exp.context for exp in self.expectations_lookup[expectation.get_pattern()]]:
|
if expectation.context in [exp.context for exp in self.expectations_lookup[expectation.get_pattern()]]:
|
||||||
print(f'Can not add {expectation} to collection')
|
print('Can not add {} to collection'.format(expectation))
|
||||||
return False
|
return False
|
||||||
self.expectations_lookup[expectation.get_pattern()] = self.expectations_lookup.setdefault(expectation.get_pattern(), []) + [expectation]
|
self.expectations_lookup[expectation.get_pattern()] = self.expectations_lookup.setdefault(expectation.get_pattern(), []) + [expectation]
|
||||||
return True
|
return True
|
||||||
|
@ -123,7 +123,7 @@ class Expectation:
|
||||||
self.next = {}
|
self.next = {}
|
||||||
|
|
||||||
def get_pattern(self, previous_answer=None):
|
def get_pattern(self, previous_answer=None):
|
||||||
return re.compile(f'(.*){re.escape(self.pattern.format(variable=previous_answer))}(.*)')
|
return re.compile(r'(.*){}(.*)'.format(re.escape(self.pattern.format(variable=previous_answer))))
|
||||||
|
|
||||||
def set_next_expectation(self, expectation, triggers=None):
|
def set_next_expectation(self, expectation, triggers=None):
|
||||||
if not isinstance(triggers, list):
|
if not isinstance(triggers, list):
|
||||||
|
@ -132,19 +132,19 @@ class Expectation:
|
||||||
self.next[trigger] = expectation
|
self.next[trigger] = expectation
|
||||||
|
|
||||||
def set_response(self, response):
|
def set_response(self, response):
|
||||||
print(f'Setting {response} for {self.pattern}')
|
print('Setting {} for {}'.format(response, self.pattern))
|
||||||
self.response = response
|
self.response = response
|
||||||
|
|
||||||
def expect(self, spawned, previous_answer=None):
|
def expect(self, spawned, previous_answer=None):
|
||||||
print(f'-> expecting next "{self.pattern.format(variable=previous_answer)}"')
|
print('-> expecting next "{}"'.format(self.pattern.format(variable=previous_answer)))
|
||||||
p = spawned.expect([pexpect.EOF, pexpect.TIMEOUT, self.get_pattern(previous_answer=previous_answer)])
|
p = spawned.expect([pexpect.EOF, pexpect.TIMEOUT, self.get_pattern(previous_answer=previous_answer)])
|
||||||
if p not in [0, 1]:
|
if p not in [0, 1]:
|
||||||
self.answer(spawned)
|
self.answer(spawned)
|
||||||
else:
|
else:
|
||||||
print(f'-> before: {spawned.before}\n-> after: {spawned.after}\n-> {self.pattern}')
|
print('-> before: {}\n-> after: {}\n-> {}'.format(spawned.before, spawned_after, self.pattern))
|
||||||
|
|
||||||
def answer(self, spawned):
|
def answer(self, spawned):
|
||||||
print(f'-> answering "{self.response}" to "{spawned.after}"')
|
print('-> answering "{}" to "{}"'.format(self.response, spawned.after))
|
||||||
if self.response is not None:
|
if self.response is not None:
|
||||||
spawned.sendline(self.response)
|
spawned.sendline(self.response)
|
||||||
if self.response in self.next:
|
if self.response in self.next:
|
||||||
|
@ -309,17 +309,17 @@ def run_module():
|
||||||
result['module'] = module.params["module"]
|
result['module'] = module.params["module"]
|
||||||
if module.params.get('variables', None) and not set(module.params['variables'].keys()).issubset(set(expectations.get_exposed_expectation_names())):
|
if module.params.get('variables', None) and not set(module.params['variables'].keys()).issubset(set(expectations.get_exposed_expectation_names())):
|
||||||
unknown_variables = list(set(module.params['variables'].keys()).difference(set(expectations.get_exposed_expectation_names())))
|
unknown_variables = list(set(module.params['variables'].keys()).difference(set(expectations.get_exposed_expectation_names())))
|
||||||
result['msg'] += f"Variables {unknown_variables} not available\n"
|
result['msg'] += "Variables {} not available\n".format(unknown_variables)
|
||||||
else:
|
else:
|
||||||
for variable in module.params.get('variables', {}).keys():
|
for variable in module.params.get('variables', {}).keys():
|
||||||
result['msg'] += f"Overloading variable {variable}\n"
|
result['msg'] += "Overloading variable {}\n".format(variable)
|
||||||
else:
|
else:
|
||||||
result['msg'] += f'Module {module.module} not supported\n'
|
result['msg'] += 'Module {} not supported\n'.format(module.module)
|
||||||
module.exit_json(**result)
|
module.exit_json(**result)
|
||||||
|
|
||||||
|
|
||||||
if module.params['module'] not in supported_modules:
|
if module.params['module'] not in supported_modules:
|
||||||
result['msg'] += f"Unsupported module {module.params['module']}\n"
|
result['msg'] += "Unsupported module {}\n".format(module.params['module'])
|
||||||
module.fail_json(**result)
|
module.fail_json(**result)
|
||||||
else:
|
else:
|
||||||
result['module'] = module.params['module']
|
result['module'] = module.params['module']
|
||||||
|
@ -327,7 +327,7 @@ def run_module():
|
||||||
if module.params.get('variables', None):
|
if module.params.get('variables', None):
|
||||||
if not set(module.params['variables'].keys()).issubset(set(expectations.get_exposed_expectation_names())):
|
if not set(module.params['variables'].keys()).issubset(set(expectations.get_exposed_expectation_names())):
|
||||||
unknown_variables = list(set(module.params['variables'].keys()).difference(set(expectations.get_exposed_expectation_names())))
|
unknown_variables = list(set(module.params['variables'].keys()).difference(set(expectations.get_exposed_expectation_names())))
|
||||||
result['msg'] += f"Variables {unknown_variables} not available\n"
|
result['msg'] += "Variables {} not available\n".format(unknown_variables)
|
||||||
module.fail_json(**result)
|
module.fail_json(**result)
|
||||||
else:
|
else:
|
||||||
for expectation_name, response in module.params['variables'].items():
|
for expectation_name, response in module.params['variables'].items():
|
||||||
|
@ -342,7 +342,7 @@ def run_module():
|
||||||
if p == 0:
|
if p == 0:
|
||||||
break
|
break
|
||||||
if p == 1:
|
if p == 1:
|
||||||
print(f'Some missing expectations for {instance_process.before}{instance_process.after}')
|
print('Some missing expectations for {}{}'.format(instance_process.before, instance_process.after))
|
||||||
break
|
break
|
||||||
pattern = patterns[p]
|
pattern = patterns[p]
|
||||||
for expectation in expectations.get_expectations_by_pattern(patterns[p]):
|
for expectation in expectations.get_expectations_by_pattern(patterns[p]):
|
||||||
|
@ -351,7 +351,7 @@ def run_module():
|
||||||
break
|
break
|
||||||
some_index += 1
|
some_index += 1
|
||||||
result['changed'] = True
|
result['changed'] = True
|
||||||
result['msg'] += f"Module {result['module']} instanciated"
|
result['msg'] += "Module {} instanciated".format(result['module'])
|
||||||
module.exit_json(**result)
|
module.exit_json(**result)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
result['msg'] += err
|
result['msg'] += err
|
||||||
|
|
Loading…
Reference in New Issue