Liste récursive des interactions
This commit is contained in:
parent
9887189b38
commit
879a042487
@ -36,10 +36,10 @@ final = Expectation("""1 -> Ne rien faire
|
||||
|
||||
Entrez le numéro de votre choix :""", response='2', name='final')
|
||||
|
||||
|
||||
expectations.add_expectation(already_registered)
|
||||
expectations.add_expectation(network_configuration)
|
||||
expectations.add_expectation(new_server)
|
||||
expectations.add_expectation(zephir_address)
|
||||
expectations.add_expectation(hardware)
|
||||
expectations.add_expectation(key_available)
|
||||
expectations.add_expectation(final)
|
||||
@ -48,6 +48,7 @@ network_configuration.set_next_expectation(interface_name, triggers=['O', 'Oui',
|
||||
interface_name.set_next_expectation(network_address)
|
||||
network_address.set_next_expectation(network_netmask)
|
||||
network_netmask.set_next_expectation(gateway)
|
||||
network_configuration.set_next_expectation(zephir_address, triggers=['N', 'Non', 'NON'])
|
||||
|
||||
new_server.set_next_expectation(rne, triggers=['N', 'Non', 'NON'])
|
||||
rne.set_next_expectation(server_id, triggers='')
|
||||
|
@ -37,8 +37,7 @@ class ExpectationCollection:
|
||||
expectations = [exp for exps in self.expectations_lookup.values() for exp in exps]
|
||||
if recursive:
|
||||
expectations.extend([exp for exps in expectations for exp in exps.get_following_expectations()])
|
||||
pass
|
||||
return expectations
|
||||
return list(set(expectations))
|
||||
|
||||
def count_expectations(self):
|
||||
return len(self.get_expectations(recursive=True))
|
||||
@ -70,7 +69,7 @@ class Expectation:
|
||||
self.response = response
|
||||
|
||||
def expect(self, spawned, previous_answer=None):
|
||||
print(f'-> expecting next "{self.pattern.format(variable=previous_answer}"')
|
||||
print(f'-> expecting next "{self.pattern.format(variable=previous_answer)}"')
|
||||
p = spawned.expect([pexpect.EOF, pexpect.TIMEOUT, self.get_pattern(previous_answer=previous_answer)])
|
||||
if p not in [0, 1]:
|
||||
self.answer(spawned)
|
||||
@ -99,6 +98,8 @@ class Expectation:
|
||||
return True
|
||||
|
||||
def get_following_expectations(self):
|
||||
for next_expectation in self.next.values():
|
||||
return [next_expectation] + next_expectation.get_following_expectations()
|
||||
return []
|
||||
following = []
|
||||
for next_expectation in set(self.next.values()):
|
||||
following.append(next_expectation)
|
||||
following.extend(next_expectation.get_following_expectations())
|
||||
return following
|
||||
|
Loading…
Reference in New Issue
Block a user