aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2014-02-11 09:34:59 +0100
committerMatěj Cepl <mcepl@redhat.com>2014-02-13 02:01:54 +0100
commit23a64455b1d30b5ed71ac58cb786aeeb54f168c2 (patch)
treef736d340a7cf8e2ae69a10a851a1c7f003316a76
parent31152dadf548370abb25e93bbdf4359c8b155433 (diff)
downloadgg_scraper-23a64455b1d30b5ed71ac58cb786aeeb54f168c2.tar.gz
Fix setup.py.RunTests.run() to return proper exit code.
The previous situation didn't fail on Travis-CI. But this does, so I had to include also a number of fixes for revealed issues. Fixing #314, #315, #316, and #317
-rwxr-xr-xgg_scraper.py21
-rw-r--r--setup.py4
-rw-r--r--test/test_functional.py26
-rw-r--r--test/test_unit.py10
4 files changed, 35 insertions, 26 deletions
diff --git a/gg_scraper.py b/gg_scraper.py
index 563229f..cb6bc4e 100755
--- a/gg_scraper.py
+++ b/gg_scraper.py
@@ -54,12 +54,11 @@ MANGLED_ADDR_RE = re.compile(
r'([a-zA-Z0-9_.+-]+\.\.\.@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)',
re.IGNORECASE)
-__version__ = '0.6'
+__version__ = '0.7'
-if sys.version_info[:2] < (2, 7):
- py26 = True
-else:
- py26 = False
+pyver = sys.version_info
+py26 = pyver[:2] < (2, 7)
+py3k = pyver[0] == 3
class Page(object):
@@ -112,15 +111,19 @@ class Article(Page):
result = None
try:
res = self.opener.open(self.root)
- if not py26:
+ if not py3k:
raw_msg = res.read().decode('utf8')
else:
raw_msg = res.read()
proc = subprocess.Popen(['/usr/bin/formail'],
stdin=subprocess.PIPE,
- stdout=subprocess.PIPE,
- universal_newlines=True)
+ stdout=subprocess.PIPE)
+ #universal_newlines=True)
+ if not(py3k and isinstance(raw_msg, bytes)):
+ raw_msg = raw_msg.encode('utf8')
result = proc.communicate(raw_msg)[0]
+ if not py3k:
+ result = result.decode('utf8')
res.close()
except HTTPError as exc:
logging.warning('Exception on downloading {0}:\n{1}'.format(
@@ -298,7 +301,7 @@ class MBOX(mailbox.mbox):
else:
self.add(mbx_str.encode('utf8'))
except UnicodeDecodeError:
- logging.debug('mbx_str = type {0}'.format(type(mbx_str)))
+ logging.warning('mbx_str = type {0}'.format(type(mbx_str)))
self.unlock()
self.close()
diff --git a/setup.py b/setup.py
index 331e57e..3695fad 100644
--- a/setup.py
+++ b/setup.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
+import sys
from distutils.core import setup, Command
try:
import unittest2 as unittest
@@ -25,7 +26,8 @@ class RunTests(Command):
def run(self):
tests = unittest.TestLoader().discover('test')
runner = unittest.TextTestRunner(verbosity=2)
- runner.run(tests)
+ res = runner.run(tests)
+ sys.exit(int(not res.wasSuccessful()))
classifiers = [
diff --git a/test/test_functional.py b/test/test_functional.py
index 31fc4ec..44a5c8f 100644
--- a/test/test_functional.py
+++ b/test/test_functional.py
@@ -18,18 +18,21 @@ ARTICLE_URL = 'https://groups.google.com/d/msg/jbrout' + \
'/xNwoVmC07KI/OfpRHFscUkwJ'
-def msg_wo_From(inmsg):
- return '\n'.join(inmsg.replace('\r\n', '\n').split('\n')[1:])
-
-
class TestGGScrapperFunctional(unittest.TestCase):
- def setUp(self):
- self.dired = lambda x: os.path.join(os.path.dirname(__file__), x)
+ @staticmethod
+ def msg_wo_From(inmsg):
+ if gg_scraper.py3k and isinstance(inmsg, bytes):
+ inmsg = inmsg.decode()
+ out = inmsg.replace('\r\n', '\n').split('\n')[1:]
+ return '\n'.join(out)
+
+ @staticmethod
+ def dired(x):
+ return os.path.join(os.path.dirname(__file__), x)
def test_collecting_topics(self):
page = gg_scraper.Group(IN_URL)
topics = page.get_topics()
- logging.debug("number of topics = %d", len(topics))
self.assertGreater(len(topics), 0)
def test_collecting_articles(self):
@@ -39,8 +42,6 @@ class TestGGScrapperFunctional(unittest.TestCase):
'ubuntu 11.04 ?')
articles = topic.get_articles()
article_count = topic.get_count_articles()
- logging.debug('article_count = {0:d}'.format(article_count))
- logging.debug('articles = len {0:d}'.format(len(articles)))
self.assertEqual(len(articles), article_count)
def test_get_raw_article(self):
@@ -49,17 +50,18 @@ class TestGGScrapperFunctional(unittest.TestCase):
with io.open(self.dired('message.eml'), 'r',
encoding='utf8') as exp_f:
- self.assertEqual(msg_wo_From(article.collect_message()),
+ self.assertEqual(self.msg_wo_From(article.collect_message()),
exp_f.read())
def test_py26_unicode_raw_article(self):
self.maxDiff = None
URL = 'https://groups.google.com/forum/message/raw?' + \
'msg=django-oscar/BbBiMWwolf0/gn-s0sFYEhkJ'
- article = msg_wo_From(gg_scraper.Article(URL).collect_message())
+ article = self.msg_wo_From(gg_scraper.Article(URL).collect_message())
with io.open(self.dired('py26_unicode.eml'), 'r',
encoding='utf8') as exp_f:
- self.assertEqual(article, exp_f.read())
+ expected = exp_f.read()
+ self.assertEqual(article, expected)
if __name__ == '__main__':
diff --git a/test/test_unit.py b/test/test_unit.py
index e0fd0a4..25de312 100644
--- a/test/test_unit.py
+++ b/test/test_unit.py
@@ -3,9 +3,9 @@ import tempfile
import yaml
import sys
try:
- import unittest2 as unittest
+ import unittest2 as unittest
except ImportError:
- import unittest
+ import unittest
import gg_scraper
from gg_scraper import Group, Topic, Article # noqa
@@ -27,7 +27,8 @@ class TestMBOX(unittest.TestCase):
with open(group_file_name, 'r') as group_f:
self.group = yaml.load(group_f)
- @unittest.skipIf(sys.version_info[:2] < (2, 7), 'Formatting on 2.6 is different')
+ @unittest.skipIf(sys.version_info[:2] < (2, 7),
+ 'Formatting on 2.6 is different')
def test_create_mbox(self):
'''Create a mbox file from (YAMLed) Group
'''
@@ -37,7 +38,8 @@ class TestMBOX(unittest.TestCase):
with open('test/mbox.mbx') as exp_f:
with open(mbx_file.name) as mbx_f:
- self.assertEqual(exp_f.read(), mbx_f.read())
+ self.assertEqual(exp_f.read().strip(),
+ mbx_f.read().strip())
os.unlink(mbx_file.name)