Skip to content

Commit

Permalink
Merge pull request #463 from nhartung/utf_read_write
Browse files Browse the repository at this point in the history
Fixing Windows Tests
  • Loading branch information
jacebrowning committed Mar 5, 2020
2 parents 22a5b6e + f4d321b commit 9353ce7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
33 changes: 19 additions & 14 deletions doorstop/cli/tests/tutorial.py
Expand Up @@ -238,12 +238,15 @@ def test_custom_defaults(self):

cp = self.doorstop("publish REQ", stdout=subprocess.PIPE)
self.assertIn(
b'''1.0 REQ001
Some text
with more than
one line.
''',
b'1.0 REQ001'
+ str.encode(os.linesep)
+ str.encode(os.linesep)
+ b' Some text'
+ str.encode(os.linesep)
+ b' with more than'
+ str.encode(os.linesep)
+ b' one line.'
+ str.encode(os.linesep),
cp.stdout,
)

Expand All @@ -266,14 +269,16 @@ def test_item_with_name(self):

cp = self.doorstop("publish REQ", stdout=subprocess.PIPE)
self.assertIn(
b'''1.0 REQ-ABC
1.1 REQ-009
1.2 REQ-XYZ
1.3 REQ-099
''',
b'1.0 REQ-ABC'
+ str.encode(os.linesep)
+ str.encode(os.linesep)
+ b'1.1 REQ-009'
+ str.encode(os.linesep)
+ str.encode(os.linesep)
+ b'1.2 REQ-XYZ'
+ str.encode(os.linesep)
+ str.encode(os.linesep)
+ b'1.3 REQ-099',
cp.stdout,
)

Expand Down
4 changes: 2 additions & 2 deletions doorstop/common.py
Expand Up @@ -111,7 +111,7 @@ def read_text(path):
"""
log.trace("reading text from '{}'...".format(path)) # type: ignore
try:
with open(path, 'r') as f:
with open(path, 'r', encoding='utf-8') as f:
return f.read()
except Exception as e:
msg = "reading '{}' failed: {}".format(path, e)
Expand Down Expand Up @@ -172,7 +172,7 @@ def write_text(text, path):
"""
if text:
log.trace("writing text to '{}'...".format(path)) # type: ignore
with open(path, 'w') as f:
with open(path, 'w', encoding='utf-8') as f:
f.write(text)
return path

Expand Down
5 changes: 4 additions & 1 deletion doorstop/core/vcs/tests/test_base.py
Expand Up @@ -2,6 +2,7 @@

"""Unit tests for the doorstop.vcs.base module."""

import os
import unittest
from unittest.mock import patch

Expand Down Expand Up @@ -52,4 +53,6 @@ def test_paths(self):
wc = SampleWorkingCopy(ROOT)
paths = [relpath for path, _, relpath in wc.paths]
self.assertEqual([], [x for x in paths if x.startswith('.git/')])
self.assertNotEqual([], [x for x in paths if x.startswith('doorstop/')])
self.assertNotEqual(
[], [x for x in paths if x.startswith(os.path.join('doorstop', ''))]
)

0 comments on commit 9353ce7

Please sign in to comment.