187 lines
6.6 KiB
Diff
187 lines
6.6 KiB
Diff
|
From 0999f890e57e45b0124fe1ddf1c368e63bd5c5c4 Mon Sep 17 00:00:00 2001
|
||
|
From: Jaroslav Rohel <jrohel@redhat.com>
|
||
|
Date: Thu, 2 May 2019 14:08:06 +0200
|
||
|
Subject: [PATCH] Unit tests for reintroduced hawkey.Repo
|
||
|
|
||
|
---
|
||
|
python/hawkey/tests/module/__init__.py | 2 ++
|
||
|
python/hawkey/tests/module/hawkey_testmodule.cpp | 16 ++++++++++++++++
|
||
|
python/hawkey/tests/tests/base.py | 8 +++++++-
|
||
|
python/hawkey/tests/tests/test_repo.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
|
||
|
python/hawkey/tests/tests/test_sack.py | 17 ++++++++++++++++-
|
||
|
5 files changed, 90 insertions(+), 2 deletions(-)
|
||
|
create mode 100644 python/hawkey/tests/tests/test_repo.py
|
||
|
|
||
|
diff --git a/python/hawkey/tests/module/__init__.py b/python/hawkey/tests/module/__init__.py
|
||
|
index b41c3cc..b2ccd3d 100644
|
||
|
--- a/python/hawkey/tests/module/__init__.py
|
||
|
+++ b/python/hawkey/tests/module/__init__.py
|
||
|
@@ -32,6 +32,8 @@ FIXED_ARCH = _hawkey_test.FIXED_ARCH
|
||
|
UNITTEST_DIR = _hawkey_test.UNITTEST_DIR
|
||
|
YUM_DIR_SUFFIX = _hawkey_test.YUM_DIR_SUFFIX
|
||
|
|
||
|
+glob_for_repofiles = _hawkey_test.glob_for_repofiles
|
||
|
+
|
||
|
class TestSackMixin(object):
|
||
|
def __init__(self, repo_dir):
|
||
|
self.repo_dir = repo_dir
|
||
|
diff --git a/python/hawkey/tests/module/hawkey_testmodule.cpp b/python/hawkey/tests/module/hawkey_testmodule.cpp
|
||
|
index b705701..9b21ad2 100644
|
||
|
--- a/python/hawkey/tests/module/hawkey_testmodule.cpp
|
||
|
+++ b/python/hawkey/tests/module/hawkey_testmodule.cpp
|
||
|
@@ -23,6 +23,7 @@
|
||
|
// hawkey
|
||
|
#include "dnf-sack-private.hpp"
|
||
|
|
||
|
+#include "python/hawkey/repo-py.hpp"
|
||
|
#include "python/hawkey/sack-py.hpp"
|
||
|
#include "tests/hawkey/testshared.h"
|
||
|
|
||
|
@@ -53,9 +54,24 @@ py_load_repo(PyObject *unused, PyObject *args)
|
||
|
Py_RETURN_NONE;
|
||
|
}
|
||
|
|
||
|
+static PyObject *
|
||
|
+py_glob_for_repofiles(PyObject *unused, PyObject *args)
|
||
|
+{
|
||
|
+ const char *repo_name, *path;
|
||
|
+ DnfSack *sack;
|
||
|
+
|
||
|
+ if (!PyArg_ParseTuple(args, "O&ss",
|
||
|
+ sack_converter, &sack, &repo_name, &path))
|
||
|
+ return NULL;
|
||
|
+ HyRepo repo = glob_for_repofiles(dnf_sack_get_pool(sack), repo_name, path);
|
||
|
+ return repoToPyObject(repo);
|
||
|
+}
|
||
|
+
|
||
|
static struct PyMethodDef testmodule_methods[] = {
|
||
|
{"load_repo", (PyCFunction)py_load_repo,
|
||
|
METH_VARARGS, NULL},
|
||
|
+ {"glob_for_repofiles", (PyCFunction)py_glob_for_repofiles,
|
||
|
+ METH_VARARGS, NULL},
|
||
|
{NULL} /* sentinel */
|
||
|
};
|
||
|
|
||
|
diff --git a/python/hawkey/tests/tests/base.py b/python/hawkey/tests/tests/base.py
|
||
|
index 8f1c1af..4d5937b 100644
|
||
|
--- a/python/hawkey/tests/tests/base.py
|
||
|
+++ b/python/hawkey/tests/tests/base.py
|
||
|
@@ -1,5 +1,5 @@
|
||
|
#
|
||
|
-# Copyright (C) 2012-2013 Red Hat, Inc.
|
||
|
+# Copyright (C) 2012-2019 Red Hat, Inc.
|
||
|
#
|
||
|
# Licensed under the GNU Lesser General Public License Version 2.1
|
||
|
#
|
||
|
@@ -72,6 +72,12 @@ class TestSack(hawkey.test.TestSackMixin, hawkey.Sack):
|
||
|
repo.load()
|
||
|
super(TestSack, self).load_repo(repo, **kwargs)
|
||
|
|
||
|
+ # Loading using hawkey.Repo
|
||
|
+ def load_repo_hawkey_Repo(self, **kwargs):
|
||
|
+ d = os.path.join(self.repo_dir, hawkey.test.YUM_DIR_SUFFIX)
|
||
|
+ repo = hawkey.test.glob_for_repofiles(self, "messerk", d)
|
||
|
+ super(TestSack, self).load_repo(repo, **kwargs)
|
||
|
+
|
||
|
def by_name(sack, name):
|
||
|
return hawkey.Query(sack).filter(name=name)[0]
|
||
|
|
||
|
diff --git a/python/hawkey/tests/tests/test_repo.py b/python/hawkey/tests/tests/test_repo.py
|
||
|
new file mode 100644
|
||
|
index 0000000..8ae0544
|
||
|
--- /dev/null
|
||
|
+++ b/python/hawkey/tests/tests/test_repo.py
|
||
|
@@ -0,0 +1,49 @@
|
||
|
+#
|
||
|
+# Copyright (C) 2012-2019 Red Hat, Inc.
|
||
|
+#
|
||
|
+# Licensed under the GNU Lesser General Public License Version 2.1
|
||
|
+#
|
||
|
+# This library is free software; you can redistribute it and/or
|
||
|
+# modify it under the terms of the GNU Lesser General Public
|
||
|
+# License as published by the Free Software Foundation; either
|
||
|
+# version 2.1 of the License, or (at your option) any later version.
|
||
|
+#
|
||
|
+# This library is distributed in the hope that it will be useful,
|
||
|
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
+# Lesser General Public License for more details.
|
||
|
+#
|
||
|
+# You should have received a copy of the GNU Lesser General Public
|
||
|
+# License along with this library; if not, write to the Free Software
|
||
|
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||
|
+#
|
||
|
+
|
||
|
+import hawkey
|
||
|
+import unittest
|
||
|
+
|
||
|
+
|
||
|
+class Package(unittest.TestCase):
|
||
|
+ def test_create(self):
|
||
|
+ r = hawkey.Repo("fog")
|
||
|
+ self.assertIsNotNone(r)
|
||
|
+ self.assertRaises(TypeError, hawkey.Repo);
|
||
|
+ self.assertRaises(TypeError, hawkey.Repo, 3)
|
||
|
+ self.assertRaises(TypeError, hawkey.Repo, rain="pouring")
|
||
|
+
|
||
|
+ def test_cost_assignment(self):
|
||
|
+ r = hawkey.Repo("fog")
|
||
|
+ r.cost = 300
|
||
|
+ self.assertEqual(300, r.cost)
|
||
|
+
|
||
|
+ r2 = hawkey.Repo("blizzard")
|
||
|
+ self.assertEqual(1000, r2.cost)
|
||
|
+ with self.assertRaises(TypeError):
|
||
|
+ r2.cost = '4'
|
||
|
+
|
||
|
+ def test_str_assignment(self):
|
||
|
+ r = hawkey.Repo('fog')
|
||
|
+ with self.assertRaises(TypeError):
|
||
|
+ r.repomd_fn = 3
|
||
|
+ r.repomd_fn = 'rain'
|
||
|
+ self.assertEqual(r.repomd_fn, 'rain')
|
||
|
+
|
||
|
diff --git a/python/hawkey/tests/tests/test_sack.py b/python/hawkey/tests/tests/test_sack.py
|
||
|
index fe36b86..4645b37 100644
|
||
|
--- a/python/hawkey/tests/tests/test_sack.py
|
||
|
+++ b/python/hawkey/tests/tests/test_sack.py
|
||
|
@@ -1,5 +1,5 @@
|
||
|
#
|
||
|
-# Copyright (C) 2012-2015 Red Hat, Inc.
|
||
|
+# Copyright (C) 2012-2019 Red Hat, Inc.
|
||
|
#
|
||
|
# Licensed under the GNU Lesser General Public License Version 2.1
|
||
|
#
|
||
|
@@ -48,6 +48,14 @@ class TestSackTest(base.TestCase):
|
||
|
self.assertEqual(len(sack), hawkey.test.EXPECT_YUM_NSOLVABLES +
|
||
|
hawkey.test.EXPECT_SYSTEM_NSOLVABLES)
|
||
|
|
||
|
+ # Loading test using hawkey.Repo
|
||
|
+ def test_load_yum_hawkey_Repo(self):
|
||
|
+ sack = base.TestSack(repo_dir=self.repo_dir)
|
||
|
+ sack.load_system_repo()
|
||
|
+ sack.load_repo_hawkey_Repo(build_cache=True)
|
||
|
+ self.assertEqual(len(sack), hawkey.test.EXPECT_YUM_NSOLVABLES +
|
||
|
+ hawkey.test.EXPECT_SYSTEM_NSOLVABLES)
|
||
|
+
|
||
|
def test_cache_dir(self):
|
||
|
sack = base.TestSack(repo_dir=self.repo_dir)
|
||
|
self.assertTrue(sack.cache_dir.startswith("/tmp/pyhawkey"))
|
||
|
@@ -77,6 +85,13 @@ class BasicTest(unittest.TestCase):
|
||
|
self.assertRaises(IOError, sack.load_repo, repo)
|
||
|
sack = hawkey.Sack()
|
||
|
|
||
|
+ # Loading test using hawkey.Repo
|
||
|
+ def test_failed_load_hawkey_Repo(self):
|
||
|
+ sack = hawkey.Sack(cachedir=base.cachedir)
|
||
|
+ repo = hawkey.Repo("name")
|
||
|
+ self.assertRaises(IOError, sack.load_repo, repo)
|
||
|
+ sack = hawkey.Sack()
|
||
|
+
|
||
|
def test_unicoded_cachedir(self):
|
||
|
# does not raise UnicodeEncodeError
|
||
|
hawkey.Sack(cachedir=u"unicod\xe9")
|
||
|
--
|
||
|
libgit2 0.27.7
|
||
|
|