11import imp
22import json
3+ import re
34import subprocess
45import sys
56import tempfile
@@ -94,7 +95,7 @@ def test_help():
9495]
9596
9697
97- def execute_test (command , output_file : Path = None , output = None ) -> Tuple [ str , str ] :
98+ def execute_test (command , output_file : Path = None , output = None ) -> str :
9899 proc = subprocess .Popen (command , shell = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
99100 stdout , stderr = map (bytes .decode , proc .communicate ())
100101 if output_file :
@@ -172,7 +173,6 @@ def test_script_custom(command):
172173
173174@pytest .mark .parametrize ("command" , test_commands )
174175def test_add_preamble (command ):
175-
176176 PREAMBLE_TEXT = """
177177# this is some test code
178178# to be added to the file
@@ -187,8 +187,13 @@ def test_add_preamble(command):
187187
188188
189189@pytest .mark .parametrize ("command" , test_commands )
190- def test_add_trim_preamble (command ):
190+ def test_disable_some_string_types_smoke (command ):
191+ command += " --disable-str-serializable-types float int"
192+ execute_test (command )
191193
194+
195+ @pytest .mark .parametrize ("command" , test_commands )
196+ def test_add_trim_preamble (command ):
192197 def trim_header (line_string ):
193198 """remove the quoted command and everything from the first class declaration onwards"""
194199 lines = line_string .splitlines ()
@@ -247,3 +252,17 @@ def test_script_output_file(command):
247252 file = tmp_path / 'out.py'
248253 command += f" -o { file } "
249254 execute_test (command , output_file = file )
255+
256+
257+ cmds = [
258+ pytest .param (f"""{ executable } -m User "{ test_data_path / 'users.json' } " -f pydantic --disable-str-serializable-types float int""" ,
259+ id = "users" )
260+ ]
261+
262+
263+ @pytest .mark .parametrize ("command" , cmds )
264+ def test_disable_some_string_types (command ):
265+ stdout = execute_test (command )
266+ assert 'lat: str' in stdout
267+ assert 'lng: str' in stdout
268+ assert not any (re .match (r'\s+zipcode:.+int.+' , line ) for line in stdout .split ('\n ' )), "zipcode should not be parsed as int"
0 commit comments