aboutsummaryrefslogtreecommitdiff
path: root/minishell_test/test/captured.py
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2021-02-05 12:27:32 +0100
committerCharles Cabergs <me@cacharle.xyz>2021-02-05 12:27:32 +0100
commit904a033ae738e1c351f8fef71e2ec2418fc4db3d (patch)
tree3de4980582c109c4f0d19111a2b88eafec9b9b36 /minishell_test/test/captured.py
parenta3e983f78dc4cbcf6f75f78fa2b3c57e09cd1b2b (diff)
downloadminishell_test-904a033ae738e1c351f8fef71e2ec2418fc4db3d.tar.gz
minishell_test-904a033ae738e1c351f8fef71e2ec2418fc4db3d.tar.bz2
minishell_test-904a033ae738e1c351f8fef71e2ec2418fc4db3d.zip
Renaming src -> minishell_test for package name, Renaming main.py -> __main__.py for package execution with python -m
Diffstat (limited to 'minishell_test/test/captured.py')
-rw-r--r--minishell_test/test/captured.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/minishell_test/test/captured.py b/minishell_test/test/captured.py
new file mode 100644
index 0000000..f7dae3e
--- /dev/null
+++ b/minishell_test/test/captured.py
@@ -0,0 +1,56 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# captured.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <me@cacharle.xyz> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/09/11 12:16:25 by charles #+# #+# #
+# Updated: 2021/02/04 15:52:19 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
+from typing import List, Optional
+
+import config
+
+
+class Captured:
+ def __init__(
+ self,
+ output: str,
+ status: int,
+ files_content: List[Optional[str]],
+ is_timeout: bool = False
+ ):
+ """Captured class
+ output: captured content
+ status: command status
+ files_content: content of the files altered by the command
+ is_timeout: the command has timed out
+ """
+ lines = output.split('\n')
+ for i, l in enumerate(lines):
+ if l.find(config.REFERENCE_ERROR_BEGIN) == 0:
+ lines[i] = l.replace(config.REFERENCE_ERROR_BEGIN, config.MINISHELL_ERROR_BEGIN, 1)
+ elif l.find(config.REFERENCE_PATH + ": ") == 0:
+ lines[i] = l.replace(config.REFERENCE_PATH + ": ", config.MINISHELL_ERROR_BEGIN, 1)
+ self.output = '\n'.join(lines)
+
+ self.status = status
+ self.files_content = files_content
+ self.is_timeout = is_timeout
+
+ def __eq__(self, other: object) -> bool:
+ if not isinstance(other, Captured):
+ raise NotImplementedError
+ if self.is_timeout:
+ return self.is_timeout == other.is_timeout
+ return (self.output == other.output
+ and self.status == other.status
+ and all(x == y for x, y in zip(self.files_content, other.files_content)))
+
+ @staticmethod
+ def timeout():
+ """Create a new captured timeout"""
+ return Captured("", 0, [], is_timeout=True)