Skip to content

Commit

Permalink
fix CLI command, add unit test CI (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
yxlao committed Jul 20, 2023
1 parent 4c16f1f commit 498ff5d
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 8 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/formatter.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
name: Formatter CI
name: Formatter

on:
workflow_dispatch:
push:
branches:
- main
pull_request:
types: [opened, reopened, synchronize]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
formatter:
runs-on: ubuntu-latest
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: PyPI

on:
workflow_dispatch:
push:
branches:
- main
pull_request:
types: [opened, reopened, synchronize]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install camtools
- name: Run simple import tests
run: |
python -c "import camtools; print(camtools.__version__)"
ct --help
34 changes: 34 additions & 0 deletions .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Unit Test

on:
workflow_dispatch:
push:
branches:
- main
pull_request:
types: [opened, reopened, synchronize]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[dev]
- name: Run unit tests
run: |
pytest
30 changes: 23 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ camera parameters. It follows the standard camera coordinate system with clear
and easy-to-use APIs.

<a href="https://github.com/yxlao/camtools/actions/workflows/formatter.yml">
<img src="https://github.com/yxlao/camtools/actions/workflows/formatter.yml/badge.svg" alt="Formatter">
<img src="https://github.com/yxlao/camtools/actions/workflows/formatter.yml/badge.svg" alt="Formatter">
</a>
<a href="https://github.com/yxlao/camtools/actions/workflows/unit_test.yml">
<img src="https://github.com/yxlao/camtools/actions/workflows/unit_test.yml/badge.svg" alt="Unit Test">
</a>
<a href="https://github.com/yxlao/camtools/actions/workflows/pypi.yml">
<img src="https://github.com/yxlao/camtools/actions/workflows/pypi.yml/badge.svg" alt="PyPI">
</a>

## What can you do with CamTools?
Expand All @@ -28,6 +34,7 @@ and easy-to-use APIs.

```python
pose = ct.convert.T_to_pose(T) # Convert T to pose
T = ct.convert.T_to_pose(pose) # Convert pose to T
R, t = ct.convert.T_to_R_t(T) # Convert T to R and t
C = ct.convert.pose_to_C(pose) # Convert pose to camera center
K, T = ct.convert.P_to_K_T(P) # Decompose projection matrix to K and T
Expand Down Expand Up @@ -92,18 +99,27 @@ and easy-to-use APIs.

## Installation

To install CamTools, simply do:

```bash
# Option 1: install from pip.
pip install camtools
```

# Option 2: install from git.
pip install git+https://github.com/yxlao/camtools.git
Alternatively, you can install CamTools from source with one of the following
methods:

# Option 3: install from source.
```bash
git clone https://github.com/yxlao/camtools.git
cd camtools
pip install -e . # Dev mode, if you want to modify camtools.
pip install . # Install mode, if you want to use camtools only.

# Installation mode, if you want to use camtools only.
pip install .

# Dev mode, if you want to modify camtools on the fly.
pip install -e .

# Dev mode and dev dependencies, if you want to modify camtools and run tests.
pip install -e .[dev]
```

## Camera coordinate system
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ readme = "README.md"
requires-python = ">=3.6.0"
version = "0.1.1"

[tool.setuptools]
packages = ["camtools", "camtools.tools"]

[project.urls]
Homepage = "https://github.com/yxlao/camtools"

Expand Down
41 changes: 41 additions & 0 deletions test/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from pathlib import Path
import subprocess


def _run_and_test_command(cmd: str, required_stdout: str = None):
"""
Run cmd in terminal, assert return code is 0 and check for required output.
Args:
cmd (str): Command to run in terminal.
required_stdout (str): Required std output from command.
"""
# Run command.
cmd_tokens = cmd.split()
proc = subprocess.run(cmd_tokens, capture_output=True, check=False)

# Assert return code is 0.
if proc.returncode != 0:
raise subprocess.CalledProcessError(proc.returncode, cmd_tokens)

# Assert required output is in stdout.
if required_stdout is not None:
std_out = proc.stdout.decode("utf-8")
if required_stdout not in std_out:
raise AssertionError(
f"Required stdout not found in output of {cmd}: {std_out}"
)


def test_crop_boarders():
_run_and_test_command(
cmd="ct crop-boarders --help",
required_stdout="usage: ct crop-boarders",
)


def test_draw_bboxes():
_run_and_test_command(
cmd="ct draw-bboxes --help",
required_stdout="usage: ct draw-bboxes",
)

0 comments on commit 498ff5d

Please sign in to comment.