Skip to content

Commit

Permalink
Setup ascii default encoding without mocking.
Browse files Browse the repository at this point in the history
  • Loading branch information
adiroiban committed Apr 6, 2021
1 parent 25b1167 commit 6aa1ea3
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/twisted/trial/_dist/test/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Test for distributed trial worker side.
"""

import _bootlocale
import locale
import os
from io import BytesIO, StringIO

Expand Down Expand Up @@ -347,14 +347,12 @@ def test_unicodeLogFileUTF8(self):
tempDir = FilePath(self.mktemp())
logFile = tempDir.child("test.log")

def getLatin1(do_setlocale: bool = True) -> str:
"""
A replacement for L{locale.getpreferredencoding} that always
returns the Latin-1 encoding.
"""
return "latin-1"

self.patch(_bootlocale, "getpreferredencoding", getLatin1)
# Modern OSes are running default locale in UTF-8 and this is what
# is used by Python at startup.
# For this test, we force an ASCII default encoding.
currentLocale = locale.getlocale()
self.addCleanup(locale.setlocale, locale.LC_ALL, currentLocale)
locale.setlocale(locale.LC_ALL, ("C", "ascii"))

worker = LocalWorker(amp, tempDir.path, "test.log")
worker.makeConnection(FakeTransport())
Expand Down

0 comments on commit 6aa1ea3

Please sign in to comment.