Kaydet (Commit) 24ea419d authored tarafından Suleyman Poyraz's avatar Suleyman Poyraz

Test dosyaları düzenlendi, runTests.py portage testlerinden örnek alınarak düzenlendi.

üst 30ac20ef
repos/*-bin/
repos/repo1/
repos/repo2/
repos/repo1-bin/
repos/repo2-bin/
repos/tmp/
inary-index.xml*
tests/
......@@ -10,8 +10,10 @@
# Please read the COPYING file.
#
from . import testcase
import inary
import unittest
from . import testcase
class ComponentDBTestCase(testcase.TestCase):
......@@ -84,4 +86,5 @@ class ComponentDBTestCase(testcase.TestCase):
assert set(packages) == set(["system.base"])
packages = self.componentdb.search_component(["system", "base"], repo="repo2")
assert not packages
......@@ -10,8 +10,10 @@
# Please read the COPYING file.
#
from . import testcase
import inary
import unittest
from . import testcase
class FilesDBTestCase(testcase.TestCase):
......
......@@ -10,13 +10,16 @@
# Please read the COPYING file.
#
from . import testcase
import inary
import unittest
from . import testcase
class InstallDBTestCase(testcase.TestCase):
def setUp(self):
testcase.TestCase.setUp(self)
self.installdb = inary.db.installdb.InstallDB()
def tearDown(self):
......@@ -38,9 +41,9 @@ class InstallDBTestCase(testcase.TestCase):
def testListInstalled(self):
inary.api.install(["ethtool"])
self.installdb = inary.db.installdb.InstallDB()
assert set(self.installdb.list_installed()) == set(['zlib', 'pam', 'shadow',
'jpeg', 'libidn', 'db4',
'cracklib', 'openssl',
assert set(self.installdb.list_installed()) == set(['zlib', 'pam', 'shadow',
'jpeg', 'libidn', 'db4',
'cracklib', 'openssl',
'curl', 'bash', 'ethtool'])
def testGetVersion(self):
......
......@@ -10,6 +10,8 @@
# Please read the COPYING file.
#
import unittest
from . import testcase
import inary.db.itembyrepo
......
......@@ -11,6 +11,7 @@
#
import unittest
from . import testcase
import inary.db.lazydb as lazydb
class TestDB(lazydb.LazyDB):
......@@ -21,7 +22,7 @@ class TestDB(lazydb.LazyDB):
def getTestField(self):
return self.testfield
class LazyDBTestCase(unittest.TestCase):
class LazyDBTestCase(testcase.TestCase):
def testDatabaseMethodForcingInit(self):
db = TestDB()
......@@ -38,3 +39,4 @@ class LazyDBTestCase(unittest.TestCase):
db = TestDB()
db2 = TestDB()
assert id(db) == id(db2)
......@@ -10,14 +10,16 @@
# Please read the COPYING file.
#
from . import testcase
import unittest
from . import testcase
import inary
class PackageDBTestCase(testcase.TestCase):
def setUp(self):
testcase.TestCase.setUp(self)
self.packagedb = inary.db.packagedb.PackageDB()
def testGetPackage(self):
......
......@@ -10,13 +10,16 @@
# Please read the COPYING file.
#
from . import testcase
import inary
import unittest
from . import testcase
class RepoDBTestCase(testcase.TestCase):
def setUp(self):
testcase.TestCase.setUp(self)
self.repodb = inary.db.repodb.RepoDB()
def testAddRemoveRepo(self):
......@@ -46,6 +49,7 @@ class RepoDBTestCase(testcase.TestCase):
assert set(self.repodb.get_source_repos()) == set(['repo1-src'])
def testGetBinaryRepos(self):
print(self.repodb.get_binary_repos())
assert set(self.repodb.get_binary_repos()) == set(['repo1', 'repo2'])
def testGetRepo(self):
......
......@@ -10,11 +10,12 @@
#
import unittest
from . import testcase
import os
import inary.search
import inary.operations.search
import inary.db as db
from . import testcase
class SearchTestCase(testcase.TestCase):
def setUp(self):
......@@ -31,4 +32,4 @@ class SearchTestCase(testcase.TestCase):
self.assertEqual(q1, set([1,3]))
q2 = inary.search.query('test', 'en', ['an', 'collection'], repo = db.itembyrepo.alldb)
self.assertEqual(q2, set([1,2]))
inary.search.finalize() suite = unittest.makeSuite(SearchTestCase)
inary.search.finalize()
......@@ -10,15 +10,15 @@
# Please read the COPYING file.
#
from . import testcase
import unittest
from . import testcase
import inary
class SourceDBTestCase(testcase.TestCase):
def setUp(self):
testcase.TestCase.setUp(self)
self.sourcedb = inary.db.sourcedb.SourceDB()
......
import unittest
import inary
import inary.context as ctx
......@@ -18,6 +17,6 @@ class TestCase(unittest.TestCase):
inary.api.add_repo("repo1", "repos/repo1-bin/inary-index.xml")
inary.api.add_repo("repo2", "repos/repo2-bin/inary-index.xml")
inary.api.add_repo("repo1-src", "repos/repo1/inary-index.xml")
inary.api.update_repo("repo1")
inary.api.update_repo("repo2")
inary.api.update_repo("repo1-src")
inary.api.update_repo("repo1")
inary.api.update_repo("repo2")
inary.api.update_repo("repo1-src")
......@@ -31,5 +31,3 @@ class FileTestCase(unittest.TestCase):
f = File('http://www.sulin.org.tr/Releases/2018/roadmap.html', File.read)
r = f.readlines()
assert (len(r) > 0)
......@@ -50,3 +50,4 @@ class ConfigFileTestCase(unittest.TestCase):
assert not cf.build.configurationlevel
assert cf.dirs.qt_dir
assert not cf.dirs.cache_dir
......@@ -12,4 +12,3 @@ class ConstantTestCase(unittest.TestCase):
if hasattr(constants,i):
value = getattr(constants,i)
self.assertEqual(value, constDict[i])
......@@ -30,6 +30,3 @@ class FetchTestCase(unittest.TestCase):
enc = base64.encodestring('{0}:{0}'.format(self.url.auth_info()))
self.assertEqual(self.fetch._get_http_headers(),(('Authorization', 'Basic {}'.format(enc)),))
assert not self.fetch._get_ftp_headers()
......@@ -38,4 +38,3 @@ class UriTestCase(unittest.TestCase):
uri4 = uri.URI()
uri4.set_uri('/usr/share/aclocal')
assert 'aclocal' == uri4.filename()
......@@ -16,4 +16,3 @@ class FilesTestCase(unittest.TestCase):
def testFiles(self):
self.files = inary.data.files.Files()
self.files.read('repos/repo1/system/base/bash/pspec.xml')
......@@ -22,6 +22,3 @@ class MetadataTestCase(unittest.TestCase):
def testWrite(self):
md = self.testRead()
md.write("repos/tmp/metadata-write.xml")
......@@ -40,4 +40,3 @@ class PackageTestCase(unittest.TestCase):
pkg.extract_inary.data.files("002_remove.xml")
if os.path.exists("002_remove.xml"):
self.fail("Inary files extract error")
......@@ -19,14 +19,14 @@ class RelationTestCase(unittest.TestCase):
relation.versionFrom = "8"
assert not inary.data.relation.installed_package_satisfies(relation)
relation.versionFrom = None
#Test versionTo = X
relation.versionTo = "8"
assert inary.data.relation.installed_package_satisfies(relation)
relation.versionTo = "0.1"
assert not inary.data.relation.installed_package_satisfies(relation)
relation.versionTo = None
#Test release = X
relation.release = "3"
assert not inary.data.relation.installed_package_satisfies(relation)
......@@ -49,4 +49,3 @@ class RelationTestCase(unittest.TestCase):
relation.releaseTo = None
inary.api.remove(["ethtool"])
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2018, Suleyman POYRAZ (Zaryob)
#
# 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.
#
# Please read the COPYING file.
#
import argparse
import sys
import time
import shutil
import unittest
from unittest import _TextTestResult
import inary
import inary.context as ctx
import inary.util as util
import os
def importTest(name):
mod = __import__(name)
components = name.split('.')
for comp in components[1:]:
mod = getattr(mod, comp)
return mod
def getTests(path, base_path, files=''):
if not files:
files = os.listdir(path)
files = [f[:-3] for f in files if f.startswith("test") and f.endswith(".py")]
files.sort()
parent_path = path[len(base_path)+1:]
parent_module = parent_path.replace('/', '.')
result = []
for mymodule in files:
modname = ".".join((parent_module, mymodule))
mod = importTest(modname)
result.append(unittest.TestLoader().loadTestsFromModule(mod))
return result
class TextTestResult(_TextTestResult):
def __init__(self, stream, descriptions, verbosity):
super(TextTestResult, self).__init__(stream, descriptions, verbosity)
self.todoed = []
def addTodo(self, test, info):
self.todoed.append((test, info))
if self.showAll:
self.stream.writeln("TODO")
elif self.dots:
self.stream.write(".")
def printErrors(self):
if self.dots or self.showAll:
self.stream.writeln()
self.printErrorList(util.colorize('ERROR','red'), self.errors)
self.printErrorList(util.colorize('FAIL', 'blue'), self.failures)
self.printErrorList(util.colorize('TODO', 'purple'),self.todoed)
class InaryTestRunner(unittest.TextTestRunner):
def Result(self):
return TextTestResult(self.stream, self.descriptions, self.verbosity)
def run(self, Test, retresult=True):
"""
Run the given test case or test suite.
"""
result = self.Result()
startTime = time.time()
Test(result)
stopTime = time.time()
timeTaken = stopTime - startTime
if retresult==True:
result.printErrors()
self.stream.writeln(result.separator2)
run = result.testsRun
self.stream.write(util.colorize("\n\n====== COMPLATE TESTS =======\n" ,'yellow'))
self.stream.writeln(util.colorize(" * Runned %d test%s in %.3fs" %
(run, run != 1 and "s" or "", timeTaken),'blue'))
self.stream.writeln()
if not result.wasSuccessful():
failed = len(result.failures)
errored = len(result.errors)
todoed = len(result.todoed)
success = run - (failed + errored + todoed)
self.stream.write(util.colorize(" => %d Successed\n" % success, 'green'))
if failed:
self.stream.write(util.colorize("\n => %d Failures\n" % failed, 'red'))
if errored:
self.stream.write(util.colorize("\n => %d Errored\n" % errored, 'red'))
if todoed:
self.stream.write(util.colorize("\n => %d ToDo |" % todoed, 'yellow'))
else:
self.stream.writeln("Tests End Succesfull...")
return result
def main():
suite = unittest.TestSuite()
basedir = os.path.dirname(os.path.realpath(__file__))
usage = "usage: %s [options] [tests to run]" % os.path.basename(sys.argv[0])
parser = argparse.ArgumentParser(usage=usage)
parser.add_argument("-v", "--verbose", action="store_true",
help="Print detailed log.", default="False",
dest="verbose_print")
options, args = parser.parse_known_args(args=sys.argv)
if len(args) > 1:
result = []
for arg in args:
realpath = os.path.realpath(arg)
path = os.path.dirname(realpath)
f = realpath[len(path)+1:]
if not f.startswith("test") or not f.endswith(".py"):
raise Exception("Invalid argument: '%s'" % arg)
mymodule = f[:-3]
result.extend(getTests(path, basedir, [mymodule]))
suite.addTests(result)
else:
testfile = '__test__.py'
testDirs = []
for root, dirs, files in os.walk(basedir):
if testfile in files:
testDirs.append(root)
testDirs.sort()
for mydir in testDirs:
suite.addTests(getTests(os.path.join(basedir, mydir), basedir))
verbosity=1
if options.verbose_print==True:
verbosity=2
result = InaryTestRunner(verbosity=verbosity).run(suite, retresult=options.verbose_print)
def setup():
options = inary.config.Options()
options.destdir = 'repos/tmp'
inary.api.set_options(options)
inary.api.set_scom(False)
ctx.config.values.general.distribution = "Sulin"
ctx.config.values.general.distribution_release = "2018"
if __name__ == '__main__':
if os.path.exists("repos/tmp"):
shutil.rmtree("repos/tmp")
setup()
main()
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2018, Suleyman POYRAZ (Zaryob)
#
# 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.
#
# Please read the COPYING file.
#
import os
import unittest
import inary
import inary.context as ctx
#Database tests
from databaseTests.testRepoDB import RepoDBTestCase
from databaseTests.testPackageDB import PackageDBTestCase
from databaseTests.testSourceDB import SourceDBTestCase
from databaseTests.testInstallDB import InstallDBTestCase
from databaseTests.testComponentDB import ComponentDBTestCase
from databaseTests.testFilesLDB import FilesDBTestCase
from databaseTests.testLazyDB import LazyDBTestCase
from databaseTests.testItembyRepo import ItemByRepoTestCase
#Package Tests
from packageTests.testConflict import ConflictTestCase
from packageTests.testDependency import DependencyTestCase
from packageTests.testFiles import FilesTestCase
from packageTests.testHistory import HistoryTestCase
from packageTests.testMetadata import MetadataTestCase
from packageTests.testPackage import PackageTestCase
from packageTests.testPspec import SpecFileTestCase
from packageTests.testRelations import RelationTestCase
from packageTests.testReplace import ReplaceTestCase
#File Tests
from fileTests.testArchive import ArchiveTestCase
from fileTests.testFile import FileTestCase
from fileTests.testSrcArchive import SourceArchiveTestCase
#Inary Tests
from inaryTests.testConstants import ConstantTestCase
from inaryTests.testConfigFile import ConfigFileTestCase
from inaryTests.testFetcher import FetchTestCase
from inaryTests.testMirrors import MirrorsTestCase
from inaryTests.testShell import ShellTestCase
from inaryTests.testUri import UriTestCase
from inaryTests.testUtil import UtilTestCase
from inaryTests.testVersion import VersionTestCase
#Type Tests
from typeTests.testOO import OOTestCase
from typeTests.testPgraph import GraphTestCase
# XML tests
from xmlTests.testAutoxml import AutoXmlTestCase
def setup():
options = inary.config.Options()
options.destdir = 'repos/tmp'
inary.api.set_options(options)
inary.api.set_scom(False)
ctx.config.values.general.distribution = "Sulin"
ctx.config.values.general.distribution_release = "2018"
if __name__ == '__main__':
if os.path.exists("repos/tmp"):
import shutil
shutil.rmtree("repos/tmp")
suite = unittest.TestSuite()
unittest.main()
......@@ -57,6 +57,3 @@ class OOTestCase(unittest.TestCase):
a1 = A()
a2 = A()
self.assert_(a1 is a2)
suite = unittest.makeSuite(OOTestCase)
......@@ -95,7 +95,3 @@ class LocalTextTestCase(unittest.TestCase):
def testStr(self):
s = bytes(self.a)
self.assert_(s!= None and len(s)>=6)
suite1 = unittest.makeSuite(AutoXmlTestCase)
suite2 = unittest.makeSuite(LocalTextTestCase)
suite = unittest.TestSuite((suite1, suite2))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment