Skip to content

Commit e25300b

Browse files
Added tests for exception raising, fixed the badge for CI/CD in the readme (#21)
1 parent 5f657e0 commit e25300b

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# pydantic-to-typescript
22

33
[![PyPI version](https://badge.fury.io/py/pydantic-to-typescript.svg)](https://badge.fury.io/py/pydantic-to-typescript)
4-
[![Tests](https://github.com/phillipdupuis/pydantic-to-typescript/actions/workflows/tests.yml/badge.svg)](https://github.com/phillipdupuis/pydantic-to-typescript/actions/workflows/tests.yml)
4+
[![CI/CD](https://github.com/phillipdupuis/pydantic-to-typescript/actions/workflows/cicd.yml/badge.svg)](https://github.com/phillipdupuis/pydantic-to-typescript/actions/workflows/cicd.yml)
55
[![Coverage Status](https://coveralls.io/repos/github/phillipdupuis/pydantic-to-typescript/badge.svg?branch=master)](https://coveralls.io/github/phillipdupuis/pydantic-to-typescript?branch=master)
66

77
A simple CLI tool for converting pydantic models into typescript interfaces. Useful for any scenario in which python and javascript applications are interacting, since it allows you to have a single source of truth for type definitions.

pydantic2ts/cli/script.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def import_module(path: str) -> ModuleType:
4040
return module
4141
else:
4242
return importlib.import_module(path)
43-
except BaseException as e:
43+
except Exception as e:
4444
logger.error(
4545
"The --module argument must be a module path separated by dots or a valid filepath"
4646
)

tests/test_script.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,22 @@ def test_calling_from_python(tmpdir):
9595
call_from_python=True,
9696
exclude=("LoginCredentials", "LoginResponseData"),
9797
)
98+
99+
100+
def test_error_if_json2ts_not_installed(tmpdir):
101+
with pytest.raises(Exception) as exc:
102+
module_path = get_input_module("single_module")
103+
output_path = tmpdir.join(f"cli_single_module.ts").strpath
104+
json2ts_cmd = "someCommandWhichDefinitelyDoesNotExist"
105+
generate_typescript_defs(module_path, output_path, json2ts_cmd=json2ts_cmd)
106+
assert (
107+
str(exc.value)
108+
== "json2ts must be installed. Instructions can be found here: https://www.npmjs.com/package/json-schema-to-typescript"
109+
)
110+
111+
112+
def test_error_if_invalid_module_path(tmpdir):
113+
with pytest.raises(ModuleNotFoundError):
114+
generate_typescript_defs(
115+
"fake_module", tmpdir.join(f"fake_module_output.ts").strpath
116+
)

0 commit comments

Comments
 (0)