From 20e0b28ec3c8e9e0a63759116a32438c18941a59 Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Sun, 27 Sep 2020 16:58:35 +0200 Subject: Added log checking --- src/test/__pycache__/__init__.cpython-38.pyc | Bin 185 -> 0 bytes src/test/__pycache__/test.cpython-38.pyc | Bin 1876 -> 0 bytes src/test/philo.py | 23 ----------- src/test/table.py | 23 ----------- src/test/test.py | 56 +++++++++++---------------- 5 files changed, 23 insertions(+), 79 deletions(-) delete mode 100644 src/test/__pycache__/__init__.cpython-38.pyc delete mode 100644 src/test/__pycache__/test.cpython-38.pyc delete mode 100644 src/test/philo.py delete mode 100644 src/test/table.py (limited to 'src/test') diff --git a/src/test/__pycache__/__init__.cpython-38.pyc b/src/test/__pycache__/__init__.cpython-38.pyc deleted file mode 100644 index 37cb896..0000000 Binary files a/src/test/__pycache__/__init__.cpython-38.pyc and /dev/null differ diff --git a/src/test/__pycache__/test.cpython-38.pyc b/src/test/__pycache__/test.cpython-38.pyc deleted file mode 100644 index ce4b3b7..0000000 Binary files a/src/test/__pycache__/test.cpython-38.pyc and /dev/null differ diff --git a/src/test/philo.py b/src/test/philo.py deleted file mode 100644 index c103bec..0000000 --- a/src/test/philo.py +++ /dev/null @@ -1,23 +0,0 @@ -# ############################################################################ # -# # -# ::: :::::::: # -# philo.py :+: :+: :+: # -# +:+ +:+ +:+ # -# By: charles +#+ +:+ +#+ # -# +#+#+#+#+#+ +#+ # -# Created: 2020/09/27 12:54:12 by charles #+# #+# # -# Updated: 2020/09/27 12:59:50 by charles ### ########.fr # -# # -# ############################################################################ # - -class Philo: - def __init__(id_: int): - self.id = id_ - self.last_event = None - self.last_eat_date = None - - def add_log(self, match): - pass - - def check(self): - return True diff --git a/src/test/table.py b/src/test/table.py deleted file mode 100644 index 6aa1b15..0000000 --- a/src/test/table.py +++ /dev/null @@ -1,23 +0,0 @@ -# ############################################################################ # -# # -# ::: :::::::: # -# table.py :+: :+: :+: # -# +:+ +:+ +:+ # -# By: charles +#+ +:+ +#+ # -# +#+#+#+#+#+ +#+ # -# Created: 2020/09/27 12:44:48 by charles #+# #+# # -# Updated: 2020/09/27 12:54:01 by charles ### ########.fr # -# # -# ############################################################################ # - -class Table: - def __init__(self, philo_num): - self._philos = [Philo(id_) for id_ in range(1, philo_num + 1)] - - def update(self, match): - philo = itertools.first_true(self._philos, pred = lambda x: x.id == match.id) - philo.add_log(match) - - def check(self): - return True - 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 +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # 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\d+) " - "(?P\d+) " - "(?Pis 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 -- cgit