Debian Codegraph @

testing/mozbase/mozprocess/tests/test_misc.py

raw
1 #!/usr/bin/env python
2
3 import os
4 import sys
5
6 import mozunit
7 import proctest
8 from mozprocess import processhandler
9
10 here = os.path.dirname(os.path.abspath(__file__))
11
12
13 class ProcTestMisc(proctest.ProcTest):
14 """Class to test misc operations"""
15
16 def test_process_timeout_no_kill(self):
17 """Process is started, runs but we time out waiting on it
18 to complete. Process should not be killed.
19 """
20 p = None
21
22 def timeout_handler():
23 self.assertEqual(p.proc.poll(), None)
24 p.kill()
25
26 myenv = None
27 # On macosx1014, subprocess fails to find `six` when run with python3.
28 # This ensures that subprocess first looks to sys.path to find `six`.
29 # See https://bugzilla.mozilla.org/show_bug.cgi?id=1562083
30 if sys.platform == "darwin" and sys.version_info[0] > 2:
31 myenv = os.environ.copy()
32 myenv["PYTHONPATH"] = ":".join(sys.path)
33
34 p = processhandler.ProcessHandler(
35 [self.python, self.proclaunch, "process_waittimeout.ini"],
36 cwd=here,
37 env=myenv,
38 onTimeout=(timeout_handler,),
39 kill_on_timeout=False,
40 )
41 p.run(timeout=1)
42 p.wait()
43 self.assertTrue(p.didTimeout)
44
45 self.determine_status(p, False, ["returncode", "didtimeout"])
46
47 def test_unicode_in_environment(self):
48 env = {
49 "FOOBAR": "ʘ",
50 }
51 p = processhandler.ProcessHandler(
52 [self.python, self.proclaunch, "process_normal_finish.ini"],
53 cwd=here,
54 env=env,
55 )
56 # passes if no exceptions are raised
57 p.run()
58 p.wait()
59
60
61 if __name__ == "__main__":
62 mozunit.main()