Skip to content

Commit 4d7a45c

Browse files
author
Ram Rachum
committed
-
1 parent 383bc98 commit 4d7a45c

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

garlicsim/garlicsim/general_misc/cute_inspect/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
from . import forked_inspect
77

88
getargspec = forked_inspect.getargspec
9-
getcallargs = forked_inspect.getcallargs
9+
getcallargs = forked_inspect.getcallargs
10+
getsource = forked_inspect.getsource

garlicsim/garlicsim/scripts/start_simpack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def start_simpack(containing_folder, name):
108108
source_file_name = pkg_resources.resource_filename(
109109
simpack_template_package_name, file
110110
)
111-
with open(source_file_name, 'Ur') as source:
111+
with open(source_file_name, 'rU') as source:
112112

113113
with open(dest_file, 'w') as destination:
114114

garlicsim/test_garlicsim/test_doc/test_tutorial_2/test.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@
1010
import shutil
1111
import tempfile
1212
import re
13+
import types
1314
import glob
1415

1516
from garlicsim.general_misc.temp_value_setters import \
1617
TempWorkingDirectorySetter
1718
from garlicsim.general_misc import sys_tools
1819
from garlicsim.general_misc import import_tools
20+
from garlicsim.general_misc import cute_inspect
1921

22+
import garlicsim.scripts.simpack_template.simpack_name.state
2023
import garlicsim.scripts.start_simpack
2124
start_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

Comments
 (0)