Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 526862 | Differences between
and this patch

Collapse All | Expand All

(-)tests/TestGoodreadsSource.py (-1 / +1 lines)
Lines 24-30 Link Here
24
24
25
class TestGoodreadsSource(unittest.TestCase):
25
class TestGoodreadsSource(unittest.TestCase):
26
    def test_get_for_author(self):
26
    def test_get_for_author(self):
27
        p = Jumble(["../plugins"])
27
        p = Jumble(["../data/plugins"])
28
        p.load()
28
        p.load()
29
        source = p.get_plugins(typename="GoodreadsSource")[0]
29
        source = p.get_plugins(typename="GoodreadsSource")[0]
30
        q = source["plugin"].get_for_author(u"Вежинов")
30
        q = source["plugin"].get_for_author(u"Вежинов")
(-)tests/TestJumble.py (-5 / +5 lines)
Lines 22-28 Link Here
22
from jumble.IPlugin import IPlugin
22
from jumble.IPlugin import IPlugin
23
from variety.plugins.IQuoteSource import IQuoteSource
23
from variety.plugins.IQuoteSource import IQuoteSource
24
24
25
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), "..")))
25
#sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), "..")))
26
26
27
class P1(IPlugin):
27
class P1(IPlugin):
28
    pass
28
    pass
Lines 33-40 Link Here
33
33
34
class TestJumble(unittest.TestCase):
34
class TestJumble(unittest.TestCase):
35
    def test_load(self):
35
    def test_load(self):
36
        p = Jumble(".")
36
        p = Jumble(["../data/plugins"])
37
        p.load()
37
        p.load()
38
        self.assertEqual(2, len(p.get_plugins()))
38
        self.assertEqual(4, len(p.get_plugins()))
39
        self.assertEqual(2, len(p.get_plugins(IPlugin)))
39
        self.assertEqual(4, len(p.get_plugins(IPlugin)))
40
        self.assertEqual(1, len(p.get_plugins(IQuoteSource)))
40
        self.assertEqual(1, len(p.get_plugins(name="Goodreads")))
(-)tests/TestQuotationsPageSource.py (-5 / +5 lines)
Lines 24-30 Link Here
24
24
25
class TestQuotationsPageSource(unittest.TestCase):
25
class TestQuotationsPageSource(unittest.TestCase):
26
    def test_get_random(self):
26
    def test_get_random(self):
27
        p = Jumble(["../plugins"])
27
        p = Jumble(["../data/plugins"])
28
        p.load()
28
        p.load()
29
        source = p.get_plugins(typename="QuotationsPageSource")[0]
29
        source = p.get_plugins(typename="QuotationsPageSource")[0]
30
        q = source["plugin"].get_random()
30
        q = source["plugin"].get_random()
Lines 32-47 Link Here
32
        self.assertEqual("TheQuotationsPage.com", q[0]["sourceName"])
32
        self.assertEqual("TheQuotationsPage.com", q[0]["sourceName"])
33
33
34
    def test_get_for_author(self):
34
    def test_get_for_author(self):
35
        p = Jumble(["../plugins"])
35
        p = Jumble(["../data/plugins"])
36
        p.load()
36
        p.load()
37
        source = p.get_plugins(typename="QuotationsPageSource")[0]
37
        source = p.get_plugins(typename="QuotationsPageSource")[0]
38
        q = source["plugin"].get_for_author("einstein")
38
        q = source["plugin"].get_for_author("voltaire")
39
        self.assertTrue(len(q) > 0)
39
        self.assertTrue(len(q) > 0)
40
        self.assertEqual("TheQuotationsPage.com", q[0]["sourceName"])
40
        self.assertEqual("TheQuotationsPage.com", q[0]["sourceName"])
41
        self.assertEqual("Albert Einstein", q[0]["author"])
41
        self.assertEqual("Voltaire", q[0]["author"])
42
42
43
    def test_get_for_keyword(self):
43
    def test_get_for_keyword(self):
44
        p = Jumble(["../plugins"])
44
        p = Jumble(["../data/plugins"])
45
        p.load()
45
        p.load()
46
        source = p.get_plugins(typename="QuotationsPageSource")[0]
46
        source = p.get_plugins(typename="QuotationsPageSource")[0]
47
        q = source["plugin"].get_for_keyword("funny")
47
        q = source["plugin"].get_for_keyword("funny")
(-)tests/TestQuotesDaddySource.py (-1 / +1 lines)
Lines 24-30 Link Here
24
24
25
class TestQuotesDaddySource(unittest.TestCase):
25
class TestQuotesDaddySource(unittest.TestCase):
26
    def test_get_random(self):
26
    def test_get_random(self):
27
        p = Jumble(["../plugins"])
27
        p = Jumble(["../data/plugins"])
28
        p.load()
28
        p.load()
29
        source = p.get_plugins(typename="QuotesDaddySource")[0]
29
        source = p.get_plugins(typename="QuotesDaddySource")[0]
30
        q = source["plugin"].get_random()[0]
30
        q = source["plugin"].get_random()[0]
(-)tests/TestQuotesEngine.py (-84 lines)
Lines 1-84 Link Here
1
#!/usr/bin/python
2
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3
### BEGIN LICENSE
4
# Copyright (c) 2012, Peter Levi <peterlevi@peterlevi.com>
5
# This program is free software: you can redistribute it and/or modify it 
6
# under the terms of the GNU General Public License version 3, as published 
7
# by the Free Software Foundation.
8
# 
9
# This program is distributed in the hope that it will be useful, but 
10
# WITHOUT ANY WARRANTY; without even the implied warranties of 
11
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
12
# PURPOSE.  See the GNU General Public License for more details.
13
# 
14
# You should have received a copy of the GNU General Public License along 
15
# with this program.  If not, see <http://www.gnu.org/licenses/>.
16
### END LICENSE
17
18
import sys
19
import os.path
20
import unittest
21
from variety.QuotesEngine import QuotesEngine
22
23
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), "..")))
24
25
xml1 = """
26
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">
27
    <channel>
28
        <title>Quotes Daddy - Random quote by Albert Einstein</title>
29
        <link>http://www.quotesdaddy.com/</link>
30
        <description/>
31
        <pubDate>Mon, 12 Nov 2012 13:23:57 +0000</pubDate>
32
        <language>en</language>
33
        <item>
34
            <title>
35
                "We can't solve problems by using the same kind of thinking we used when we created them." - Albert Einstein
36
            </title>
37
            <link>
38
                http://www.quotesdaddy.com/quote/17473/albert-einstein/we-cant-solve-problems-by-using-the-same-kind-of-thinking
39
            </link>
40
            <description>
41
                "We can't solve problems by using the same kind of thinking we used when we created them." - Albert Einstein
42
            </description>
43
            <guid isPermalink="false">17473</guid>
44
            <pubDate>Mon, 12 Nov 2012 13:23:57 +0000</pubDate>
45
        </item>
46
    </channel>
47
</rss>
48
"""
49
50
class TestQuotesEngine(unittest.TestCase):
51
    def test_extract_quote(self):
52
        self.assertEqual({"quote" : u"\u201C%s\u201D" % "We can't solve problems by using the same kind of thinking we used when we created them.",
53
                          "author" : "Albert Einstein",
54
                          "link" : "http://www.quotesdaddy.com/quote/17473/albert-einstein/we-cant-solve-problems-by-using-the-same-kind-of-thinking"},
55
                         QuotesEngine.extract_quote(xml1))
56
57
    def test_choose_random_feed_url(self):
58
        class Opt:
59
            def __init__(self, tags, authors):
60
                self.quotes_tags = tags
61
                self.quotes_authors = authors
62
63
        skip = set()
64
        url = QuotesEngine.choose_random_feed_url(Opt("a,b", ""), skip)
65
        self.assertTrue(url.startswith("http://www.quotesdaddy.com/feed/tagged/"))
66
        skip.add(url)
67
        url = QuotesEngine.choose_random_feed_url(Opt("a,b", ""), skip)
68
        self.assertTrue(url.startswith("http://www.quotesdaddy.com/feed/tagged/"))
69
        skip.add(url)
70
        url = QuotesEngine.choose_random_feed_url(Opt("a,b", ""), skip)
71
        self.assertEquals("http://www.quotesdaddy.com/feed", url)
72
73
        skip = set()
74
        url = QuotesEngine.choose_random_feed_url(Opt("", "a,b"), skip)
75
        self.assertTrue(url.startswith("http://www.quotesdaddy.com/feed/author/"))
76
        skip.add(url)
77
        url = QuotesEngine.choose_random_feed_url(Opt("", "a,b"), skip)
78
        self.assertTrue(url.startswith("http://www.quotesdaddy.com/feed/author/"))
79
        skip.add(url)
80
        url = QuotesEngine.choose_random_feed_url(Opt("", "a,b"), skip)
81
        self.assertEquals("http://www.quotesdaddy.com/feed", url)
82
83
if __name__ == '__main__':
84
    unittest.main()
(-)tests/test_example.py (-37 lines)
Lines 1-37 Link Here
1
#!/usr/bin/python
2
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3
### BEGIN LICENSE
4
# Copyright (c) 2012, Peter Levi <peterlevi@peterlevi.com>
5
# This program is free software: you can redistribute it and/or modify it 
6
# under the terms of the GNU General Public License version 3, as published 
7
# by the Free Software Foundation.
8
# 
9
# This program is distributed in the hope that it will be useful, but 
10
# WITHOUT ANY WARRANTY; without even the implied warranties of 
11
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
12
# PURPOSE.  See the GNU General Public License for more details.
13
# 
14
# You should have received a copy of the GNU General Public License along 
15
# with this program.  If not, see <http://www.gnu.org/licenses/>.
16
### END LICENSE
17
18
import sys
19
import os.path
20
import unittest
21
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), "..")))
22
23
from variety import AboutVarietyDialog
24
25
class TestExample(unittest.TestCase):
26
    def setUp(self):
27
        self.AboutVarietyDialog_members = [
28
        'AboutDialog', 'AboutVarietyDialog', 'gettext', 'logger', 'logging']
29
30
    def test_AboutVarietyDialog_members(self):
31
        all_members = dir(AboutVarietyDialog)
32
        public_members = [x for x in all_members if not x.startswith('_')]
33
        public_members.sort()
34
        self.assertEqual(self.AboutVarietyDialog_members, public_members)
35
36
if __name__ == '__main__':    
37
    unittest.main()

Return to bug 526862