diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2020-09-27 16:58:35 +0200 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2020-09-27 16:58:35 +0200 |
| commit | 20e0b28ec3c8e9e0a63759116a32438c18941a59 (patch) | |
| tree | ee426189825867a0d98358154da3660c48ca5957 /src/test/test.py | |
| parent | 861621b9bdbdc7336183597b3ffd4ee161be19f3 (diff) | |
| download | philosophers_test-20e0b28ec3c8e9e0a63759116a32438c18941a59.tar.gz philosophers_test-20e0b28ec3c8e9e0a63759116a32438c18941a59.tar.bz2 philosophers_test-20e0b28ec3c8e9e0a63759116a32438c18941a59.zip | |
Added log checking
Diffstat (limited to 'src/test/test.py')
| -rw-r--r-- | src/test/test.py | 56 |
1 files changed, 23 insertions, 33 deletions
diff --git a/src/test/test.py b/src/test/test.py index 7be1d18..14ee097 100644 --- a/src/test/test.py +++ b/src/test/test.py @@ -6,16 +6,21 @@ # By: charles <me@cacharle.xyz> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/09/27 11:36:32 by charles #+# #+# # -# Updated: 2020/09/27 13:28:15 by charles ### ########.fr # +# Updated: 2020/09/27 16:25:37 by charles ### ########.fr # # # # ############################################################################ # import re +import time import subprocess # import threading # from result import Result +import philo +# from test.table import Table + + class Test: #(threading.Thread): _tests = [] @@ -59,44 +64,35 @@ class Test: #(threading.Thread): if self._meal_num is not None: argv.append(str(self._meal_num)) # try: - process_result = subprocess.run( + process = subprocess.Popen( argv, stdout=subprocess.PIPE, stderr=subprocess.STDOUT ) - output = process_result.stdout.decode() - print(output) + # output = process_result.stdout.decode() + # print(output) # timeout=1, # except subprocess.TimeoutExpered as err: # return Result(err) # except subprocess.CalledProcessError as err: # return Result(err) - self._check_output(output) - # return Result() + self._check_output(process.stdout) + process.wait() def _check_output(self, stream): - # table = Table(self._philo_num) - - for line in stream.split('\n'): - match = re.match( - "^(?P<timestamp>\d+) " - "(?P<id>\d+) " - "(?P<event>is thinking|is eating|is sleeping|died)$", - line - ) - if match is None: - print("Bad line format |{}|".format(line)) - return - - print(match.group('event')) - try: - timestamp = int(match.group("timestamp")) - # if timestamp < 0 - except ValueError: - print("Invalid timestamp value {}".format(match.group("timestamp"))) - - table.add_log(match) + table = philo.Table(self._philo_num) + + for line in stream: + line = line.decode()[:-1] + # print(">", line) + l = philo.Log(line, self._philo_num) + print(l) + table.add_log(l) + table.check() + + # print(timestamp, id_, event) + # philo_states.append(Philo) @@ -104,9 +100,3 @@ class Test: #(threading.Thread): # Test._stdout_lock.aquire() # print(*args) # Test._stdout_lock.release() - -# from enum import Enum -# class PhiloEvent(Enum): -# EATING = 1 -# SLEEPING = 2 -# THINKING = 3 |
