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/TestJumble.py (-2 / +18 lines)
Lines 25-34 Link Here
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
    @classmethod
29
    def get_info(cls):
30
        return {
31
           "name": "Sample name",
32
           "description": "Sample description",
33
           "version": "1.0",
34
           "author": "Author name", # optional
35
           "url": "Plugin URL"  # optional
36
        }
29
37
30
class P2(IQuoteSource):
38
class P2(IQuoteSource):
31
    pass
39
    @classmethod
40
    def get_info(cls):
41
        return {
42
           "name": "Sample name 2",
43
           "description": "Sample description 2",
44
           "version": "2.0",
45
           "author": "Author name 2", # optional
46
           "url": "Plugin URL 2"  # optional
47
        }
32
48
33
49
34
class TestJumble(unittest.TestCase):
50
class TestJumble(unittest.TestCase):
(-)tests/TestUtil.py (-6 / +7 lines)
Lines 19-24 Link Here
19
import os.path
19
import os.path
20
import unittest
20
import unittest
21
from variety.Util import Util
21
from variety.Util import Util
22
from gi.repository import GLib
22
23
23
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), "..")))
24
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), "..")))
24
25
Lines 62-68 Link Here
62
63
63
    def test_find_unique_name(self):
64
    def test_find_unique_name(self):
64
        self.assertEquals('/etc/fstab_1', Util.find_unique_name('/etc/fstab'))
65
        self.assertEquals('/etc/fstab_1', Util.find_unique_name('/etc/fstab'))
65
        self.assertEquals('/etc/bash_1.bashrc', Util.find_unique_name('/etc/bash.bashrc'))
66
        self.assertEquals('TestUtil_1.py', Util.find_unique_name('TestUtil.py'))
66
67
67
    def test_folderpath(self):
68
    def test_folderpath(self):
68
        self.assertEquals("/", Util.folderpath("/"))
69
        self.assertEquals("/", Util.folderpath("/"))
Lines 97-103 Link Here
97
        self.assertEquals("a32377b309e3230f3c89c455ef1bdf0b", Util.md5file("test.jpg"))
98
        self.assertEquals("a32377b309e3230f3c89c455ef1bdf0b", Util.md5file("test.jpg"))
98
99
99
    def test_collapseuser(self):
100
    def test_collapseuser(self):
100
        self.assertEquals("~/.config/variety", Util.collapseuser("/home/peter/.config/variety"))
101
        self.assertEquals("~/.config/variety", Util.collapseuser(os.environ['HOME'] + "/.config/variety"))
101
        self.assertEquals("/home/peteraaa/.config/variety", Util.collapseuser("/home/peteraaa/.config/variety"))
102
        self.assertEquals("/home/peteraaa/.config/variety", Util.collapseuser("/home/peteraaa/.config/variety"))
102
        self.assertEquals("/media/.config/variety", Util.collapseuser("/media/.config/variety"))
103
        self.assertEquals("/media/.config/variety", Util.collapseuser("/media/.config/variety"))
103
104
Lines 110-119 Link Here
110
    def test_get_file_icon_name(self):
111
    def test_get_file_icon_name(self):
111
        self.assertEquals("folder", Util.get_file_icon_name("/xxx/yyy/zzz")) # nonexistent
112
        self.assertEquals("folder", Util.get_file_icon_name("/xxx/yyy/zzz")) # nonexistent
112
        self.assertEquals("user-home", Util.get_file_icon_name("~"))
113
        self.assertEquals("user-home", Util.get_file_icon_name("~"))
113
        self.assertEquals("folder-pictures", Util.get_file_icon_name("~/Pictures"))
114
        pictures_directory=GLib.get_user_special_dir(GLib.USER_DIRECTORY_PICTURES)
114
115
        # Test proper icon reading of 'Pictures' folder only if one exists for current user
115
    def test_get_xdg_pictures_folder(self):
116
        if not pictures_directory is None:
116
        self.assertEquals(os.path.expanduser('~/Pictures'), Util.get_xdg_pictures_folder())
117
            self.assertEquals("folder-pictures", Util.get_file_icon_name(pictures_directory))
117
118
118
    def test_safe_map(self):
119
    def test_safe_map(self):
119
        def f(i):
120
        def f(i):
(-)data/plugins/quotes/QuotesDaddySource.py (-3 / +8 lines)
Lines 24-29 Link Here
24
24
25
25
26
class QuotesDaddySource(IQuoteSource):
26
class QuotesDaddySource(IQuoteSource):
27
    def __init__(self):
28
        super(QuotesDaddySource,self).__init__()
29
        self.url = "http://www.quotesdaddy.com/feed"
30
31
    def set_url(self, url):
32
        self.url = url
33
27
    @classmethod
34
    @classmethod
28
    def get_info(cls):
35
    def get_info(cls):
29
        return {
36
        return {
Lines 38-46 Link Here
38
        return False
45
        return False
39
46
40
    def get_random(self):
47
    def get_random(self):
41
        url = "http://www.quotesdaddy.com/feed"
48
        bs = Util.xml_soup(self.url)
42
43
        bs = Util.xml_soup(url)
44
        item = bs.find("item")
49
        item = bs.find("item")
45
        if not item:
50
        if not item:
46
            logger.warning("Could not find quotes for URL " + url)
51
            logger.warning("Could not find quotes for URL " + url)
(-)tests/TestQuotesDaddySource.py (-1 / +3 lines)
Lines 24-31 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(["../data/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
        p = source["plugin"]
31
        p.set_url("file:///" + os.path.realpath(os.path.join(os.path.dirname(__file__), "test_quotes_feed.xml")))
32
        q = p.get_random()[0]
31
        self.assertEqual("QuotesDaddy", q["sourceName"])
33
        self.assertEqual("QuotesDaddy", q["sourceName"])
(-)tests/test_quotes_feed.xml (+17 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3
  <channel>
4
    <title>Quotes Daddy - Quote of the Day</title>
5
    <link>http://www.quotesdaddy.com/</link>
6
    <description></description>
7
    <pubDate>Sat, 25 Oct 2014 21:56:34 +0000</pubDate>
8
    <language>en</language>
9
    <item>
10
      <title>&quot;I am a success today because I had a friend who believed in me and I didn't have the heart to let him down...&quot; - Abraham Lincoln</title>
11
      <link>http://www.quotesdaddy.com/quote/288/abraham-lincoln/i-am-a-success-today-because-i-had-a-friend-who-believed</link>
12
      <description>&quot;I am a success today because I had a friend who believed in me and I didn't have the heart to let him down...&quot; - Abraham Lincoln</description>
13
      <guid isPermalink="false">288</guid>
14
      <pubDate>Sat, 25 Oct 2014 21:56:34 +0000</pubDate>
15
    </item>
16
  </channel>
17
</rss>

Return to bug 526862