mirror of
https://github.com/jongracecox/anybadge.git
synced 2025-07-21 12:21:03 +02:00
anybadge cli accessible via python -m
(#79)
* anybadge cli can be called via python -m * fix: anybadge should be shown in cli usage string * also allow executing anybadge.server as module * test: same output regardless of how cli is called
This commit is contained in:
9
anybadge/__main__.py
Normal file
9
anybadge/__main__.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from .cli import main
|
||||
|
||||
if __name__ == "__main__":
|
||||
# ensure that `anybadge` shows in usage (not __main__.py)
|
||||
import sys
|
||||
|
||||
sys.argv[0] = "anybadge"
|
||||
|
||||
main()
|
9
anybadge/server/__main__.py
Normal file
9
anybadge/server/__main__.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from .cli import main
|
||||
|
||||
if __name__ == "__main__":
|
||||
# ensure that `anybadge-server` shows in usage (not `__main__.py`)
|
||||
import sys
|
||||
|
||||
sys.argv[0] = "anybadge-server"
|
||||
|
||||
main()
|
@@ -1,3 +1,4 @@
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from unittest import TestCase
|
||||
from anybadge import Badge
|
||||
@@ -403,3 +404,9 @@ class TestAnybadge(TestCase):
|
||||
semver=True,
|
||||
)
|
||||
self.assertEqual("orange", badge.badge_color)
|
||||
|
||||
def test_module_same_output_as_main_cli(self):
|
||||
"""Test that `python -m anybadge` is equivalent to calling `anybadge` directly."""
|
||||
output_module = subprocess.check_output(["python", "-m", "anybadge", "--help"])
|
||||
output_script = subprocess.check_output(["anybadge", "--help"])
|
||||
self.assertEqual(output_module, output_script)
|
||||
|
@@ -43,3 +43,11 @@ class TestAnybadgeServer(TestCase):
|
||||
self.assertTrue(
|
||||
response.content.startswith(b'<?xml version="1.0" encoding="UTF-8"?>\n<svg')
|
||||
)
|
||||
|
||||
def test_server_module_same_output_as_server_cli(self):
|
||||
"""Test that `python -m anybadge.server` is equivalent to calling `anybadge-server` directly."""
|
||||
output_module = subprocess.check_output(
|
||||
["python", "-m", "anybadge.server", "--help"]
|
||||
)
|
||||
output_script = subprocess.check_output(["anybadge-server", "--help"])
|
||||
self.assertEqual(output_module, output_script)
|
||||
|
Reference in New Issue
Block a user