jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1324772?usp=email )

Change subject: tools: Honor modes for uncompressed archives
......................................................................

tools: Honor modes for uncompressed archives

open_archive accepts write and append modes, but its uncompressed
branch always opens files for reading. Pass through the normalized mode
so plain files follow the documented behavior.

Change-Id: I4139c20694ce23f5dcf784c95e5af758b08c74fe
---
M pywikibot/tools/__init__.py
M tests/tools_tests.py
2 files changed, 17 insertions(+), 1 deletion(-)

Approvals:
  Xqt: Looks good to me, approved
  jenkins-bot: Verified




diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index dda6e78..9931e4b 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -816,7 +816,7 @@
         binary = lzma.open(filename, mode, format=lzma_fmts[extension])

     else:  # assume it's an uncompressed file
-        binary = open(filename, 'rb')
+        binary = open(filename, mode)

     return binary

diff --git a/tests/tools_tests.py b/tests/tools_tests.py
index 1b09b27..9ae9c68 100755
--- a/tests/tools_tests.py
+++ b/tests/tools_tests.py
@@ -220,6 +220,22 @@
             self.assertEqual(f.mode, 'rb')
             self.assertIsInstance(f.read(), bytes)

+    def test_write_archive_uncompressed(self) -> None:
+        """Test writing an uncompressed file."""
+        content = self._write_content('')
+        self.assertEqual(content, self.original_content)
+
+    def test_append_archive_uncompressed(self) -> None:
+        """Test appending to an uncompressed file."""
+        with tempfile.TemporaryDirectory() as directory:
+            filename = os.path.join(directory, 'archive')
+            with open(filename, 'wb') as f:
+                f.write(b'foo')
+            with tools.open_archive(filename, 'ab') as f:
+                f.write(b'bar')
+            with open(filename, 'rb') as f:
+                self.assertEqual(f.read(), b'foobar')
+
     def test_write_archive_bz2(self) -> None:
         """Test writing a bz2 archive."""
         content = self._write_content('.bz2')

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1324772?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I4139c20694ce23f5dcf784c95e5af758b08c74fe
Gerrit-Change-Number: 1324772
Gerrit-PatchSet: 1
Gerrit-Owner: Mahveotm <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to