1010import shutil
1111import tempfile
1212import re
13+ import types
1314import glob
1415
1516from garlicsim .general_misc .temp_value_setters import \
1617 TempWorkingDirectorySetter
1718from garlicsim .general_misc import sys_tools
1819from garlicsim .general_misc import import_tools
20+ from garlicsim .general_misc import cute_inspect
1921
22+ import garlicsim .scripts .simpack_template .simpack_name .state
2023import garlicsim .scripts .start_simpack
2124start_simpack_file = garlicsim .scripts .start_simpack .__file__
2225
@@ -94,7 +97,14 @@ def test():
9497 "your new simpack.\n " )
9598 simpack_path = os .path .join (temp_dir , '_coin_flip' )
9699 assert os .path .isdir (simpack_path )
100+
97101 state_module_path = os .path .join (simpack_path , 'state.py' )
102+
103+ check_module_was_copied_with_correct_newlines (
104+ state_module_path ,
105+ garlicsim .scripts .simpack_template .simpack_name .state
106+ )
107+
98108 with open (state_module_path , 'w' ) as state_file :
99109 state_file .write (state_module_contents_for_coinflip )
100110
@@ -149,5 +159,20 @@ def get_end_balance():
149159
150160 finally :
151161 shutil .rmtree (temp_dir )
152-
162+
153163
164+ def check_module_was_copied_with_correct_newlines (destination_path ,
165+ source_module ):
166+
167+ assert os .path .isfile (destination_path )
168+ assert isinstance (source_module , types .ModuleType )
169+
170+ number_of_newlines = cute_inspect .getsource (source_module ).count ('\n ' )
171+
172+ with file (destination_path , 'rb' ) as destination_file :
173+ destination_string = destination_file .read ()
174+
175+ assert destination_string .count (os .linesep ) == number_of_newlines
176+
177+ if os .linesep == '\n ' :
178+ assert '\r \n ' not in destination_string
0 commit comments