From b5021b0a8fd65a7a4ec8f3fa01824374ae8d54ef Mon Sep 17 00:00:00 2001 From: Norwid Behrnd Date: Mon, 23 Feb 2026 19:57:22 +0100 Subject: [PATCH] style(__init__.py, unit_tests.py): explicitly use utf-8 When running the unit tests with GitHub's Windows runner image, one test currently fails for lack of (sufficient) support for unicode characters. To address this issue, the file context managers are amended by an explicit `encoding="utf-8"`. Signed-off-by: Norwid Behrnd --- filetags/__init__.py | 2 +- tests/unit_tests.py | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/filetags/__init__.py b/filetags/__init__.py index 4585d3e..6d2b6bc 100755 --- a/filetags/__init__.py +++ b/filetags/__init__.py @@ -2520,7 +2520,7 @@ def assert_empty_tagfilter_directory(directory): logging.debug('re-creating tagfilter directory "%s" ...' % str(directory)) os.makedirs(directory) - with open(id, 'w'): + with open(id, 'w', encoding="utf-8"): pass if not options.dryrun: diff --git a/tests/unit_tests.py b/tests/unit_tests.py index 20f5308..9d9771d 100755 --- a/tests/unit_tests.py +++ b/tests/unit_tests.py @@ -354,7 +354,7 @@ class TestLocateAndParseControlledVocabulary(unittest.TestCase): def create_file(self, name, content): assert(os.path.isdir(os.path.dirname(name))) - with open(name, 'w') as outputhandle: + with open(name, 'w', encoding="utf-8") as outputhandle: outputhandle.write(content) def test_find_cv_in_startfile_dir_instead_of_cwd(self): @@ -613,7 +613,7 @@ class TestFileWithoutTags(unittest.TestCase): def create_tmp_file(self, name): - with open(os.path.join(self.tempdir, name), 'w') as outputhandle: + with open(os.path.join(self.tempdir, name), 'w', encoding="utf-8") as outputhandle: outputhandle.write('This is a test file for filetags unit testing') def file_exists(self, name): @@ -825,7 +825,7 @@ class TestHierarchyWithFilesAndFolders(unittest.TestCase): def create_tmp_file(self, directory, name): - with open(os.path.join(directory, name), 'w') as outputhandle: + with open(os.path.join(directory, name), 'w', encoding="utf-8") as outputhandle: outputhandle.write('This is a test file for filetags unit testing') def file_exists(self, name): @@ -937,7 +937,7 @@ class TestHierarchyWithFilesAndFolders(unittest.TestCase): def test_tagtrees_overwrites_old_default_directory(self): - with open(os.path.join(self.subdir2, 'boring tagtrees data.txt'), 'w'): + with open(os.path.join(self.subdir2, 'boring tagtrees data.txt'), 'w', encoding="utf-8"): pass filetags.generate_tagtrees(directory=self.subdir2, @@ -952,7 +952,7 @@ class TestHierarchyWithFilesAndFolders(unittest.TestCase): filetags.options.tagtrees_directory = self.subdir2 - with open(os.path.join(self.subdir2, '.filetags_tagtrees'), 'w'): + with open(os.path.join(self.subdir2, '.filetags_tagtrees'), 'w', encoding="utf-8"): pass filetags.generate_tagtrees(directory=self.subdir2, @@ -969,7 +969,7 @@ class TestHierarchyWithFilesAndFolders(unittest.TestCase): filetags.options.tagtrees_directory = self.subdir2 - with open(os.path.join(self.subdir2, 'critical data.txt'), 'w'): + with open(os.path.join(self.subdir2, 'critical data.txt'), 'w', encoding="utf-8"): pass with self.assertRaises(SystemExit): @@ -1055,7 +1055,7 @@ class TestReplacingLinkSourceAndTarget(unittest.TestCase): def create_source_file(self, name): - with open(os.path.join(self.sourcedir, name), 'w') as outputhandle: + with open(os.path.join(self.sourcedir, name), 'w', encoding="utf-8") as outputhandle: outputhandle.write('This is a test file for filetags unit testing') def create_link_file(self, source, destination):