diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2015-01-05 09:03:05 +0100 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2015-01-05 12:59:40 +0100 |
commit | d17b009ffec3077bf8db6e6902a7456ec90e9c38 (patch) | |
tree | 2a5ee305bd8c8a39faf7c2db342d399c689ae432 /test/test_wlp.py | |
parent | a9e311030533ac6c175e2289e8928e4aae98b6c3 (diff) | |
download | pygn-d17b009ffec3077bf8db6e6902a7456ec90e9c38.tar.gz |
First draft of the pure Python parser done, we should be noarch.
Fixes #2
Diffstat (limited to 'test/test_wlp.py')
-rwxr-xr-x | test/test_wlp.py | 93 |
1 files changed, 59 insertions, 34 deletions
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() |