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