[multimedia/kid3] src/test: Fix tests on Windows

Urs Fleisch <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 7e3b71f865e69bde34de2711ece3f490bc6ae3a5 by Urs Fleisch.
Committed on 22/07/2026 at 08:24.
Pushed by ufleisch into branch 'master'.

Fix tests on Windows

M  +9    -3    src/test/kid3testsupport.py
M  +22   -14   src/test/test_cli_functions.py

https://invent.kde.org/multimedia/kid3/-/commit/7e3b71f865e69bde34de2711ece3f490bc6ae3a5

diff --git a/src/test/kid3testsupport.py b/src/test/kid3testsupport.py
index d9ad850c..90a78134 100644
--- a/src/test/kid3testsupport.py
+++ b/src/test/kid3testsupport.py
@@ -12,7 +12,10 @@ class Kid3ConfigFile:
     """Temporary file context manager with INI file contents."""
     def __init__(self, contents):
         self._contents = contents
-        self._file = tempfile.NamedTemporaryFile('w+')
+        if sys.platform == 'win32':
+            self._file = open('kid3test.ini', 'w')
+        else:
+            self._file = tempfile.NamedTemporaryFile('w+')
 
     def __enter__(self):
         result = self._file.__enter__()
@@ -93,8 +96,11 @@ def kid3_cli_path():
 def call_kid3_cli(args):
     if isinstance(args, str):
         args = [args]
-    if sys.platform == 'win32':
-        args.insert(0, '--portable')
+    if sys.platform == 'win32' and not os.environ['KID3_CONFIG_FILE']:
+        # An empty name for the config file does not work on Windows
+        os.environ['KID3_CONFIG_FILE'] = 'kid3test.ini'
+        with open('kid3test.ini', 'w'):
+            pass # just truncate to empty file
     out = subprocess.check_output([kid3_cli_path()] + args)
     try:
         s = out.decode()
diff --git a/src/test/test_cli_functions.py b/src/test/test_cli_functions.py
index cac42c61..bbe959f3 100755
--- a/src/test/test_cli_functions.py
+++ b/src/test/test_cli_functions.py
@@ -84,25 +84,31 @@ class CliFunctionsTestCase(unittest.TestCase):
             'TagFormat\n')
         self.assertEqual(call_kid3_cli(
             ['-c', 'config Tag.id3v2Version',
-             '-c', 'config Tag.id3v2Version 3',
-             '-c', 'config Tag.id3v2Version']),
+             '-c', 'config Tag.id3v2Version ID3v2_4_0',
+             '-c', 'config Tag.id3v2Version',
+             '-c', 'config Tag.id3v2Version ID3v2_3_0']),
             'ID3v2_3_0\n'
-            '3\n'
-            '3\n')
+            'ID3v2_4_0\n'
+            'ID3v2_4_0\n'
+            'ID3v2_3_0\n')
         self.assertEqual(call_kid3_cli(
             ['-c', 'config TagFormat.caseConversion',
              '-c', 'config TagFormat.caseConversion NoChanges',
-             '-c', 'config TagFormat.caseConversion']),
+             '-c', 'config TagFormat.caseConversion',
+             '-c', 'config TagFormat.caseConversion AllFirstLettersUppercase']),
             'AllFirstLettersUppercase\n'
             'NoChanges\n'
-            'NoChanges\n')
+            'NoChanges\n'
+            'AllFirstLettersUppercase\n')
         self.assertEqual(call_kid3_cli(
             ['-c', 'config NumberTracks.numberTracksDestination',
-             '-c', 'config NumberTracks.numberTracksDestination 12',
-             '-c', 'config NumberTracks.numberTracksDestination']),
+             '-c', 'config NumberTracks.numberTracksDestination 21',
+             '-c', 'config NumberTracks.numberTracksDestination',
+             '-c', 'config NumberTracks.numberTracksDestination 1']),
             '1\n'
             '21\n'
-            '21\n')
+            '21\n'
+            '1\n')
 
     def test_config_invalid(self):
         p = subprocess.Popen([kid3_cli_path(), '-c', 'config NoSuchGroup.foo'],
@@ -134,7 +140,7 @@ class CliFunctionsTestCase(unittest.TestCase):
         with tempfile.TemporaryDirectory() as tmpdir:
             lines = call_kid3_cli(['-c', 'pwd', '-c', 'cd "%s"' % tmpdir, '-c', 'pwd']).splitlines()
             self.assertTrue(lines)
-            self.assertEqual(lines[-1], tmpdir)
+            self.assertIn(lines[-1], (tmpdir, tmpdir.replace('\\', '/')))
 
             p = subprocess.Popen([kid3_cli_path(), '-c', 'cd %s/no_such_dir' % tmpdir],
                                  stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@@ -1778,11 +1784,13 @@ class CliFunctionsJsonTestCase(unittest.TestCase):
             '"RenameFolder","Tag","TagFormat"]}\n')
         self.assertEqual(call_kid3_cli(
             ['-c', '{"method":"config","params":["Tag.id3v2Version"]}',
-             '-c', '{"method":"config","params":["Tag.id3v2Version","4"]}',
-             '-c', '{"method":"config","params":["Tag.id3v2Version"]}']),
+             '-c', '{"method":"config","params":["Tag.id3v2Version","ID3v2_4_0"]}',
+             '-c', '{"method":"config","params":["Tag.id3v2Version"]}',
+             '-c', '{"method":"config","params":["Tag.id3v2Version","ID3v2_3_0"]}']),
             '{"result":"ID3v2_3_0"}\n'
-            '{"result":"4"}\n'
-            '{"result":"4"}\n')
+            '{"result":"ID3v2_4_0"}\n'
+            '{"result":"ID3v2_4_0"}\n'
+            '{"result":"ID3v2_3_0"}\n')
 
         p = subprocess.Popen([kid3_cli_path(), '-c',
                               '{"method":"config","params":["Tag.textEncoding","UTF8"]}'],
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.