summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2018-07-17 21:31:05 -0700
committerDylan Baker <dylan@pnwbakers.com>2018-07-26 10:36:11 -0700
commit6e5fe5141f5e9ab479ae4a865d1cf7772cbf379e (patch)
tree363d893c342091a39c5024964a3590a07bcb2c92 /tests
parent4035958005f57bc617e3067e0b35c7409a32be33 (diff)
helper: use asyncio.subprocess instead of twisted
Diffstat (limited to 'tests')
-rw-r--r--tests/helper_test.py45
1 files changed, 21 insertions, 24 deletions
diff --git a/tests/helper_test.py b/tests/helper_test.py
index 061ce122..6f0add53 100644
--- a/tests/helper_test.py
+++ b/tests/helper_test.py
@@ -1,5 +1,5 @@
# encoding=utf-8
-# Copyright © 2016-2017 Dylan Baker
+# Copyright © 2016-2018 Dylan Baker
# Copyright © 2017 Lucas Hoffman
# This program is free software: you can redistribute it and/or modify
@@ -25,8 +25,6 @@ import random
import mock
from twisted.trial import unittest
-from twisted.internet.defer import inlineCallbacks
-from twisted.internet.error import ProcessTerminated
from alot import helper
@@ -427,20 +425,20 @@ class TestShorten(unittest.TestCase):
class TestCallCmdAsync(unittest.TestCase):
- @inlineCallbacks
- def test_no_stdin(self):
- ret = yield helper.call_cmd_async(['echo', '-n', 'foo'])
- self.assertEqual(ret, 'foo')
+ @utilities.async_test
+ async def test_no_stdin(self):
+ ret = await helper.call_cmd_async(['echo', '-n', 'foo'])
+ self.assertEqual(ret[0], 'foo')
- @inlineCallbacks
- def test_stdin(self):
- ret = yield helper.call_cmd_async(['cat', '-'], stdin='foo')
- self.assertEqual(ret, 'foo')
+ @utilities.async_test
+ async def test_stdin(self):
+ ret = await helper.call_cmd_async(['cat', '-'], stdin='foo')
+ self.assertEqual(ret[0], 'foo')
- @inlineCallbacks
- def test_env_set(self):
+ @utilities.async_test
+ async def test_env_set(self):
with mock.patch.dict(os.environ, {}, clear=True):
- ret = yield helper.call_cmd_async(
+ ret = await helper.call_cmd_async(
# Thanks to the future import it doesn't matter if python is
# python2 or python3
['python', '-c', 'from __future__ import print_function; '
@@ -448,21 +446,20 @@ class TestCallCmdAsync(unittest.TestCase):
'print(os.environ.get("foo", "fail"), end="")'
],
env={'foo': 'bar'})
- self.assertEqual(ret, 'bar')
+ self.assertEqual(ret[0], 'bar')
- @inlineCallbacks
- def test_env_doesnt_pollute(self):
+ @utilities.async_test
+ async def test_env_doesnt_pollute(self):
with mock.patch.dict(os.environ, {}, clear=True):
- yield helper.call_cmd_async(['echo', '-n', 'foo'],
+ await helper.call_cmd_async(['echo', '-n', 'foo'],
env={'foo': 'bar'})
self.assertEqual(os.environ, {})
- @inlineCallbacks
- def test_command_fails(self):
- with self.assertRaises(ProcessTerminated) as cm:
- yield helper.call_cmd_async(['_____better_not_exist'])
- self.assertEqual(cm.exception.exitCode, 1)
- self.assertTrue(cm.exception.stderr)
+ @utilities.async_test
+ async def test_command_fails(self):
+ _, err, ret = await helper.call_cmd_async(['_____better_not_exist'])
+ self.assertEqual(ret, 1)
+ self.assertTrue(err)
class TestGetEnv(unittest.TestCase):