diff options
author | Till Maas <opensource@till.name> | 2014-02-06 10:26:50 +0100 |
---|---|---|
committer | Till Maas <opensource@till.name> | 2014-02-06 10:26:50 +0100 |
commit | 7095cd04dd77a5d25d9a3f9bd235436e6b48d326 (patch) | |
tree | a19a66521c6a862eaf15a25b6620ad547d356e21 /cnucnu/tests/aliases_test.py | |
parent | 7b095614e12c6c427b6968261633b8808f9299ba (diff) | |
download | cnucnu-7095cd04dd77a5d25d9a3f9bd235436e6b48d326.tar.gz cnucnu-7095cd04dd77a5d25d9a3f9bd235436e6b48d326.tar.xz cnucnu-7095cd04dd77a5d25d9a3f9bd235436e6b48d326.zip |
Package_list: Refactor alias handling
- Use one dictionary to handle alias information
- Use generic function to resolve aliases
- Add basic test cases for aliases
Diffstat (limited to 'cnucnu/tests/aliases_test.py')
-rwxr-xr-x | cnucnu/tests/aliases_test.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/cnucnu/tests/aliases_test.py b/cnucnu/tests/aliases_test.py new file mode 100755 index 0000000..31d9e34 --- /dev/null +++ b/cnucnu/tests/aliases_test.py @@ -0,0 +1,78 @@ +#!/usr/bin/python -tt +# vim: fileencoding=utf8 foldmethod=marker +# {{{ License header: GPLv2+ +# This file is part of cnucnu. +# +# Cnucnu 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. +# +# Cnucnu 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 cnucnu. If not, see <http://www.gnu.org/licenses/>. +# }}} + +import unittest +import sys +sys.path.insert(0, '../..') + +from cnucnu.package_list import unalias, ALIASES + + +class AliasTest(unittest.TestCase): + def testDefaultRegex(self): + regex = unalias("testname", "DEFAULT", "regex") + self.assertEqual(regex, ALIASES["DEFAULT"]["regex"].format( + name="testname")) + + def testCPAN(self): + url = unalias("perl-test", "CPAN-DEFAULT", "url") + self.assertEqual(url, "http://search.cpan.org/dist/test/") + + url = unalias("perl-test", "CPAN-DEFAULT:overridden-name", "url") + self.assertEqual(url, "http://search.cpan.org/dist/overridden-name/") + + def testDebian(self): + url = unalias("testpackage", "DEBIAN-DEFAULT", "url") + self.assertEqual( + url, + "http://ftp.debian.org/debian/pool/main/t/testpackage/" + ) + + def testDrupalRegex(self): + regex = unalias("drupal6-testpackage", "DRUPAL-DEFAULT", "regex") + self.assertEqual( + regex, + "(?s)Recommended releases.*?>6.x-([^<]*)" + ) + + regex = unalias("drupal7-testpackage", "DRUPAL-DEFAULT", "regex") + self.assertEqual( + regex, + "(?s)Recommended releases.*?>7.x-([^<]*)" + ) + + def testDrupalUrl(self): + url = unalias("drupal6-testpkg", "DRUPAL-DEFAULT", "url") + self.assertEqual( + url, + "http://drupal.org/project/testpkg" + ) + + def testPHPPear(self): + url = unalias("php-pear-Test-Case", "PEAR-DEFAULT", "url") + self.assertEqual( + url, + "http://pear.php.net/package/Test_Case/download" + ) + + +if __name__ == "__main__": + suite = unittest.TestLoader().loadTestsFromTestCase(AliasTest) + unittest.TextTestRunner(verbosity=2).run(suite) + #unittest.main() |