unittest yapımız...

Hazırladığınız modüller/fonksiyonlar için unittestleri de yazmayı ihmal etmeyiniz.

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...
This commit is contained in:
Barış Metin
2005-06-14 09:47:14 +00:00
parent c459e36796
commit 19517387f3
5 changed files with 162 additions and 0 deletions
+60
View File
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE PSPEC SYSTEM
"http://www.uludag.org.tr/projeler/pisi/pisi-spec.dtd">
<PSPEC>
<Source>
<Name>popt</Name>
<Homepage>http://www.rpm.org/</Homepage>
<Packager>
<Name>Kirmizi kafalar</Name>
<Email>hotmail@redhat.com</Email>
</Packager>
<License>As-Is</License>
<Archive archType="targz" md5sum="5988e7aeb0ae4dac8d83561265984cc9">
ftp://ftp.rpm.org/pub/rpm/dist/rpm-4.1.x/popt-1.7.tar.gz
</Archive>
<Patches>
<Patch compressionType="gz">popt-1.7-uclibc.patch.gz</Patch>
</Patches>
<BuildDependencies>
<Dependency versionFrom="1.8"> make </Dependency>
</BuildDependencies>
<History>
<Update>
<Date>05/05/2005</Date>
<Version>1.7</Version>
<Release>1</Release>
</Update>
</History>
</Source>
<Package>
<Name>popt</Name>
<Summary lang="en">Command line option parsing library</Summary>
<Summary lang="tr">Komut satırı seçenekleri işleme kütüphanesi</Summary>
<Description>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
</Description>
<Category>devel:library</Category>
<RuntimeDependencies>
<Dependency>gettext</Dependency>
</RuntimeDependencies>
<Files>
<Path fileType="sharedLib">/usr/lib</Path>
<Path fileType="doc">/usr/share/doc</Path>
<Path fileType="doc">/usr/share/man</Path>
<Path fileType="localedata">/usr/share/locale</Path>
<Path fileType="header">/usr/include/popt.h</Path>
</Files>
</Package>
</PSPEC>
+33
View File
@@ -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)
+25
View File
@@ -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)
+21
View File
@@ -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()
+23
View File
@@ -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)