diff options
Diffstat (limited to 'tests/helper_test.py')
-rw-r--r-- | tests/helper_test.py | 45 |
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): |