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

Deleted tests

Testler başıma bela oldu
üst 0ad272e3
repos/*-bin/
repos/repo1/
repos/repo2/
repos/repo1-bin/
repos/repo2-bin/
repos/tmp/
inary-index.xml*
tests/
Inary UnitTests
##############
Before running unittests you need to first go to repos directory and
create test repositories.
>>> test@sulin tests/repos# python3 createrepos.py
Now you can return to tests folder and run tests.
>>> test@sulin tests # python3 runtests.py
# -*- 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 unittest
from . import testcase
class ComponentDBTestCase(testcase.TestCase):
def setUp(self):
testcase.TestCase.setUp(self)
self.componentdb = inary.db.componentdb.ComponentDB()
def testHasComponent(self):
assert self.componentdb.has_component("system.base", "repo1")
assert not self.componentdb.has_component("floct.flict", "repo1")
assert self.componentdb.has_component("applications.network", "repo2")
assert not self.componentdb.has_component("floct.flict", "repo2")
assert self.componentdb.has_component("applications.util")
def testListComponents(self):
assert set(self.componentdb.list_components("repo1")) == set(["system", "system.base",
"applications"])
assert set(self.componentdb.list_components("repo2")) == set(["applications", "applications.util",
"applications.network"])
assert set(self.componentdb.list_components()) == set(["system", "system.base",
"applications", "applications.network",
"applications.util"])
def testGetComponent(self):
component = self.componentdb.get_component("applications.network")
assert component.name == "applications.network"
assert "ncftp" in component.packages
assert "lynx" not in component.packages
component = self.componentdb.get_component("applications.network", "repo2")
assert component.name == "applications.network"
assert "lynx" in component.packages
assert "ncftp" not in component.packages
def testGetUnionComponent(self):
component = self.componentdb.get_union_component("applications.network")
assert component.name == "applications.network"
assert "lynx" in component.packages
assert "ncftp" in component.packages
def testGetPackages(self):
packages = self.componentdb.get_packages("applications.network")
assert "ncftp" in packages
assert "lynx" not in packages
packages = self.componentdb.get_packages("applications.network", "repo2")
assert "lynx" in packages
assert "ncftp" not in packages
packages = self.componentdb.get_packages("applications", "repo2", walk = True)
assert "cpulimit" and "lynx" in packages
assert "ncftp" not in packages
def testGetUnionPackages(self):
packages = self.componentdb.get_union_packages("applications.network")
assert "ncftp" in packages
assert "lynx" in packages
assert "cpulimit" not in packages
packages = self.componentdb.get_union_packages("applications", walk = True)
assert "ncftp" and "lynx" and "cpulimit" in packages
def testSearchComponent(self):
packages = self.componentdb.search_component(["applic"])
assert set(packages) == set(['applications', 'applications.network', 'applications.util'])
packages = self.componentdb.search_component(["system", "base"], repo="repo1")
assert set(packages) == set(["system.base"])
packages = self.componentdb.search_component(["system", "base"], repo="repo2")
assert not 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):
assert not self.filesdb.has_file("usr/bin/ethtool")
inary.api.install(["ethtool"])
assert self.filesdb.has_file("usr/bin/ethtool")
inary.api.remove(["ethtool"])
assert not self.filesdb.has_file("usr/bin/ethtool")
def testGetFile(self):
inary.api.install(["ethtool"])
pkg, path = self.filesdb.get_file("usr/bin/ethtool")
assert pkg == "ethtool"
assert path == "usr/bin/ethtool"
inary.api.remove(["ethtool"])
assert not self.filesdb.has_file("usr/bin/ethtool")
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)
assert not self.filesdb.has_file("etc/inary/inary.conf")
assert not self.filesdb.has_file("etc/inary/mirrors.conf")
self.filesdb.add_files("inary", files)
assert self.filesdb.has_file("etc/inary/inary.conf")
assert self.filesdb.has_file("etc/inary/mirrors.conf")
pkg, path = self.filesdb.get_file("etc/inary/inary.conf")
assert pkg == "inary"
# FIXME: inconsistency in filesdb.py add_remove and remove_remove parameters
self.filesdb.remove_files(files.list)
assert not self.filesdb.has_file("etc/inary/inary.conf")
assert not self.filesdb.has_file("etc/inary/mirrors.conf")
def testSearchFile(self):
assert not self.filesdb.search_file("ethtool")
inary.api.install(["ethtool"])
found = self.filesdb.search_file("ethtool")
# -*- 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 InstallDBTestCase(testcase.TestCase):
def setUp(self):
testcase.TestCase.setUp(self)
self.installdb = inary.db.installdb.InstallDB()
def tearDown(self):
inary.api.remove(["ctorrent", "ethtool"])
def testGetPackage(self):
inary.api.install(["ethtool"])
idb = inary.db.installdb.InstallDB()
pkg = idb.get_package("ethtool")
assert type(pkg) == inary.metadata.Package
assert pkg.name == "ethtool"
def testHasPackage(self):
inary.api.install(["ethtool"])
self.installdb = inary.db.installdb.InstallDB()
assert not self.installdb.has_package("flipfloo")
assert self.installdb.has_package("ethtool")
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',
'curl', 'bash', 'ethtool'])
def testGetVersion(self):
inary.api.install(["ethtool"])
self.installdb = inary.db.installdb.InstallDB()
version, release, build = self.installdb.get_version("zlib")
assert version == "0.3"
assert release == "1"
assert build == None
def testGetFiles(self):
inary.api.install(["ethtool"])
self.installdb = inary.db.installdb.InstallDB()
files = self.installdb.get_files("ethtool")
assert files.list[0].path == "usr/bin/ethtool"
def testGetInfo(self):
inary.api.install(["ethtool"])
idb = inary.db.installdb.InstallDB()
info = idb.get_info("ethtool")
self.assertTrue(isinstance(info, inary.db.installdb.InstallInfo))
self.assertEqual(info.version, "0.3")
def testGetReverseDependencies(self):
inary.api.install(["ethtool"])
inary.api.install(["ctorrent"])
self.installdb = inary.db.installdb.InstallDB()
revdeps = self.installdb.get_rev_deps("openssl")
assert set(["ctorrent", "curl"]) == set(map(lambda x:x[0], revdeps))
def testAddRemovePackage(self):
inary.api.install(["ctorrent"])
self.installdb = inary.db.installdb.InstallDB()
assert self.installdb.has_package("ctorrent")
assert not self.installdb.has_package("ethtool")
inary.api.install(["ethtool"])
self.installdb = inary.db.installdb.InstallDB()
assert self.installdb.has_package("ctorrent")
assert self.installdb.has_package("ethtool")
def testMarkListPending(self):
inary.api.set_scom(False)
assert not self.installdb.has_package("ethtool")
inary.api.install(["ethtool"])
assert "ethtool" in self.installdb.list_pending()
inary.api.remove(["ethtool"])
assert "ethtool" not in self.installdb.list_pending()
inary.api.set_scom(True)
def testClearPending(self):
inary.api.set_scom(False)
assert not self.installdb.has_package("ethtool")
inary.api.install(["ethtool"])
assert "ethtool" in self.installdb.list_pending()
self.installdb.clear_pending("ethtool")
assert "ethtool" not in self.installdb.list_pending()
inary.api.remove(["ethtool"])
assert "ethtool" not in self.installdb.list_pending()
inary.api.set_scom(True)
def testSearchPackage(self):
self.installdb = inary.db.installdb.InstallDB()
assert not self.installdb.has_package("ethtool")
assert not self.installdb.search_package(["ethtool"])
inary.api.install(["ethtool"])
self.installdb = inary.db.installdb.InstallDB()
assert self.installdb.search_package(["et", "tool", "h"]) == ["ethtool"]
# -*- 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):
assert self.testdb.tdb.has_repo("repo1")
assert self.testdb.tdb.has_repo("repo2")
assert not self.testdb.tdb.has_repo("hedehodo")
def testHasItem(self):
assert self.testdb.tdb.has_item("kdiff3", "repo2")
assert not self.testdb.tdb.has_item("kdiff3", "repo1")
assert self.testdb.tdb.has_item("acpica")
def testWhichRepo(self):
assert self.testdb.tdb.which_repo("aggdraw") == "repo1"
assert self.testdb.tdb.which_repo("kmess") == "repo2"
def testGetItemAndRepository(self):
pkg, repo = self.testdb.tdb.get_item_repo("acpica")
assert pkg == "package acpica"
assert repo == "repo1"
pkg, repo = self.testdb.tdb.get_item_repo("kmess")
assert pkg == "package kmess"
assert repo == "repo2"
def testItemRepos(self):
db = inary.db.itembyrepo.ItemByRepo({})
assert db.item_repos("caracal") == ["caracal"]
# repos were created by testcase.py
assert db.item_repos() == ['repo1', 'repo2', 'repo1-src']
def testGetItem(self):
assert self.testdb.tdb.get_item("acpica") == "package acpica"
assert self.testdb.tdb.get_item("kmess") == "package kmess"
def testGetItemOfRepository(self):
assert self.testdb.tdb.get_item("acpica", "repo1") == "package acpica"
assert self.testdb.tdb.get_item("kmess", "repo2") == "package kmess"
def testGetItemKeys(self):
assert set(self.testdb.tdb.get_item_keys("repo1")) == set(["aggdraw", "acpica"])
assert set(self.testdb.tdb.get_item_keys("repo2")) == set(["kdiff3", "kmess"])
assert set(self.testdb.tdb.get_item_keys()) == set(["kdiff3", "kmess", "aggdraw", "acpica"])
def testGetListItem(self):
assert set(self.testdb.odb.get_list_item("repo1")) == set(['rar', 'wengophone'])
assert set(self.testdb.odb.get_list_item("repo2")) == set(['xara'])
assert 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("ncftp", "repo1")
assert pkg.name == "ncftp"
pkg = self.packagedb.get_package("lynx", "repo2")
assert pkg.name == "lynx"
pkg = self.packagedb.get_package("cpulimit")
assert pkg.name == "cpulimit"
def testHasPackage(self):
assert self.packagedb.has_package("ncftp", "repo1")
assert not self.packagedb.has_package("ncftp", "repo2")
assert self.packagedb.has_package("lynx")
def testGetVersion(self):
version, release, build = self.packagedb.get_version("lynx", "repo2")
assert version == "0.3"
assert release == "1"
def testWhichRepo(self):
assert self.packagedb.which_repo("lynx") == "repo2"
def testGetPackageAndRepository(self):
pkg, repo = self.packagedb.get_package_repo("cpulimit")
assert pkg.name == "cpulimit"
assert repo == "repo2"
def testGetObsoletes(self):
assert set(self.packagedb.get_obsoletes("repo1")) == set(["wengophone", "rar"])
assert set(self.packagedb.get_obsoletes("repo2")) == set(["xara"])
assert set(self.packagedb.get_obsoletes()) == set(["wengophone", "rar", "xara"])
def testGetReverseDependencies(self):
pkg, dep = self.packagedb.get_rev_deps("openssl")[0]
assert pkg == "curl"
assert str(dep) == "openssl"
def testGetReplaces(self):
# FIXME: update createrepo.py to generate replaces
assert not self.packagedb.get_replaces()
def testListPackages(self):
assert set(self.packagedb.list_packages("repo1")) == set(['nfdump', 'ethtool', 'ncftp',
'libidn', 'zlib', 'db4', 'openssl',
'jpeg', 'pam', 'shadow', 'bogofilter',
'curl', 'gsl', 'bash', 'cracklib'])
assert set(self.packagedb.list_packages("repo2")) == set(['libpcap', 'ctorrent', 'lft', 'lynx',
'iat', 'cpulimit', 'rpl'])
def testSearchPackage(self):
packages = self.packagedb.search_package(["bogo", "filter"])
packages = ["bogofilter"]
packages = self.packagedb.search_package(["cpu", "limit"], repo="repo2")
packages = ["cpulimit"]
# -*- 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):
assert "repo2-src" not in self.repodb.list_repos()
repo = inary.db.repodb.Repo(inary.uri.URI("repos/repo2/inary-index.xml"))
self.repodb.add_repo("repo2-src", repo)
assert "repo2-src" in self.repodb.list_repos()
self.repodb.remove_repo("repo2-src")
assert "repo2" in self.repodb.list_repos()
assert "repo1" in self.repodb.list_repos()
assert "repo2-src" not in self.repodb.list_repos()
def testAddRemoveCycle(self):
for r in range(30):
assert "test-repo" not in 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)
assert "test-repo" in self.repodb.list_repos()
self.repodb.remove_repo("test-repo")
assert "test-repo" not in self.repodb.list_repos()
def testListRepos(self):
assert set(self.repodb.list_repos()) == set(['repo1', 'repo2', 'repo1-src'])
def testGetSourceRepos(self):
assert set(self.repodb.get_source_repos()) == set(['repo1-src'])
def testGetBinaryRepos(self):
assert set(self.repodb.get_binary_repos()) == set(['repo1', 'repo2'])
def testGetRepo(self):
repo = self.repodb.get_repo("repo1")
uri = repo.indexuri
assert uri.get_uri() == "repos/repo1-bin/inary-index.xml"
def testRepoOrder(self):
repoorder = inary.db.repodb.RepoOrder()
assert repoorder.get_order() == ['repo1', 'repo2', 'repo1-src']
repoorder.add("test-repo", "http://test-repo/inary-index.xml")
assert repoorder.get_order() == ['repo1', 'repo2', 'repo1-src', 'test-repo']
repoorder.remove("test-repo")
assert repoorder.get_order() == ['repo1', 'repo2', 'repo1-src']
# -*- 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, database = True)
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):
assert set(self.sourcedb.list_sources()) == set(['ethtool', 'nfdump', 'shadow', 'libidn',
'zlib', 'db4', 'openssl', 'jpeg', 'gsl',
'curl', 'bogofilter', 'ncftp', 'pam',
'bash', 'cracklib'])
def testHasSpec(self):
assert self.sourcedb.has_spec("ethtool")
assert not self.sourcedb.has_spec("hedehodo")
def testGetSpec(self):
spec = self.sourcedb.get_spec("ethtool")
assert spec.source.name == "ethtool"
assert spec.source.partOf == "applications.network"
def testGetSpecOfRepository(self):
spec = self.sourcedb.get_spec("ethtool", "repo1-src")