def get_plugin_downloader(typename): p = Jumble(["data/plugins"]) p.load() plugin = p.get_plugins(typename=typename)[0]["plugin"] parent = AttrDict() parent.size_ok = lambda x, y: True plugin.set_variety(parent) return plugin
def test_validate(self): parent = AttrDict() parent.options.safe_mode = True source = RedditSource() source.set_variety(parent) def _validate(url): return source.validate(url)[1] is None self.assertTrue(_validate("http://www.reddit.com/r/comics")) self.assertFalse(_validate("http://www.reddit.com/r/nsfw/")) parent.options.safe_mode = False self.assertTrue(_validate("http://www.reddit.com/r/comics")) self.assertTrue(_validate("http://www.reddit.com/r/nsfw/")) self.assertTrue(_validate("http://www.reddit.com/r/AutumnPorn/")) self.assertTrue( _validate( "http://www.reddit.com/r/AutumnPorn/top?sort=top&t=month")) self.assertFalse(_validate("http://www.reddit.com/r/bestof/")) self.assertFalse( _validate("http://www.reddit.com/r/dhkjregfhjregfjfdrejh/")) self.assertFalse( _validate("http://www.notreddit.com/r/dhkjregfhjregfjfdrejh/"))
def test_validate(self): parent = AttrDict() parent.options.safe_mode = True self.assertTrue( RedditDownloader.validate("http://www.reddit.com/r/comics", parent)) self.assertFalse( RedditDownloader.validate("http://www.reddit.com/r/nsfw/", parent)) parent.options.safe_mode = False self.assertTrue( RedditDownloader.validate("http://www.reddit.com/r/comics", parent)) self.assertTrue( RedditDownloader.validate("http://www.reddit.com/r/nsfw/", parent)) self.assertTrue( RedditDownloader.validate("http://www.reddit.com/r/AutumnPorn/")) self.assertTrue( RedditDownloader.validate( "http://www.reddit.com/r/AutumnPorn/top?sort=top&t=month")) self.assertFalse( RedditDownloader.validate("http://www.reddit.com/r/bestof/")) self.assertFalse( RedditDownloader.validate( "http://www.reddit.com/r/dhkjregfhjregfjfdrejh/")) self.assertFalse( RedditDownloader.validate( "http://www.notreddit.com/r/dhkjregfhjregfjfdrejh/"))
def test_attr_dict(self): a = AttrDict({'a': {'b': 1}}) self.assertFalse(bool(a.deep.inside)) self.assertTrue(bool(a.a)) self.assertEqual(1, a.a.b) a.l.k = 3 self.assertEqual(3, a.l.k) a.f.g.h = 2 self.assertEqual(2, a.f.g.h) a["x"]["y"]["z"] = 1 self.assertEqual(1, a["x"]["y"]["z"]) b = AttrDict(x=1, y=2) self.assertFalse(bool(b.deep.inside)) self.assertEqual(1, b.x) self.assertEqual(2, b.y) b.c = {'z': 3} self.assertEqual(3, b.c.z) self.assertFalse(bool(b.c.dredrefre))
def _source(self): parent = AttrDict() parent.size_ok = lambda x, y: True source = UnsplashConfigurableSource() source.set_variety(parent) return source