File tree Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Original file line number Diff line number Diff line change 1
1
# pydantic-to-typescript
2
2
3
3
[ ![ 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 )
5
5
[ ![ 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 )
6
6
7
7
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.
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ def import_module(path: str) -> ModuleType:
40
40
return module
41
41
else :
42
42
return importlib .import_module (path )
43
- except BaseException as e :
43
+ except Exception as e :
44
44
logger .error (
45
45
"The --module argument must be a module path separated by dots or a valid filepath"
46
46
)
Original file line number Diff line number Diff line change @@ -95,3 +95,22 @@ def test_calling_from_python(tmpdir):
95
95
call_from_python = True ,
96
96
exclude = ("LoginCredentials" , "LoginResponseData" ),
97
97
)
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
+ )
You can’t perform that action at this time.
0 commit comments