summaryrefslogtreecommitdiffstats
path: root/testing/mozbase/mozfile/tests/test_which.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/mozbase/mozfile/tests/test_which.py
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/mozbase/mozfile/tests/test_which.py')
-rw-r--r--testing/mozbase/mozfile/tests/test_which.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/testing/mozbase/mozfile/tests/test_which.py b/testing/mozbase/mozfile/tests/test_which.py
new file mode 100644
index 0000000000..b02f13ccdf
--- /dev/null
+++ b/testing/mozbase/mozfile/tests/test_which.py
@@ -0,0 +1,63 @@
+# Any copyright is dedicated to the Public Domain.
+# https://creativecommons.org/publicdomain/zero/1.0/
+
+import os
+import sys
+
+import mozunit
+import six
+from mozfile import which
+
+here = os.path.abspath(os.path.dirname(__file__))
+
+
+def test_which(monkeypatch):
+ cwd = os.path.join(here, "files", "which")
+ monkeypatch.chdir(cwd)
+
+ if sys.platform == "win32":
+ if six.PY3:
+ import winreg
+ else:
+ import _winreg as winreg
+ bindir = os.path.join(cwd, "win")
+ monkeypatch.setenv("PATH", bindir)
+ monkeypatch.setattr(winreg, "QueryValue", (lambda k, sk: None))
+
+ assert which("foo.exe").lower() == os.path.join(bindir, "foo.exe").lower()
+ assert which("foo").lower() == os.path.join(bindir, "foo.exe").lower()
+ assert (
+ which("foo", exts=[".FOO", ".BAR"]).lower()
+ == os.path.join(bindir, "foo").lower()
+ )
+ assert os.environ.get("PATHEXT") != [".FOO", ".BAR"]
+ assert which("foo.txt") is None
+
+ assert which("bar").lower() == os.path.join(bindir, "bar").lower()
+ assert which("baz").lower() == os.path.join(cwd, "baz.exe").lower()
+
+ registered_dir = os.path.join(cwd, "registered")
+ quux = os.path.join(registered_dir, "quux.exe").lower()
+
+ def mock_registry(key, subkey):
+ assert subkey == (
+ r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\quux.exe"
+ )
+ return quux
+
+ monkeypatch.setattr(winreg, "QueryValue", mock_registry)
+ assert which("quux").lower() == quux
+ assert which("quux.exe").lower() == quux
+
+ else:
+ bindir = os.path.join(cwd, "unix")
+ monkeypatch.setenv("PATH", bindir)
+ assert which("foo") == os.path.join(bindir, "foo")
+ assert which("baz") is None
+ assert which("baz", exts=[".EXE"]) is None
+ assert "PATHEXT" not in os.environ
+ assert which("file") is None
+
+
+if __name__ == "__main__":
+ mozunit.main()