From 19517387f3a2b18fd349ca342469a9d125e4d0d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Metin?= Date: Tue, 14 Jun 2005 09:47:14 +0000 Subject: [PATCH] =?UTF-8?q?unittest=20yap=C4=B1m=C4=B1z...=20Haz=C4=B1rlad?= =?UTF-8?q?=C4=B1=C4=9F=C4=B1n=C4=B1z=20mod=C3=BCller/fonksiyonlar=20i?= =?UTF-8?q?=C3=A7in=20unittestleri=20de=20yazmay=C4=B1=20ihmal=20etmeyiniz?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit samples/ altına testlerde de örnek olarak kullanacağımız dosyaları yerleştireceğiz. Bu dosyaların da (örneğin; spec dosyaları) güncel olmasına önem gösterelim... --- src/samples/popt.pspec | 60 ++++++++++++++++++++++++++++++++++ src/unittests/archivetests.py | 33 +++++++++++++++++++ src/unittests/fetchertests.py | 25 ++++++++++++++ src/unittests/run.py | 21 ++++++++++++ src/unittests/specfiletests.py | 23 +++++++++++++ 5 files changed, 162 insertions(+) create mode 100644 src/samples/popt.pspec create mode 100644 src/unittests/archivetests.py create mode 100644 src/unittests/fetchertests.py create mode 100755 src/unittests/run.py create mode 100644 src/unittests/specfiletests.py diff --git a/src/samples/popt.pspec b/src/samples/popt.pspec new file mode 100644 index 00000000..411dee3e --- /dev/null +++ b/src/samples/popt.pspec @@ -0,0 +1,60 @@ + + + + + + + + popt + http://www.rpm.org/ + + Kirmizi kafalar + hotmail@redhat.com + + As-Is + + ftp://ftp.rpm.org/pub/rpm/dist/rpm-4.1.x/popt-1.7.tar.gz + + + popt-1.7-uclibc.patch.gz + + + make + + + + 05/05/2005 + 1.7 + 1 + + + + + + popt + Command line option parsing library + Komut satırı seçenekleri işleme kütüphanesi + Command line option parsing library. + While it is similiar to getopt(3), it contains a number of enhancements, including: + + 1) popt is fully reentrant + 2) popt can parse arbitrary argv[] style arrays while + getopt(2) makes this quite difficult + 3) popt allows users to alias command line arguments + 4) popt provides convience functions for parsing strings + into argv[] style arrays + + devel:library + + gettext + + + /usr/lib + /usr/share/doc + /usr/share/man + /usr/share/locale + /usr/include/popt.h + + + diff --git a/src/unittests/archivetests.py b/src/unittests/archivetests.py new file mode 100644 index 00000000..94a270d7 --- /dev/null +++ b/src/unittests/archivetests.py @@ -0,0 +1,33 @@ + +import unittest +from os.path import exists as pathexists + +from pisi import archive +from pisi import specfile +from pisi import util + +class ArchiveFileTestCase(unittest.TestCase): + def setUp(self): + self.spec = specfile.SpecFile() + self.spec.read("samples/popt.pspec") + + self.achv = archive.Archive(self.spec.source.archiveType, + self.spec.source.archiveName) + + def testUnpackTar(self): + assert self.spec.source.archiveType == "targz" + + # unpacking is trivial with Archive() + self.achv.unpack() + + # but testing is hard + assert pathexists("popt-1.7") + + testfile = "popt-1.7/Makefile.am" + assert pathexists(testfile) + + self.assertEqual(util.md5_file(testfile), + "171545adab7b51ebf6ec5575d3000a95") + +suite = unittest.makeSuite(ArchiveFileTestCase) + diff --git a/src/unittests/fetchertests.py b/src/unittests/fetchertests.py new file mode 100644 index 00000000..5b586c93 --- /dev/null +++ b/src/unittests/fetchertests.py @@ -0,0 +1,25 @@ + +import unittest +import os + +from pisi import fetcher +from pisi import specfile +from pisi import util + +class FetcherTestCase(unittest.TestCase): + def setUp(self): + self.spec = specfile.SpecFile() + self.spec.read("samples/popt.pspec") + + self.fetch = fetcher.Fetcher(self.spec.source.archiveUri, + self.spec.source.archiveName) + + def testFetch(self): + self.fetch.fetch() + destpath = self.fetch.filedest + "/" + self.fetch.filename + if os.access(destpath, os.R_OK): + self.assertEqual(util.md5_file(destpath), + self.spec.source.archiveMD5) + + +suite = unittest.makeSuite(FetcherTestCase) diff --git a/src/unittests/run.py b/src/unittests/run.py new file mode 100755 index 00000000..10cf8699 --- /dev/null +++ b/src/unittests/run.py @@ -0,0 +1,21 @@ +#!/usr/bin/python + +import unittest +import sys +sys.path.append(".") + +import specfiletests +import fetchertests +import archivetests + +def main(): + alltests = unittest.TestSuite(( + specfiletests.suite, + fetchertests.suite, + archivetests.suite + )) + + unittest.TextTestRunner(verbosity=2).run(alltests) + +if __name__ == "__main__": + main() diff --git a/src/unittests/specfiletests.py b/src/unittests/specfiletests.py new file mode 100644 index 00000000..3fd0de42 --- /dev/null +++ b/src/unittests/specfiletests.py @@ -0,0 +1,23 @@ + +import unittest + +from pisi import specfile + +class SpecReadTestCase(unittest.TestCase): + def setUp(self): + self.spec = specfile.SpecFile() + self.spec.read("samples/popt.pspec") + + def testSourceName(self): + self.assertEqual(self.spec.source.name, + "popt") + + def testMD5Sum(self): + self.assertEqual(self.spec.source.archiveMD5, + "5988e7aeb0ae4dac8d83561265984cc9") + + def testLenPackages(self): + self.assertEqual(len(self.spec.packages), 1) + + +suite = unittest.makeSuite(SpecReadTestCase)