Skip to content

armgit / Soup

Public Imported from GitHub
0

Fine-tune LLMs from one YAML. Layer streaming trains an 8B model on a 4 GB laptop GPU.

fix(tests): strip ANSI codes before matching console output in test_errors.py (#2176)

Daivik Awasthi85d8c5f583fd
diff --git a/tests/test_errors.py b/tests/test_errors.py
index 7e1059f3..62ef9654 100644
--- a/tests/test_errors.py
+++ b/tests/test_errors.py
@@ -24,7 +24,7 @@ def test_cuda_oom_error():
with patch("soup_cli.utils.errors.console", test_console):
exc = RuntimeError("CUDA out of memory. Tried to allocate 2.00 GiB")
format_friendly_error(exc, verbose=False)
- output = buf.getvalue()
+ output = " ".join(strip_ansi(buf.getvalue()).split())
assert "--batch-size" in output
assert "GPU ran out of memory" in output
# v0.53.4 #11 — message now suggests --batch-size / --grad-accum CLI flags.
@@ -40,7 +40,7 @@ def test_missing_fastapi_error():
with patch("soup_cli.utils.errors.console", test_console):
exc = ModuleNotFoundError("No module named 'fastapi'")
format_friendly_error(exc, verbose=False)
- output = buf.getvalue()
+ output = " ".join(strip_ansi(buf.getvalue()).split())
assert "soup-cli[serve]" in output
@@ -51,7 +51,7 @@ def test_missing_datasketch_error():
with patch("soup_cli.utils.errors.console", test_console):
exc = ModuleNotFoundError("No module named 'datasketch'")
format_friendly_error(exc, verbose=False)
- output = buf.getvalue()
+ output = " ".join(strip_ansi(buf.getvalue()).split())
assert "soup-cli[data]" in output
@@ -62,7 +62,7 @@ def test_missing_wandb_error():
with patch("soup_cli.utils.errors.console", test_console):
exc = ModuleNotFoundError("No module named 'wandb'")
format_friendly_error(exc, verbose=False)
- output = buf.getvalue()
+ output = " ".join(strip_ansi(buf.getvalue()).split())
assert "pip install wandb" in output
@@ -73,7 +73,7 @@ def test_missing_deepspeed_error():
with patch("soup_cli.utils.errors.console", test_console):
exc = ModuleNotFoundError("No module named 'deepspeed'")
format_friendly_error(exc, verbose=False)
- output = buf.getvalue()
+ output = " ".join(strip_ansi(buf.getvalue()).split())
assert "soup-cli[deepspeed]" in output
@@ -88,7 +88,7 @@ def test_missing_train_dep_points_at_train_extra(module):
with patch("soup_cli.utils.errors.console", test_console):
exc = ModuleNotFoundError(f"No module named '{module}'")
format_friendly_error(exc, verbose=False)
- output = buf.getvalue()
+ output = " ".join(strip_ansi(buf.getvalue()).split())
# The `\[train]` escape renders to a literal `[train]` in the output.
assert "soup-cli[train]" in output
assert "[train] extra" in output
@@ -101,7 +101,7 @@ def test_connection_error():
with patch("soup_cli.utils.errors.console", test_console):
exc = ConnectionError("Failed to connect")
format_friendly_error(exc, verbose=False)
- output = buf.getvalue()
+ output = " ".join(strip_ansi(buf.getvalue()).split())
assert "Network connection failed" in output
@@ -112,7 +112,7 @@ def test_unknown_error_shows_type():
with patch("soup_cli.utils.errors.console", test_console):
exc = ZeroDivisionError("division by zero")
format_friendly_error(exc, verbose=False)
- output = buf.getvalue()
+ output = " ".join(strip_ansi(buf.getvalue()).split())
assert "ZeroDivisionError" in output
assert "division by zero" in output
assert "--verbose" in output
@@ -127,7 +127,7 @@ def test_verbose_shows_traceback():
raise RuntimeError("CUDA out of memory. Tried to allocate")
except RuntimeError as exc:
format_friendly_error(exc, verbose=True)
- output = buf.getvalue()
+ output = " ".join(strip_ansi(buf.getvalue()).split())
assert "GPU ran out of memory" in output
assert "Traceback" in output or "RuntimeError" in output
@@ -141,7 +141,7 @@ def test_verbose_unknown_error():
raise ValueError("something weird")
except ValueError as exc:
format_friendly_error(exc, verbose=True)
- output = buf.getvalue()
+ output = " ".join(strip_ansi(buf.getvalue()).split())
assert "ValueError" in output
assert "something weird" in output
@@ -153,7 +153,7 @@ def test_yaml_error():
with patch("soup_cli.utils.errors.console", test_console):
exc = Exception("yaml.scanner.ScannerError: mapping values are not allowed here")
format_friendly_error(exc, verbose=False)
- output = buf.getvalue()
+ output = " ".join(strip_ansi(buf.getvalue()).split())
assert "YAML syntax" in output
@@ -164,7 +164,7 @@ def test_validation_error():
with patch("soup_cli.utils.errors.console", test_console):
exc = Exception("2 validation error for SoupConfig")
format_friendly_error(exc, verbose=False)
- output = buf.getvalue()
+ output = " ".join(strip_ansi(buf.getvalue()).split())
assert "Config validation failed" in output
@@ -175,7 +175,7 @@ def test_auth_401_error():
with patch("soup_cli.utils.errors.console", test_console):
exc = Exception("401 Client Error: Unauthorized")
format_friendly_error(exc, verbose=False)
- output = buf.getvalue()
+ output = " ".join(strip_ansi(buf.getvalue()).split())
assert "Authentication failed" in output
@@ -186,7 +186,7 @@ def test_file_not_found_error():
with patch("soup_cli.utils.errors.console", test_console):
exc = FileNotFoundError("No such file or directory: 'model.bin'")
format_friendly_error(exc, verbose=False)
- output = buf.getvalue()
+ output = " ".join(strip_ansi(buf.getvalue()).split())
assert "No such file or directory" in output
assert "soup init" in output
@@ -217,7 +217,7 @@ def test_cuda_oom_mentions_gradient_checkpointing():
exc = RuntimeError("CUDA out of memory")
format_friendly_error(exc, verbose=False)
- output = buf.getvalue()
+ output = " ".join(strip_ansi(buf.getvalue()).split())
assert "gradient_checkpointing" in output
assert "4bit" in output
@@ -231,7 +231,7 @@ def test_gated_repo_error():
exc = Exception("GatedRepoError: Cannot access gated repo")
format_friendly_error(exc, verbose=False)
- output = buf.getvalue()
+ output = " ".join(strip_ansi(buf.getvalue()).split())
assert "huggingface-cli login" in output
assert "HF_TOKEN" in output
@@ -245,7 +245,7 @@ def test_gated_repo_hyphenated_error():
exc = Exception("Access denied to gated-repo")
format_friendly_error(exc, verbose=False)
- output = buf.getvalue()
+ output = " ".join(strip_ansi(buf.getvalue()).split())
assert "huggingface-cli login" in output
@@ -260,7 +260,7 @@ def test_trust_remote_code_error():
)
format_friendly_error(exc, verbose=False)
- output = buf.getvalue()
+ output = " ".join(strip_ansi(buf.getvalue()).split())
assert "trust_remote_code=True" in output