Skip to content

Commit e95ffb5

Browse files
committed
Add tests to the build command
1 parent b0b482f commit e95ffb5

2 files changed

Lines changed: 58 additions & 5 deletions

File tree

components/rsptx/build_tools/build.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@ def full(ctx, config):
890890
@click.pass_context
891891
def dev(ctx, config):
892892
"""Build the wheels, images, and restart the services"""
893+
ctx.invoke(test)
893894
ctx.invoke(wheel)
894895
ctx.invoke(image)
895896
ctx.invoke(restart)
@@ -903,12 +904,51 @@ def dev(ctx, config):
903904
@click.pass_context
904905
def sync(ctx, config):
905906
"""Build the wheels, images, check the database, and restart the services"""
907+
ctx.invoke(test)
906908
ctx.invoke(wheel)
907909
ctx.invoke(image)
908910
ctx.invoke(checkdb)
909911
ctx.invoke(restart)
910912

911913

914+
@cli.command()
915+
@pass_config
916+
def test(config):
917+
"""Run format checks and tests"""
918+
checks = [
919+
["black", "--check", "--config", "pyproject.toml", "bases"],
920+
["black", "--check", "--config", "pyproject.toml", "components"],
921+
]
922+
923+
for command_list in checks:
924+
console.print(f"Running {' '.join(command_list)}...", style="bold")
925+
ret = subprocess.run(command_list, capture_output=True)
926+
if ret.returncode != 0:
927+
console.print(
928+
f"Command failed: {' '.join(command_list)}",
929+
style="bold red",
930+
)
931+
if ret.stdout:
932+
console.print(ret.stdout.decode(stdout_err_encoding))
933+
if ret.stderr:
934+
console.print(ret.stderr.decode(stdout_err_encoding))
935+
exit(1)
936+
937+
console.print("Running pytest in test with SERVER_CONFIG=test...", style="bold")
938+
test_env = os.environ.copy()
939+
test_env["SERVER_CONFIG"] = "test"
940+
ret = subprocess.run(["pytest"], cwd="test", env=test_env, capture_output=True)
941+
if ret.returncode != 0:
942+
console.print("Pytest failed", style="bold red")
943+
if ret.stdout:
944+
console.print(ret.stdout.decode(stdout_err_encoding))
945+
if ret.stderr:
946+
console.print(ret.stderr.decode(stdout_err_encoding))
947+
exit(1)
948+
949+
console.print("All checks passed", style="green")
950+
951+
912952
# Bake
913953
# build multi-architecture images and push them to the registry
914954
@cli.command()
@@ -929,6 +969,8 @@ def bake(ctx, config, version):
929969
with open(".last_version", "w") as f:
930970
f.write(version)
931971
# we need to build the wheels first
972+
973+
ctx.invoke(test)
932974
ctx.invoke(wheel)
933975
for service in config.ym["services"]:
934976
if service == "nginx_dstart_dev":

pyproject.toml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,21 @@ line-length = 88
199199
# Ignore directories using regex
200200
exclude = '''
201201
(
202-
^/(\.git|\.mypy_cache|\.pytest_cache|\.tox|venv|build|dist|.venv|projects|migrations)/
203-
| ^/bases/rsptx/web2py_server/
204-
| ^/bases/rsptx/interactives/
205-
| ^/bases/rsptx/dash_server_api/
206-
| node_modules
202+
(^|/)(\.git|\.mypy_cache|\.pytest_cache|\.tox|venv|build|dist|\.venv|projects|migrations)/
203+
| (^|/)(bases/)?rsptx/web2py_server/
204+
| (^|/)(bases/)?rsptx/interactives/
205+
| (^|/)(bases/)?rsptx/dash_server_api/
206+
| (^|/)node_modules/
207+
)
208+
'''
209+
210+
# Also exclude these paths when files/directories are passed explicitly.
211+
force-exclude = '''
212+
(
213+
(^|/)(\.git|\.mypy_cache|\.pytest_cache|\.tox|venv|build|dist|\.venv|projects|migrations)/
214+
| (^|/)(bases/)?rsptx/web2py_server/
215+
| (^|/)(bases/)?rsptx/interactives/
216+
| (^|/)(bases/)?rsptx/dash_server_api/
217+
| (^|/)node_modules/
207218
)
208219
'''

0 commit comments

Comments
 (0)