From 9d52bffb66265d8b929bfa98448589b261028bb6 Mon Sep 17 00:00:00 2001 From: Nick Hartung Date: Wed, 4 Mar 2020 20:12:06 -0600 Subject: [PATCH 1/3] Reading and writing files using utf-8 encoding explicitly rather than relying on the system encoding. Fixing a test that was checking for unix paths --- doorstop/common.py | 4 ++-- doorstop/core/vcs/tests/test_base.py | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/doorstop/common.py b/doorstop/common.py index 8264bd2c2..bf386ca0b 100644 --- a/doorstop/common.py +++ b/doorstop/common.py @@ -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) @@ -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 diff --git a/doorstop/core/vcs/tests/test_base.py b/doorstop/core/vcs/tests/test_base.py index fbe89b404..c42648314 100644 --- a/doorstop/core/vcs/tests/test_base.py +++ b/doorstop/core/vcs/tests/test_base.py @@ -2,6 +2,7 @@ """Unit tests for the doorstop.vcs.base module.""" +import os import unittest from unittest.mock import patch @@ -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', ''))] + ) From 9fd6556de82514a52f7b90830549bbc7b2f12567 Mon Sep 17 00:00:00 2001 From: Nick Hartung Date: Wed, 4 Mar 2020 20:39:36 -0600 Subject: [PATCH 2/3] Using os.linesep for expected text rather than relying on \n --- doorstop/cli/tests/tutorial.py | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/doorstop/cli/tests/tutorial.py b/doorstop/cli/tests/tutorial.py index 423694c25..f7b9055d2 100644 --- a/doorstop/cli/tests/tutorial.py +++ b/doorstop/cli/tests/tutorial.py @@ -238,12 +238,10 @@ 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, ) @@ -266,14 +264,10 @@ 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, ) From f4d321b3523e2193b28ea364fd0ae5386b05cecd Mon Sep 17 00:00:00 2001 From: Nick Hartung Date: Wed, 4 Mar 2020 21:02:29 -0600 Subject: [PATCH 3/3] Updating formatting according to black --- doorstop/cli/tests/tutorial.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/doorstop/cli/tests/tutorial.py b/doorstop/cli/tests/tutorial.py index f7b9055d2..4a8a55343 100644 --- a/doorstop/cli/tests/tutorial.py +++ b/doorstop/cli/tests/tutorial.py @@ -238,10 +238,15 @@ def test_custom_defaults(self): cp = self.doorstop("publish REQ", stdout=subprocess.PIPE) self.assertIn( - 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), + 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, ) @@ -264,10 +269,16 @@ def test_item_with_name(self): cp = self.doorstop("publish REQ", stdout=subprocess.PIPE) self.assertIn( - 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', + 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, )