summaryrefslogtreecommitdiffstats
path: root/Lib/_android_support.py
diff options
context:
space:
mode:
authorMalcolm Smith <smith@chaquo.com>2024-08-16 05:00:29 (GMT)
committerGitHub <noreply@github.com>2024-08-16 05:00:29 (GMT)
commitf84cce6f2588c6437d69a30856d7c4ba00b70ae0 (patch)
treee1a99f5e59aa7588c9d548217bfd8fdd47384ccd /Lib/_android_support.py
parente913d2c87f1ae4e7a4aef5ba78368ef31d060767 (diff)
downloadcpython-f84cce6f2588c6437d69a30856d7c4ba00b70ae0.zip
cpython-f84cce6f2588c6437d69a30856d7c4ba00b70ae0.tar.gz
cpython-f84cce6f2588c6437d69a30856d7c4ba00b70ae0.tar.bz2
gh-116622: Add Android test script (#121595)
Adds a script for running the test suite on Android emulator devices. Starting with a fresh install of the Android Commandline tools; the script manages installing other requirements, starting the emulator (if required), and retrieving results from that emulator.
Diffstat (limited to 'Lib/_android_support.py')
-rw-r--r--Lib/_android_support.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/Lib/_android_support.py b/Lib/_android_support.py
index d5d13ec..066e547 100644
--- a/Lib/_android_support.py
+++ b/Lib/_android_support.py
@@ -31,15 +31,17 @@ def init_streams(android_log_write, stdout_prio, stderr_prio):
logcat = Logcat(android_log_write)
sys.stdout = TextLogStream(
- stdout_prio, "python.stdout", errors=sys.stdout.errors)
+ stdout_prio, "python.stdout", sys.stdout.fileno(),
+ errors=sys.stdout.errors)
sys.stderr = TextLogStream(
- stderr_prio, "python.stderr", errors=sys.stderr.errors)
+ stderr_prio, "python.stderr", sys.stderr.fileno(),
+ errors=sys.stderr.errors)
class TextLogStream(io.TextIOWrapper):
- def __init__(self, prio, tag, **kwargs):
+ def __init__(self, prio, tag, fileno=None, **kwargs):
kwargs.setdefault("encoding", "UTF-8")
- super().__init__(BinaryLogStream(prio, tag), **kwargs)
+ super().__init__(BinaryLogStream(prio, tag, fileno), **kwargs)
self._lock = RLock()
self._pending_bytes = []
self._pending_bytes_count = 0
@@ -98,9 +100,10 @@ class TextLogStream(io.TextIOWrapper):
class BinaryLogStream(io.RawIOBase):
- def __init__(self, prio, tag):
+ def __init__(self, prio, tag, fileno=None):
self.prio = prio
self.tag = tag
+ self._fileno = fileno
def __repr__(self):
return f"<BinaryLogStream {self.tag!r}>"
@@ -122,6 +125,12 @@ class BinaryLogStream(io.RawIOBase):
logcat.write(self.prio, self.tag, b)
return len(b)
+ # This is needed by the test suite --timeout option, which uses faulthandler.
+ def fileno(self):
+ if self._fileno is None:
+ raise io.UnsupportedOperation("fileno")
+ return self._fileno
+
# When a large volume of data is written to logcat at once, e.g. when a test
# module fails in --verbose3 mode, there's a risk of overflowing logcat's own