File: local_test.py

package info (click to toggle)
python-mitogen 0.3.0~rc1-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,240 kB
  • sloc: python: 19,899; sh: 91; perl: 19; ansic: 18; makefile: 13
file content (54 lines) | stat: -rw-r--r-- 1,404 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

import os
import sys

import unittest2

import mitogen

import testlib


def get_sys_executable():
    return sys.executable


def get_os_environ():
    return dict(os.environ)


class ConstructionTest(testlib.RouterMixin, testlib.TestCase):
    stub_python_path = testlib.data_path('stubs/stub-python.py')

    def test_stream_name(self):
        context = self.router.local()
        pid = context.call(os.getpid)
        self.assertEquals('local.%d' % (pid,), context.name)

    def test_python_path_inherited(self):
        context = self.router.local()
        self.assertEquals(sys.executable, context.call(get_sys_executable))

    def test_python_path_string(self):
        context = self.router.local(
            python_path=self.stub_python_path,
        )
        env = context.call(get_os_environ)
        self.assertEquals('1', env['THIS_IS_STUB_PYTHON'])

    def test_python_path_list(self):
        context = self.router.local(
            python_path=[
                self.stub_python_path,
                "magic_first_arg",
                sys.executable
            ]
        )
        self.assertEquals(sys.executable, context.call(get_sys_executable))
        env = context.call(get_os_environ)
        self.assertEquals('magic_first_arg', env['STUB_PYTHON_FIRST_ARG'])
        self.assertEquals('1', env['THIS_IS_STUB_PYTHON'])


if __name__ == '__main__':
    unittest2.main()