From 0070445e57b004a7dcd5a1bd043654017c6a802a Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 12 2011 19:42:49 +0000 Subject: Test case for R2spec --- diff --git a/test/test-R2spec.py b/test/test-R2spec.py new file mode 100644 index 0000000..52b1bd4 --- /dev/null +++ b/test/test-R2spec.py @@ -0,0 +1,89 @@ +#!/usr/bin/python +#-*- coding: utf-8 -*- + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# (C) 2011 - Pierre-Yves Chibon + +""" R2spec launcher script """ + + +# Cases: +# -p +# -> remove sources + +# -u +# -> remove sources + +# --> download sources +# -s remove sources + +import argparse +import os +import sys +import unittest +import urllib2 + +sys.path.insert(0, os.path.abspath('../')) +from r2spec.r2spec_obj import R2spec, setup_parser + +BASE_URL = 'https://fedorahosted.org/releases/F/e/FedoraReview/' +R_TEST_SRC = BASE_URL + 'Rdummypkg_1.0.tar.gz' + + +def download_sources(url): + """ Download the given url in the current working directory. + :arg url, url to the object to download + """ + sources = url.rsplit('/', 1)[1] + remotefile = urllib2.urlopen(url) + localfile = open(sources, 'w') + localfile.write(remotefile.read()) + localfile.close() + return sources + + +class R2spec_tests(unittest.TestCase): + """ R2spec tests. """ + + def __init__(self, methodName='runTest'): + """ Constructor. """ + unittest.TestCase.__init__(self, methodName) + + def test_r2spec_url(self): + """ Test R2spec using an url direct to the sources """ + parser = setup_parser('R2spec') + arg = parser.parse_args() + arg.url = R_TEST_SRC + R2spec().main(arg) + + def test_r2spec_package(self): + """ Test R2spec using a package name """ + parser = setup_parser('R2spec') + arg = parser.parse_args() + arg.package = 'tkWidgets' + R2spec().main(arg) + + def test_r2spec_sources(self): + """ Test R2spec using a package name """ + sources = download_sources(R_TEST_SRC) + parser = setup_parser('R2spec') + arg = parser.parse_args() + arg.sources = sources + R2spec().main(arg) + +suite = unittest.TestLoader().loadTestsFromTestCase(R2spec_tests) +unittest.TextTestRunner(verbosity=2).run(suite)