#!/usr/bin/env python import unittest, xml.dom.minidom from planet import shell, config, logger class XsltFilterTests(unittest.TestCase): def test_xslt_filter(self): config.load('tests/data/filter/translate.ini') testfile = 'tests/data/filter/category-one.xml' input = open(testfile).read() output = shell.run(config.filters()[0], input, mode="filter") dom = xml.dom.minidom.parseString(output) catterm = dom.getElementsByTagName('category')[0].getAttribute('term') self.assertEqual('OnE', catterm) try: import libxslt except: try: from subprocess import Popen, PIPE xsltproc=Popen(['xsltproc','--version'],stdout=PIPE,stderr=PIPE) xsltproc.communicate() if xsltproc.returncode != 0: raise ImportError except: logger.warn("libxslt is not available => can't test xslt filters") del XsltFilterTests.test_xslt_filter
self.assertEqual('', output) testfile = 'tests/data/filter/category-two.xml' output = open(testfile).read() for filter in config.filters(): output = shell.run(filter, output, mode="filter") self.assertNotEqual('', output) try: from subprocess import Popen, PIPE sed=Popen(['sed','--version'],stdout=PIPE,stderr=PIPE) sed.communicate() if sed.returncode != 0: logger.warn("sed is not available => can't test stripAd_yahoo") del FilterTests.test_stripAd_yahoo try: import libxml2 except: logger.warn("libxml2 is not available => can't test xpath_sifter") del FilterTests.test_xpath_filter1 del FilterTests.test_xpath_filter2 except ImportError: logger.warn("Popen is not available => can't test standard filters") for method in dir(FilterTests): if method.startswith('test_'): delattr(FilterTests,method)
output = shell.run(filter, open(testfile).read(), mode="filter") self.assertTrue(output.find('<h2>Search</h2>') >= 0) self.assertTrue(output.find('<form><input name="q"/></form>') >= 0) self.assertTrue( output.find( ' href="http://planet.intertwingly.net/opensearchdescription.xml"' ) >= 0) self.assertTrue(output.find('</script>') >= 0) try: import libxslt except: try: try: # Python 2.5 bug 1704790 workaround (alas, Unix only) import commands if commands.getstatusoutput('xsltproc --version')[0] != 0: raise ImportError except: from subprocess import Popen, PIPE xsltproc = Popen(['xsltproc', '--version'], stdout=PIPE, stderr=PIPE) xsltproc.communicate() if xsltproc.returncode != 0: raise ImportError except: logger.warn("libxslt is not available => can't test xslt filters") del XsltFilterTests.test_xslt_filter del XsltFilterTests.test_addsearch_filter
import test_filter_genshi for method in dir(test_filter_genshi.GenshiFilterTests): if method.startswith('test_'): break else: delattr(ApplyTest,'test_apply_genshi_fancy') try: import libxml2 except ImportError: delattr(ApplyTest,'test_apply_filter_mememe') try: import win32pipe (stdin,stdout) = win32pipe.popen4('xsltproc -V', 't') stdin.close() stdout.read() try: exitcode = stdout.close() except IOError: exitcode = -1 except: import commands (exitstatus,output) = commands.getstatusoutput('xsltproc -V') exitcode = ((exitstatus>>8) & 0xFF) if exitcode: logger.warn("xsltproc is not available => can't test XSLT templates") for method in dir(ApplyTest): if method.startswith('test_'): delattr(ApplyTest,method)
'photos_public.gne?id=SOMEID', 'http://del.icio.us/rss/SOMEID', 'http://del.icio.us/rss/eliast', 'http://torrez.us/feed/rdf' ], feeds) def test_recursive(self): config.load('tests/data/config/foaf-deep.ini') feeds = config.subscriptions() feeds.sort() self.assertEqual([ 'http://api.flickr.com/services/feeds/photos_public.gne?id=77366516@N00', 'http://del.icio.us/rss/eliast', 'http://del.icio.us/rss/leef', 'http://del.icio.us/rss/rubys', 'http://intertwingly.net/blog/atom.xml', 'http://thefigtrees.net/lee/life/atom.xml', 'http://torrez.us/feed/rdf' ], feeds) # these tests only make sense if libRDF is installed try: import RDF except ImportError: logger.warn( "Redland RDF is not available => can't test FOAF reading lists") for key in FoafTest.__dict__.keys(): if key.startswith('test_'): delattr(FoafTest, key) if __name__ == '__main__': unittest.main()
#!/usr/bin/env python # coding=utf-8 import unittest from planet import logger, shell class GenshiFilterTests(unittest.TestCase): def test_addsearch_filter(self): testfile = 'tests/data/filter/index.html' the_filter = 'addsearch.genshi' with open(testfile) as fp: output = shell.run(the_filter, fp.read(), mode="filter") self.assertTrue(output.find('<h2>Search</h2>') >= 0) self.assertTrue(output.find('<form><input name="q"/></form>') >= 0) self.assertTrue(output.find(' href="http://planet.intertwingly.net/opensearchdescription.xml"') >= 0) self.assertTrue(output.find('</script>') >= 0) try: import genshi except ImportError: logger.warn("Genshi is not available => can't test genshi filters") for method in dir(GenshiFilterTests): if method.startswith('test_'): delattr(GenshiFilterTests, method)
def test_django_date_type(self): config.load('tests/data/filter/django/test.ini') results = dj.tmpl.template_info("<feed/>") self.assertEqual(type(results['date']), datetime.datetime) def test_django_entry_title(self): config.load('tests/data/filter/django/test.ini') feed = open('tests/data/filter/django/test.xml') input = feed.read() feed.close() results = dj.run( os.path.realpath('tests/data/filter/django/title.html.dj'), input) self.assertEqual(results, "\xc2\xa1Atom-Powered Robots Run Amok!\n") def test_django_config_context(self): config.load('tests/data/filter/django/test.ini') feed = open('tests/data/filter/django/test.xml') input = feed.read() feed.close() results = dj.run( os.path.realpath('tests/data/filter/django/config.html.dj'), input) self.assertEqual(results, "Django on Venus\n") try: from django.conf import settings except ImportError: logger.warn("Django is not available => can't test django filters") for method in dir(DjangoFilterTests): if method.startswith('test_'): delattr(DjangoFilterTests, method)
feeds.sort() self.assertEqual(5,len(feeds)) self.assertEqual(['http://api.flickr.com/services/feeds/' + 'photos_public.gne?id=77366516@N00', 'http://api.flickr.com/services/feeds/' + 'photos_public.gne?id=SOMEID', 'http://del.icio.us/rss/SOMEID', 'http://del.icio.us/rss/eliast', 'http://torrez.us/feed/rdf'], feeds) def test_recursive(self): config.load('tests/data/config/foaf-deep.ini') feeds = config.subscriptions() feeds.sort() self.assertEqual(['http://api.flickr.com/services/feeds/photos_public.gne?id=77366516@N00', 'http://del.icio.us/rss/eliast', 'http://del.icio.us/rss/leef', 'http://del.icio.us/rss/rubys', 'http://intertwingly.net/blog/atom.xml', 'http://thefigtrees.net/lee/life/atom.xml', 'http://torrez.us/feed/rdf'], feeds) # these tests only make sense if libRDF is installed try: import RDF except: logger.warn("Redland RDF is not available => can't test FOAF reading lists") for key in FoafTest.__dict__.keys(): if key.startswith('test_'): delattr(FoafTest, key) if __name__ == '__main__': unittest.main()
#!/usr/bin/env python import unittest, xml.dom.minidom from planet import shell, config, logger class GenshiFilterTests(unittest.TestCase): def test_addsearch_filter(self): testfile = 'tests/data/filter/index.html' filter = 'addsearch.genshi' output = shell.run(filter, open(testfile).read(), mode="filter") self.assertTrue(output.find('<h2>Search</h2>')>=0) self.assertTrue(output.find('<form><input name="q"/></form>')>=0) self.assertTrue(output.find(' href="http://planet.intertwingly.net/opensearchdescription.xml"')>=0) self.assertTrue(output.find('</script>')>=0) try: import genshi except: logger.warn("Genshi is not available => can't test genshi filters") for method in dir(GenshiFilterTests): if method.startswith('test_'): delattr(GenshiFilterTests,method)
self.assertEqual(results['name'], 'Django on Venus') def test_django_date_type(self): config.load('tests/data/filter/django/test.ini') results = dj.tmpl.template_info("<feed/>") self.assertEqual(type(results['date']), datetime.datetime) def test_django_entry_title(self): config.load('tests/data/filter/django/test.ini') feed = open('tests/data/filter/django/test.xml') input = feed.read(); feed.close() results = dj.run( os.path.realpath('tests/data/filter/django/title.html.dj'), input) self.assertEqual(results, u"\xa1Atom-Powered Robots Run Amok!\n") def test_django_config_context(self): config.load('tests/data/filter/django/test.ini') feed = open('tests/data/filter/django/test.xml') input = feed.read(); feed.close() results = dj.run( os.path.realpath('tests/data/filter/django/config.html.dj'), input) self.assertEqual(results, "Django on Venus\n") try: from django.conf import settings except ImportError: logger.warn("Django is not available => can't test django filters") for method in dir(DjangoFilterTests): if method.startswith('test_'): delattr(DjangoFilterTests,method)
import test_filter_genshi for method in dir(test_filter_genshi.GenshiFilterTests): if method.startswith('test_'): break else: delattr(ApplyTest, 'test_apply_genshi_fancy') try: import libxml2 except ImportError: delattr(ApplyTest, 'test_apply_filter_mememe') try: import win32pipe (stdin, stdout) = win32pipe.popen4('xsltproc -V', 't') stdin.close() stdout.read() try: exitcode = stdout.close() except IOError: exitcode = -1 except: import commands (exitstatus, output) = commands.getstatusoutput('xsltproc -V') exitcode = ((exitstatus >> 8) & 0xFF) if exitcode: logger.warn("xsltproc is not available => can't test XSLT templates") for method in dir(ApplyTest): if method.startswith('test_'): delattr(ApplyTest, method)
# Python 2.5 bug 1704790 workaround (alas, Unix only) import commands if commands.getstatusoutput('sed --version')[0] == 0: _no_sed = False except: pass if _no_sed: try: sed = Popen(['sed', '--version'], stdout=PIPE, stderr=PIPE) sed.communicate() if sed.returncode == 0: _no_sed = False except WindowsError: pass if _no_sed: logger.warn("sed is not available => can't test stripAd_yahoo") del FilterTests.test_stripAd_yahoo try: import libxml2 except: logger.warn("libxml2 is not available => can't test xpath_sifter") del FilterTests.test_xpath_filter1 del FilterTests.test_xpath_filter2 except ImportError: logger.warn("Popen is not available => can't test standard filters") for method in dir(FilterTests): if method.startswith('test_'): delattr(FilterTests, method)
shutil.rmtree(test_spider.workdir) os.removedirs(os.path.split(test_spider.workdir)[0]) def test_index_splice(self): import test_splice config.load(test_splice.configfile) index = idindex.create() self.assertEqual(12, len(index)) self.assertEqual('tag:planet.intertwingly.net,2006:testfeed1', index['planet.intertwingly.net,2006,testfeed1,1']) self.assertEqual('http://intertwingly.net/code/venus/tests/data/spider/testfeed3.rss', index['planet.intertwingly.net,2006,testfeed3,1']) for key in index.keys(): value = index[key] if value.find('testfeed2')>0: index[key] = value.swapcase() index.close() from planet.splice import splice doc = splice() self.assertEqual(8,len(doc.getElementsByTagName('entry'))) self.assertEqual(4,len(doc.getElementsByTagName('planet:source'))) self.assertEqual(12,len(doc.getElementsByTagName('planet:name'))) try: module = 'dbhash' except ImportError: logger.warn("dbhash is not available => can't test id index") for method in dir(idIndexTest): if method.startswith('test_'): delattr(idIndexTest,method)