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 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
77A 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:
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 )
Original file line number Diff line number Diff 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+ )
You can’t perform that action at this time.
0 commit comments