aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2015-01-05 09:03:05 +0100
committerMatěj Cepl <mcepl@cepl.eu>2015-01-05 12:59:40 +0100
commitd17b009ffec3077bf8db6e6902a7456ec90e9c38 (patch)
tree2a5ee305bd8c8a39faf7c2db342d399c689ae432 /test
parenta9e311030533ac6c175e2289e8928e4aae98b6c3 (diff)
downloadpyg-d17b009ffec3077bf8db6e6902a7456ec90e9c38.tar.gz
First draft of the pure Python parser done, we should be noarch.
Fixes #2
Diffstat (limited to 'test')
-rw-r--r--test/__init__.py13
-rwxr-xr-xtest/test_pyg.py13
-rwxr-xr-xtest/test_wlp.py93
3 files changed, 63 insertions, 56 deletions
diff --git a/test/__init__.py b/test/__init__.py
index 55f45b6..e69de29 100644
--- a/test/__init__.py
+++ b/test/__init__.py
@@ -1,13 +0,0 @@
-import os.path
-import sys
-import sysconfig
-
-
-def distutils_dir_name(dname):
- """Returns the name of a distutils build directory"""
- f = "{dirname}.{platform}-{version[0]}.{version[1]}"
- return f.format(dirname=dname,
- platform=sysconfig.get_platform(),
- version=sys.version_info)
-wlp_lib_path = os.path.join('build', distutils_dir_name('lib'))
-sys.path.insert(0, wlp_lib_path)
diff --git a/test/test_pyg.py b/test/test_pyg.py
index 240228b..4c1c1c0 100755
--- a/test/test_pyg.py
+++ b/test/test_pyg.py
@@ -1,15 +1,12 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-import mail2news
-import os
-import os.path
import re
import subprocess
-import sys
-import test
import unittest
+import mail2news
+
class TestM2N(unittest.TestCase):
expected_output = """Newsgroups: pyg.test
@@ -38,6 +35,7 @@ one line test
self.assertEqual(out, self.expected_output)
+# @unittest.skip('not ready')
class TestN2M(unittest.TestCase):
expected_output = """Received: from GATEWAY by mitmanek.ceplovi.cz with pyg
for <test@example.com> ; Mon Dec 15 17:13:30 2014 (CEST)
@@ -59,15 +57,12 @@ Resent-Sender: sender@example.com
""" % (mail2news.VERSION, mail2news.DESC)
def test_n2m(self):
- env = os.environ
- env['PYTHONPATH'] = ":".join(sys.path)
-
with open('examples/articletest.accepted') as in_mail:
pid = subprocess.Popen(['./pygn2m', '-Tvt', 'test@example.com',
'-s', 'sender@example.com',
'-w', 'examples/whitelist.example'],
stdin=subprocess.PIPE,
- stdout=subprocess.PIPE, env=env)
+ stdout=subprocess.PIPE)
in_message = in_mail.read().replace('pyg@pyg.server.tld',
'kame@inwind.it')
out, err = pid.communicate(in_message)
diff --git a/test/test_wlp.py b/test/test_wlp.py
index 9825e44..430c235 100755
--- a/test/test_wlp.py
+++ b/test/test_wlp.py
@@ -1,13 +1,27 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-import logging
-logging.basicConfig(level=logging.DEBUG)
import unittest
-import wlp
-import wlp_lex
-import wlp_yacc
+import wlp_parser
from rply import Token
+import whitelist
+import wlp
+
+
+# logging.basicConfig(level=logging.DEBUG)
+
+EXPECTED_WL = {
+ 'alfarano@students.cs.unibo.it': {
+ 'From:': 'Cosimo Alfarano',
+ 'X-Firstname:': 'Cosimo'
+ },
+ 'kame@innocent.com': {
+ 'From:': 'kame@inwind.it',
+ 'Reply-to': 'me',
+ 'Reply-to:': 'KA',
+ 'Sender:': 'Kalfa'
+ }
+}
class TestWLP(unittest.TestCase):
@@ -49,44 +63,55 @@ class TestWLP(unittest.TestCase):
Token('VAR', 'Sender:'),
Token('VAL', '"Kalfa"')
]
- tokens = list(wlp_lex.lexer.lex(self.test_input))
+ tokens = list(wlp_parser.lexer.lex(self.test_input))
self.assertEqual(tokens, expected_stream)
def test_wlp_parser(self):
expected_tree = [
- [[Token('OWNER', '<kame@innocent.com>'),
- [[Token('VAR', 'From:'),
- Token('VAL', "'ME'"),
- [Token('VAR', 'Sender:'), Token('VAL', '"Cosimo"')],
- [Token('VAR', 'Reply-to'), Token('VAL', '"me"')]]]],
- [[Token('OWNER', '<alfarano@students.cs.unibo.it>'),
- [[Token('VAR', 'From:'),
- Token('VAL', "'Cosimo Alfarano'"),
- [Token('VAR', 'X-Firstname:'), Token('VAL', "'Cosimo'")]]]]]],
- [[Token('OWNER', '<kame@innocent.com>'),
- [[Token('VAR', 'From:'),
- Token('VAL', "'kame@inwind.it'"),
- [Token('VAR', 'Reply-to:'), Token('VAL', '"KA"')],
- [Token('VAR', 'Sender:'), Token('VAL', '"Kalfa"')]]]]]
+ [
+ Token('OWNER', '<kame@innocent.com>'),
+ [
+ [Token('VAR', 'From:'), Token('VAL', "'ME'")],
+ [Token('VAR', 'Sender:'), Token('VAL', '"Cosimo"')],
+ [Token('VAR', 'Reply-to'), Token('VAL', '"me"')]
+ ]
+ ],
+ [
+ Token('OWNER', '<alfarano@students.cs.unibo.it>'),
+ [
+ [Token('VAR', 'From:'), Token('VAL', "'Cosimo Alfarano'")],
+ [Token('VAR', 'X-Firstname:'), Token('VAL', "'Cosimo'")]
+ ]
+ ],
+ [
+ Token('OWNER', '<kame@innocent.com>'),
+ [
+ [Token('VAR', 'From:'), Token('VAL', "'kame@inwind.it'")],
+ [Token('VAR', 'Reply-to:'), Token('VAL', '"KA"')],
+ [Token('VAR', 'Sender:'), Token('VAL', '"Kalfa"')]
+ ]
+ ]
]
- lex_stream = wlp_lex.lexer.lex(self.test_input)
- tree = wlp_yacc.parser.parse(lex_stream)
+ lex_stream = wlp_parser.lexer.lex(self.test_input)
+ tree = wlp_parser.parser.parse(lex_stream)
self.assertEqual(tree, expected_tree)
- def test_wlp_C_parser(self):
+ def test_wlp(self):
wlp.setfilebyname('examples/whitelist.example')
wl_dict = wlp.mkdict()
- expected_dict = {'alfarano@students.cs.unibo.it': {
- 'From:': 'Cosimo Alfarano',
- 'X-Firstname:': 'Cosimo'
- },
- 'kame@innocent.com': {
- 'From:': 'kame@inwind.it',
- 'Reply-to': 'me',
- 'Reply-to:': 'KA',
- 'Sender:': 'Kalfa'}
- }
- self.assertEqual(wl_dict, expected_dict)
+ self.assertEqual(wl_dict, EXPECTED_WL)
+
+
+class TestWhitelist(unittest.TestCase):
+ def setUp(self):
+ self.wl = whitelist.whitelist('examples/whitelist.example')
+
+ def test_init(self):
+ self.assertEqual(self.wl.wl, EXPECTED_WL)
+
+ def test_checkfrom(self):
+ self.assertEqual(self.wl.checkfrom('kame@inwind.it'),
+ 'kame@innocent.com')
if __name__ == "__main__":
unittest.main()