Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions test/test_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@
"""

import errno
import shutil
import subprocess
import sys
import sysconfig
import unittest
from abc import ABCMeta, abstractmethod

from .config import *

def _console_script(name: str) -> str:
"""Return the path of the console script ``name`` installed with this interpreter."""
path = shutil.which(name, path=sysconfig.get_path("scripts"))
if path is None:
raise FileNotFoundError(f"console script {name!r} is not installed")
return path


class CanScriptTest(unittest.TestCase, metaclass=ABCMeta):
Expand All @@ -28,10 +36,9 @@ def test_do_commands_exist(self):
for command in self._commands():
try:
subprocess.check_output(
command.split(),
command,
stderr=subprocess.STDOUT,
encoding="utf-8",
shell=IS_WINDOWS,
)
except subprocess.CalledProcessError as e:
return_code = e.returncode
Expand Down Expand Up @@ -73,8 +80,8 @@ def _import(self):
class TestLoggerScript(CanScriptTest):
def _commands(self):
commands = [
"python -m can.logger --help",
"can_logger --help",
[sys.executable, "-m", "can.logger", "--help"],
[_console_script("can_logger"), "--help"],
]
return commands

Expand All @@ -87,8 +94,8 @@ def _import(self):
class TestPlayerScript(CanScriptTest):
def _commands(self):
commands = [
"python -m can.player --help",
"can_player --help",
[sys.executable, "-m", "can.player", "--help"],
[_console_script("can_player"), "--help"],
]
return commands

Expand All @@ -101,8 +108,8 @@ def _import(self):
class TestBridgeScript(CanScriptTest):
def _commands(self):
commands = [
"python -m can.bridge --help",
"can_bridge --help",
[sys.executable, "-m", "can.bridge", "--help"],
[_console_script("can_bridge"), "--help"],
]
return commands

Expand All @@ -115,8 +122,8 @@ def _import(self):
class TestLogconvertScript(CanScriptTest):
def _commands(self):
commands = [
"python -m can.logconvert --help",
"can_logconvert --help",
[sys.executable, "-m", "can.logconvert", "--help"],
[_console_script("can_logconvert"), "--help"],
]
return commands

Expand Down
Loading