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

yeni testler eklendi

Bu testler database için geliştrilmiş önceki testlerin revizesidir.
üst 8f19869b
# -*- 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.
#
# -*- 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 inary
import inary.db
import unittest
from . import testcase
class ComponentDBTestCase(testcase.TestCase):
def setUp(self):
testcase.TestCase.setUp(self)
self.componentdb = inary.db.componentdb.ComponentDB()
def testHasComponent(self):
self.assertTrue(self.componentdb.has_component("system.base", "core-binary"))
self.assertFalse(self.componentdb.has_component("floct.flict", "core-binary"))
self.assertTrue(self.componentdb.has_component("multimedia.graphics", "core-src"))
self.assertFalse(self.componentdb.has_component("floct.flict", "core-src"))
self.assertTrue(self.componentdb.has_component("programming.language.python"))
def testListComponents(self):
self.assertEqual(set(self.componentdb.list_components(repo="core-binary")),set(['util.shell', 'programming.environment.kdevelop',
'programming.environment.eclipse', 'system.devel',
'util.archive', 'programming.tool', 'office.docbook',
'multimedia', 'desktop', 'util.admin', 'x11',
'x11.library', 'programming.devel', 'util',
'util.crypt', 'hardware.disk', 'system.boot',
'hardware', 'system.pages', 'system.locale',
'tex.base', 'x11.util', 'office', 'system',
'desktop.font', 'system.base', 'programming.library',
'programming.environment.eric', 'tex',
'programming', 'programming.language.python',
'programming.environment', 'util.misc',
'multimedia.graphics', 'system.doc',
'programming.language', 'programming.docs']))
if set(["applications", "applications.util", "applications.network"]) not in set(self.componentdb.list_components()):
assert True
else:
assert False
def testGetComponent(self):
component = self.componentdb.get_component("system.base")
self.assertEqual(component.name, "system.base")
self.assertIn("expat", component.packages)
self.assertNotIn("expat-devel", component.packages)
component = self.componentdb.get_component("util.admin", repo="core-binary")
self.assertEqual(component.name,"util.admin")
self.assertIn("libcap-ng-utils", component.packages)
self.assertNotIn("ncftp", component.packages)
def testGetUnionComponent(self):
component = self.componentdb.get_union_component("system.locale")
self.assertEqual(component.name, "system.locale")
self.assertIn("glibc-locales-so", component.packages)
self.assertNotIn("minizip", component.packages)
def testGetPackages(self):
packages = self.componentdb.get_packages("system.devel")
self.assertIn("expat-devel", packages)
self.assertNotIn("expat", packages)
packages = self.componentdb.get_packages("util.misc", repo="core-binary")
self.assertIn("uuidd", packages)
self.assertNotIn( "ncftp", packages)
packages = self.componentdb.get_packages("system.pages", walk = True)
self.assertIn("autoconf-pages" and "autoconf-pages",packages)
def testGetSources(self):
packages = self.componentdb.get_sources("system.devel")
self.assertIn("isl", packages)
self.assertNotIn( "ncftp", packages)
packages = self.componentdb.get_sources("system.devel", repo="core-binary")
self.assertEqual([], packages)
packages = self.componentdb.get_packages("system.devel", walk = True)
self.assertIn("ppl" and "expat-devel", packages)
def testGetUnionPackages(self):
packages = self.componentdb.get_union_packages("programming.devel")
self.assertIn('device-mapper-event-devel',packages)
self.assertNotIn( "ncftp", packages)
packages = self.componentdb.get_union_packages("system.pages", walk = True)
assert "autoconf-pages" and "autoconf-pages" in packages
def testSearchComponent(self):
packages = self.componentdb.search_component(["yst"])
self.assertIn('system.base', set(packages))
self.assertNotIn('programming', set(packages))
packages = self.componentdb.search_component(["doc"], repo="core-binary")
self.assertIn("system.doc", packages)
packages = self.componentdb.search_component(["til", "isc"], repo="core-binary")
self.assertIn("util.misc", packages)
# -*- 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 inary
import inary.context as ctx
import unittest
from . import testcase
class FilesDBTestCase(testcase.TestCase):
filesdb = inary.db.filesdb.FilesDB()
def testHasFile(self):
self.assertFalse(self.filesdb.has_file("etc/protocols"))
inary.api.install(["iana-etc"])
self.assertTrue(self.filesdb.has_file("etc/protocols"))
self.assertTrue(self.filesdb.has_file("etc/services"))
inary.api.remove(["iana-etc"])
self.assertFalse(self.filesdb.has_file("etc/protocols"))
def testGetFile(self):
inary.api.install(["iana-etc"])
pkg, path = self.filesdb.get_file("etc/protocols")
self.assertEqual(pkg, "iana-etc")
self.assertEqual(path, "etc/protocols")
inary.api.remove(["iana-etc"])
self.assertFalse(self.filesdb.has_file("etc/protocols"))
def testAddRemoveFiles(self):
fileinfo1 = inary.data.files.FileInfo()
fileinfo1.path = "etc/inary/inary.conf"
fileinfo2 = inary.data.files.FileInfo()
fileinfo2.path = "etc/inary/mirrors.conf"
files = inary.data.files.Files()
files.list.append(fileinfo1)
files.list.append(fileinfo2)
self.assertFalse(self.filesdb.has_file("etc/inary/inary.conf"))
self.assertFalse(self.filesdb.has_file("etc/inary/mirrors.conf"))
self.filesdb.add_files("inary", files)
self.assertTrue(self.filesdb.has_file("etc/inary/inary.conf"))
self.assertTrue(self.filesdb.has_file("etc/inary/mirrors.conf"))
pkg, path = self.filesdb.get_file("etc/inary/inary.conf")
self.assertEqual(pkg, "inary")
# FIXME: inconsistency in filesdb.py add_remove and remove_remove parameters
self.filesdb.remove_files(files.list)
self.assertFalse(self.filesdb.has_file("etc/inary/inary.conf"))
self.assertFalse(self.filesdb.has_file("etc/inary/mirrors.conf"))
def testSearchFile(self):
self.assertFalse(self.filesdb.search_file("protocols"))
inary.api.install(["iana-etc"])
self.assertTrue(self.filesdb.search_file("protocols"))
inary.api.remove(["iana-etc"])
# -*- 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 inary
import inary.data
import inary.db
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):
inary.api.remove(["timezone", "time", "acl", "attr"])
def testGetPackage(self):
inary.api.install(["timezone"])
idb = inary.db.installdb.InstallDB()
pkg = idb.get_package("timezone")
self.assertEqual(type(pkg), inary.data.metadata.Package)
self.assertEqual(pkg.name, "timezone")
def testHasPackage(self):
inary.api.install(["timezone"])
self.installdb = inary.db.installdb.InstallDB()
self.assertFalse(self.installdb.has_package("flipfloo"))
self.assertTrue(self.installdb.has_package("timezone"))
def testListInstalled(self):
inary.api.install(["timezone", "time"])
self.installdb = inary.db.installdb.InstallDB()
self.assertEqual(set(self.installdb.list_installed()), set(["timezone", "time"]))
def testGetVersion(self):
inary.api.install(["timezone"])
self.installdb = inary.db.installdb.InstallDB()
version, release, build = self.installdb.get_version("timezone")
self.assertEqual(version, "2018e")
self.assertEqual(release, "1")
self.assertEqual(build, None)
def testGetFiles(self):
inary.api.install(["timezone"])
self.installdb = inary.db.installdb.InstallDB()
files = self.installdb.get_files("timezone")
self.assertIn("usr/share/zoneinfo/Portugal", [x.path for x in files.list])
self.assertNotIn("usr/bin", [x.path for x in files.list])
def testGetInfo(self):
inary.api.install(["timezone"])
idb = inary.db.installdb.InstallDB()
info = idb.get_info("timezone")
self.assertTrue(isinstance(info, inary.db.installdb.InstallInfo))
self.assertEqual(info.version, "2018e")
def testGetReverseDependencies(self):
inary.api.install(["acl"])
self.installdb = inary.db.installdb.InstallDB()
revdeps = self.installdb.get_rev_deps("acl")
self.assertIn(set(["attr"]), set(map(lambda x:x[0], revdeps)))
def testAddRemovePackage(self):
inary.api.install(["time"])
self.installdb = inary.db.installdb.InstallDB()
self.assertTrue(self.installdb.has_package("time"))
self.assertFalse(self.installdb.has_package("timezone"))
inary.api.install(["timezone"])
self.installdb = inary.db.installdb.InstallDB()
self.assertTrue(self.installdb.has_package("time"))
self.assertTrue(self.installdb.has_package("timezone"))
def testMarkListPending(self):
self.skipTest(reason="")
def testClearPending(self):
self.skipTest(reason="")
def testSearchPackage(self):
self.installdb = inary.db.installdb.InstallDB()
self.assertFalse(self.installdb.has_package("timezone"))
self.assertFalse(self.installdb.search_package(["timezone"]))
inary.api.install(["timezone"])
self.installdb = inary.db.installdb.InstallDB()
self.assertEqual(self.installdb.search_package(["t", "ime", "zone"]), ["timezone"])
# -*- 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 unittest
from . import testcase
import inary.db.itembyrepo
class TestDB:
def __init__(self):
self.packages = {}
self.obsoletes = {}
self.packages["repo1"] = {"aggdraw":"package aggdraw",
"acpica":"package acpica"}
self.packages["repo2"] = {"kdiff3":"package kdiff3",
"kmess":"package kmess"}
self.obsoletes["repo1"] = ["wengophone", "rar"]
self.obsoletes["repo2"] = ["xara"]
self.tdb = inary.db.itembyrepo.ItemByRepo(self.packages)
self.odb = inary.db.itembyrepo.ItemByRepo(self.obsoletes)
# original item_repos in ItemByRepo uses repodb.list_repos
def item_repos(repo=None):
repos = ["repo1", "repo2"]
if repo:
repos = [repo]
return repos
self.tdb.item_repos = item_repos
self.odb.item_repos = item_repos
class ItemByRepoTestCase(testcase.TestCase):
testdb = TestDB()
def testHasRepository(self):
self.assertTrue(self.testdb.tdb.has_repo("repo1"))
self.assertTrue(self.testdb.tdb.has_repo("repo2"))
self.assertFalse(self.testdb.tdb.has_repo("hedehodo"))
def testHasItem(self):
self.assertTrue(self.testdb.tdb.has_item("kdiff3", "repo2"))
self.assertFalse(self.testdb.tdb.has_item("kdiff3", "repo1"))
self.assertTrue(self.testdb.tdb.has_item("acpica"))
def testWhichRepo(self):
self.assertEqual(self.testdb.tdb.which_repo("aggdraw"), "repo1")
self.assertEqual(self.testdb.tdb.which_repo("kmess"), "repo2")
def testGetItemAndRepository(self):
pkg, repo = self.testdb.tdb.get_item_repo("acpica")
self.assertEqual(pkg, "package acpica")
self.assertEqual(repo, "repo1")
pkg, repo = self.testdb.tdb.get_item_repo("kmess")
self.assertEqual(pkg, "package kmess")
self.assertEqual(repo, "repo2")
def testItemRepos(self):
db = inary.db.itembyrepo.ItemByRepo({})
self.assertEqual(db.item_repos("caracal"), ["caracal"])
# repos were created by testcase.py
self.assertEqual(db.item_repos(), ['core-src', 'core-binary'])
def testGetItem(self):
self.assertEqual(self.testdb.tdb.get_item("acpica"), "package acpica")
self.assertEqual(self.testdb.tdb.get_item("kmess"), "package kmess")
def testGetItemOfRepository(self):
self.assertEqual(self.testdb.tdb.get_item("acpica", "repo1"), "package acpica")
self.assertEqual(self.testdb.tdb.get_item("kmess", "repo2"), "package kmess")
def testGetItemKeys(self):
self.assertEqual(set(self.testdb.tdb.get_item_keys("repo1")), set(["aggdraw", "acpica"]))
self.assertEqual(set(self.testdb.tdb.get_item_keys("repo2")), set(["kdiff3", "kmess"]))
self.assertEqual(set(self.testdb.tdb.get_item_keys()), set(["kdiff3", "kmess", "aggdraw", "acpica"]))
def testGetListItem(self):
self.assertEqual(set(self.testdb.odb.get_list_item("repo1")), set(['rar', 'wengophone']))
self.assertEqual(set(self.testdb.odb.get_list_item("repo2")), set(['xara']))
self.assertEqual(set(self.testdb.odb.get_list_item()), set(['rar', 'xara', 'wengophone']))
# -*- 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 unittest
from . import testcase
import inary.db.lazydb as lazydb
class TestDB(lazydb.LazyDB):
def init(self):
self.testfield = True
def getTestField(self):
return self.testfield
class LazyDBTestCase(testcase.TestCase):
def testDatabaseMethodForcingInit(self):
db = TestDB()
assert db.getTestField()
assert "testfield" in db.__dict__
db._delete()
def testDatabaseWithoutInit(self):
db = TestDB()
assert not "testfield" in db.__dict__
db._delete()
def testSingletonBehaviour(self):
db = TestDB()
db2 = TestDB()
assert id(db) == id(db2)
# -*- 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 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):
pkg = self.packagedb.get_package("bash", "core-binary")
self.assertEqual(pkg.name, "bash")
pkg = self.packagedb.get_package("grep", "core-src")
self.assertEqual(pkg.name, "grep")
pkg = self.packagedb.get_package("expat")
self.assertEqual(pkg.name, "expat")
def testHasPackage(self):
self.assertTrue(self.packagedb.has_package("tar", "core-binary"))
self.assertFalse(self.packagedb.has_package("tar", "core-src"))
self.assertTrue(self.packagedb.has_package("zlib"))
def testGetVersion(self):
version, release, build = self.packagedb.get_version("bash", "core-binary")
self.assertEqual(version, "5.0")
self.assertEqual(release, "1")
def testWhichRepo(self):
self.assertEqual(self.packagedb.which_repo("bash"), "core-binary")
def testGetPackageAndRepository(self):
pkg, repo = self.packagedb.get_package_repo("gcc")
self.assertEqual(pkg.name, "gcc")
self.assertEqual(repo, "core-binary")
def testGetObsoletes(self):
self.assertEqual(self.packagedb.get_obsoletes(), [])
def testGetReverseDependencies(self):
pkg, dep = self.packagedb.get_rev_deps("bash")[0]
assert pkg == "bash-dbginfo"
assert str(dep) == "bash release 1"
def testGetReplaces(self):
# FIXME: update createrepo.py to generate replaces
assert not self.packagedb.get_replaces()
def testListPackages(self):
self.assertIn("expat", self.packagedb.list_packages("core-binary"))
def testSearchPackage(self):
packages = self.packagedb.search_package(["osd","doc"])
self.assertIn('biosdevname-docs', packages)
packages = self.packagedb.search_package(["32bit","bus"],repo="core-binary")
self.assertIn('dbus-32bit', packages)
# -*- 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 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):
self.assertNotIn("repo2-src", self.repodb.list_repos())
repo = inary.db.repodb.Repo(inary.uri.URI("repos/repo2/inary-index.xml"))
self.repodb.add_repo("repo2-src", repo)
self.assertIn("repo2-src",self.repodb.list_repos())
self.repodb.remove_repo("repo2-src")
self.assertIn("core-src", self.repodb.list_repos())
self.assertIn("core-binary", self.repodb.list_repos())
self.assertNotIn("repo2-src", self.repodb.list_repos())
def testAddRemoveCycle(self):
for r in range(30):
self.assertNotIn("test-repo",self.repodb.list_repos())
repo = inary.db.repodb.Repo(inary.uri.URI("http://test-repo/inary-index.xml"))
self.repodb.add_repo("test-repo", repo)
self.assertIn("test-repo", self.repodb.list_repos())
self.repodb.remove_repo("test-repo")
self.assertNotIn("test-repo", self.repodb.list_repos())
def testListRepos(self):
self.assertEqual(set(self.repodb.list_repos()), set(['core-src', 'core-binary']))
def testGetSourceRepos(self):
self.assertEqual(set(self.repodb.get_source_repos()), set(['core-src']))
def testGetBinaryRepos(self):
self.assertEqual(set(self.repodb.get_binary_repos()), set(['core-binary']))
def testGetRepo(self):
repo = self.repodb.get_repo("core-src")
uri = repo.indexuri
self.assertEqual(uri.get_uri(), "http://127.0.0.1/SulinRepository/inary-index.xml")
def testRepoOrder(self):
repoorder = inary.db.repodb.RepoOrder()
self.assertEqual(repoorder.get_order(), ['core-src', 'core-binary'])
repoorder.add("test-repo", "http://test-repo/inary-index.xml")
self.assertEqual(repoorder.get_order(), ['core-src', 'core-binary', 'test-repo'])
repoorder.remove("test-repo")
self.assertEqual(repoorder.get_order(), ['core-src', 'core-binary'])
# -*- 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 3 of the License, or (at your
# option) any later version.
#
# Please read the COPYING file.
#
import unittest
from . import testcase
import os
import inary.operations.search
import inary.db as db
class SearchTestCase(testcase.TestCase):
def setUp(self):
testcase.TestCase.setUp(self)
def testSearch(self):
doc1 = "A set object is an unordered collection of immutable values."
doc2 = "Being an unordered collection, sets do not record element position or order of insertion."
doc3 = "There are currently two builtin set types, set and frozenset"
inary.search.init(['test'], ['en'])
inary.search.add_doc('test', 'en', 1, doc1, repo = db.itembyrepo.installed)
inary.search.add_doc('test', 'en', 2, doc2, repo = db.itembyrepo.installed)
inary.search.add_doc('test', 'en', 3, doc3, repo = db.itembyrepo.installed)
q1 = inary.search.query('test', 'en', ['set'], repo = db.itembyrepo.alldb)
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()
# -*- 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 unittest
from . import testcase
import inary
class SourceDBTestCase(testcase.TestCase):
def setUp(self):
testcase.TestCase.setUp(self)
self.sourcedb = inary.db.sourcedb.SourceDB()
def testListSources(self):
self.skipTest(reason="")
def testHasSpec(self):
assert self.sourcedb.has_spec("openssl")
assert not self.sourcedb.has_spec("hedehodo")
def testGetSpec(self):
spec = self.sourcedb.get_spec("zlib")
assert spec.source.name == "zlib"
assert spec.source.partOf == "system.base"
def testGetSpecOfRepository(self):
spec = self.sourcedb.get_spec("xz", "core-src")
assert spec.source.name == "xz"
assert spec.source.partOf == "system.base"
def testGetSpecAndRepository(self):
spec, repo = self.sourcedb.get_spec_repo("openssl")
assert spec.source.name == "openssl"
assert spec.source.partOf == "system.base"
assert repo == "core-src"
def testGetSourceFromPackage(self):
pkg = self.sourcedb.pkgtosrc("xz")
assert pkg == "xz"
def testSearchPackage(self):
packages = self.sourcedb.search_spec(["open", "ssl"])
assert set(["openssl"]) == set(packages)
packages = self.sourcedb.search_spec(["xorg", "util"], repo="core-src")
assert set(["xorg-util"]) == set(packages)
import unittest
import inary
import inary.context as ctx
import inary.db.repodb
import inary.operations.repository as repository
class TestCase(unittest.TestCase):
def setUp(self):
options = inary.config.Options()
options.destdir = 'tests/tmp_root'
inary.api.set_options(options)
inary.api.set_scom(False)