[PATCH v6 1/2] parsemail: Convert to a management command
Daniel Axtens
dja at axtens.net
Tue Sep 20 15:09:42 AEST 2016
Hi Stephen,
> + def test_missing_project_stdin(self):
> + path = os.path.join(TEST_MAIL_DIR, '0001-git-pull-request.mbox')
> + with open(path) as file_:
> + with self.assertRaises(SystemExit) as exc:
> + call_command('parsemail', infile=file_)
> +
> + self.assertEqual(exc.exception.code, 1)
> +
I don't think this is actually testing stdin.
I think you want something like this:
diff --git a/patchwork/tests/test_management.py b/patchwork/tests/test_management.py
index f2b968f5be35..42700dd9bb15 100644
--- a/patchwork/tests/test_management.py
+++ b/patchwork/tests/test_management.py
@@ -18,6 +18,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import os
+import sys
from django.core.management import call_command
from django.test import TestCase
@@ -46,9 +47,10 @@ class ParsemailTest(TestCase):
def test_missing_project_stdin(self):
path = os.path.join(TEST_MAIL_DIR, '0001-git-pull-request.mbox')
- with open(path) as file_:
- with self.assertRaises(SystemExit) as exc:
- call_command('parsemail', infile=file_)
+ sys.stdin.close()
+ sys.stdin = open(path)
+ with self.assertRaises(SystemExit) as exc:
+ call_command('parsemail', infile=None)
self.assertEqual(exc.exception.code, 1)
@@ -70,10 +72,11 @@ class ParsemailTest(TestCase):
utils.create_state()
path = os.path.join(TEST_MAIL_DIR, '0001-git-pull-request.mbox')
- with open(path) as file_:
- with self.assertRaises(SystemExit) as exc:
- call_command('parsemail', infile=file_,
- list_id=project.listid)
+ sys.stdin.close()
+ sys.stdin = open(path)
+ with self.assertRaises(SystemExit) as exc:
+ call_command('parsemail', infile=None,
+ list_id=project.listid)
self.assertEqual(exc.exception.code, 0)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 859 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/patchwork/attachments/20160920/630ebe2a/attachment.sig>
More information about the Patchwork
mailing list