# HG changeset patch
# User Dan Villiom Podlaski Christiansen <danchr@gmail.com>
# Date 1637543377 -3600
#      Mon Nov 22 02:09:37 2021 +0100
# Node ID 265a78f97b7bcce0f524200e5279a97734d55999
# Parent  48575d96fe199cf8dd359efc99e000c04f57ce9e
tests: extract getpass extension to dedicated file

Not only is this easier to view and edit, but it also avoids causing
issues with coverage.

diff --git a/tests/test-serve-ci.t b/tests/test-serve-ci.t
--- a/tests/test-serve-ci.t
+++ b/tests/test-serve-ci.t
@@ -11,23 +11,9 @@
 
 Allow password prompts without a TTY:
 
-  $ cat << EOF > get_pass.py
-  > from __future__ import generator_stop
-  > import getpass, os, sys
-  > def newgetpass(args):
-  >     try:
-  >       passwd = os.environb.get(b'PASSWD', b'nope')
-  >       print(passwd.encode())
-  >     except AttributeError: # python 2.7
-  >       passwd = os.environ.get('PASSWD', 'nope')
-  >       print(passwd)
-  >     sys.stdout.flush()
-  >     return passwd
-  > getpass.getpass = newgetpass
-  > EOF
   $ cat >> $HGRCPATH << EOF
   > [extensions]
-  > getpass = $TESTTMP/get_pass.py
+  > getpass = $TESTDIR/testlib/ext-get-password-from-env.py
   > EOF
 
 Create a silly SSH configuration:
diff --git a/tests/testlib/ext-get-password-from-env.py b/tests/testlib/ext-get-password-from-env.py
new file mode 100644
--- /dev/null
+++ b/tests/testlib/ext-get-password-from-env.py
@@ -0,0 +1,23 @@
+#
+# small dummy extension that obtains passwords from an environment
+# variable
+#
+
+from __future__ import generator_stop
+
+import getpass
+import os
+import sys
+
+
+def newgetpass(args):
+    try:
+      passwd = os.environb.get(b'PASSWD', b'nope')
+      print(passwd.encode())
+    except AttributeError: # python 2.7
+      passwd = os.environ.get('PASSWD', 'nope')
+      print(passwd)
+    sys.stdout.flush()
+    return passwd
+
+getpass.getpass = newgetpass