Skip to content

Commit

Permalink
add sample unit test
Browse files Browse the repository at this point in the history
Signed-off-by: ted chang <[email protected]>
  • Loading branch information
tedhtchang committed Mar 4, 2024
1 parent 5a0cf5c commit ba1cf96
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
22 changes: 22 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Test

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install -r setup_requirements.txt
- name: Run unit tests
run: tox -e py
33 changes: 33 additions & 0 deletions tests/utils/test_data_type_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# SPDX-License-Identifier: Apache-2.0
# https://spdx.dev/learn/handling-license-info/

# Third Party
import pytest
import torch

# Local
from tuning.utils import data_type_utils

dtype_dict = {
"bool": torch.bool,
"double": torch.double,
"float32": torch.float32,
"int64": torch.int64,
"long": torch.long,
}


def test_str_to_torch_dtype():
for t in dtype_dict.keys():
assert data_type_utils.str_to_torch_dtype(t) == dtype_dict.get(t)


def test_str_to_torch_dtype_exit():
with pytest.raises(SystemExit):
data_type_utils.str_to_torch_dtype("foo")


def test_get_torch_dtype():
for t in dtype_dict.keys():
assert data_type_utils.get_torch_dtype(t) == dtype_dict.get(t)
assert data_type_utils.get_torch_dtype(dtype_dict.get(t)) == dtype_dict.get(t)
11 changes: 10 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
[tox]
envlist = lint, fmt
envlist = py, lint, fmt

[testenv]
description = run unit tests
deps =
pytest>=7
torch
transformers>=4.34.1
commands =
pytest {posargs:tests}

[testenv:fmt]
description = format with pre-commit
Expand Down

0 comments on commit ba1cf96

Please sign in to comment.