Skip to content

Commit 5901a16

Browse files
committed
test: fix failure under cygwin python caused by line endings
reading config.ini files under cygwin python results in \r\n terminated lines which do not compare properly with the success conditions. replace \r\n with \n when required.
1 parent dc50e34 commit 5901a16

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

test/test_admin.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ def find_in_file(filename, regexp):
6262
with open(filename) as f:
6363
contents = f.read()
6464

65+
try:
66+
# handle text files with \r\n line endings
67+
contents.index("\r")
68+
contents = contents.replace("\r\n", "\n")
69+
except ValueError:
70+
pass
71+
6572
m = re.search(regexp, contents, re.MULTILINE)
6673

6774
if not m: return False

test/test_demo.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,14 @@ def run_install_demo(self, template, db="anydbm"):
5050

5151
# verify that db was set properly by reading config
5252
with open(self.home + "/config.ini", "r") as f:
53-
config_lines = f.readlines()
53+
config_lines = f.read().replace("\r\n", "\n")
54+
55+
try:
56+
# handle text files with \r\n line endings
57+
config_lines.index("\r")
58+
config_lines = config_lines.replace("\r\n", "\n")
59+
except ValueError:
60+
pass
5461

5562
self.assertIn("backend = %s\n"%db, config_lines)
5663

@@ -88,7 +95,14 @@ def testDemoJinja(self):
8895

8996
# verify that template was set to jinja2 by reading config
9097
with open(self.home + "/config.ini", "r") as f:
91-
config_lines = f.readlines()
98+
config_lines = f.read()
99+
100+
try:
101+
# handle text files with \r\n line endings
102+
config_lines.index("\r")
103+
config_lines = config_lines.replace("\r\n", "\n")
104+
except ValueError:
105+
pass
92106

93107
self.assertIn("template_engine = jinja2\n", config_lines)
94108

0 commit comments

Comments
 (0)