Skip to content

Commit

Permalink
fix: solve exception with CommandLineExecutor
Browse files Browse the repository at this point in the history
  • Loading branch information
JuReMq committed May 13, 2024
1 parent 93081fd commit 3a1f6d0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/spl_core/common/command_line_executor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import locale
import subprocess
import sys
from pathlib import Path
from typing import Dict, List, Optional

Expand Down Expand Up @@ -42,6 +44,7 @@ def execute(self, cmd: str | List[str]) -> subprocess.CompletedProcess[str]:
text=True,
env=self.env,
universal_newlines=True,
encoding="cp850" if (locale.getlocale()[0] == "de_DE" and sys.platform == "win32") else "utf-8",
) as process:
if process.stdout:
for line in process.stdout:
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/test_command_line_executor.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

import pytest

from spl_core.common.command_line_executor import CommandLineExecutor
Expand Down Expand Up @@ -29,3 +31,10 @@ def test_CommandLineExecuter(self, command, exp_stdout, exp_stderr, exp_returnco
assert result.stdout == exp_stdout
assert result.stderr == exp_stderr
assert result.returncode == exp_returncode

def test_CommandLineExecuter_exception(self, tmp_path: Path) -> None:
test_path = tmp_path.joinpath("test")
test_path.mkdir()
link_path = test_path.joinpath("link")
result = CommandLineExecutor().execute(["cmd", "/c", "mklink", "/J", str(link_path), str(test_path)])
assert result.returncode == 0

0 comments on commit 3a1f6d0

Please sign in to comment.