From 8e01364f65738744ce81ad72ae872d1fded2ffa0 Mon Sep 17 00:00:00 2001
From: iamashwin99 <ashwin-kumar.karnad@mpsd.mpg.de>
Date: Tue, 30 May 2023 15:57:30 +0200
Subject: [PATCH] first attempt at tests for run

---
 tests.py | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/tests.py b/tests.py
index be7c6b2..d3c020e 100644
--- a/tests.py
+++ b/tests.py
@@ -25,6 +25,26 @@ def test_os_chdir(tmp_path):
     assert os.getcwd() == initial_cwd
 
 
+def test_run_method(tmp_path):
+    with mod.os_chdir(str(tmp_path)):
+        run = mod.run
+        # test a command with options:
+        assert run(["date", "+%Y-%m-%d"], shell=True).returncode == 0
+        # ensure single string command works
+        assert run(("ls -l")).returncode == 0
+        # test spaces are handled correctly:
+        assert run(["touch", "file1 file2"]).returncode == 0
+        assert os.path.exists("file1")
+        assert os.path.exists("file2")
+        # test output is captured:
+        assert (
+            b"Hello, world!\n"
+            in run(["echo", "Hello, world!"], capture_output=True).stdout
+        )
+        # test counter works:
+        assert b"##-04\n" in run(["echo", "Hello, world!"], capture_output=True).stdout
+
+
 def test_prepare_environment(tmp_path):
     # simulate running ./install-software-environment.py --release dev-23a \
     #   --target-directory /tmp/test_prepare_env
-- 
GitLab