summaryrefslogtreecommitdiff
path: root/tests/test_subprocess.py
blob: 87d0ee42da15ab094cca45a5ca39184e8c2226c1 (plain)
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
import asyncio
import asyncio.subprocess
import os
import sys
import unittest

class SubprocessTestCase(unittest.TestCase):
    def setUp(self):
        policy = asyncio.get_event_loop_policy()
        if os.name == 'nt':
            self.loop = asyncio.ProactorEventLoop()
        else:
            self.loop = policy.new_event_loop()
        # ensure that the event loop is passed explicitly in the code
        policy.set_event_loop(None)

    def test_shell(self):
        args = [sys.executable, '-c', 'pass']

        @asyncio.coroutine
        def run():
            return (yield from asyncio.subprocess.call(*args, loop=self.loop))

        exitcode = self.loop.run_until_complete(run())
        self.assertEqual(exitcode, 0)


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