From 38fa9b57572c32d5def84cf1f5158c9e19dc574c Mon Sep 17 00:00:00 2001 From: xiaozai Date: Wed, 11 Dec 2024 10:27:23 +0800 Subject: [PATCH] Add unittest module for querylayerinlocal --- test/__init__.py | 1 + test/test_querylayerinlocal.py | 48 ++++++++++++++++------------------ 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/test/__init__.py b/test/__init__.py index d768790..bbc6177 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -29,6 +29,7 @@ from test_isocheck import TestIsoCheck from test_localcheck import TestLocalCheck from test_repocheck import TestRepoCheck from test_util import TestUtil +from test_querylayerinlocal import TestQueryLayerInLocal if __name__ == "__main__": diff --git a/test/test_querylayerinlocal.py b/test/test_querylayerinlocal.py index 85cc217..a5de30e 100644 --- a/test/test_querylayerinlocal.py +++ b/test/test_querylayerinlocal.py @@ -13,7 +13,7 @@ # See the Mulan PSL v2 for more details. # ********************************************************************************** """ - +import os import unittest from src.rpmquery.querylayerinlocal import QueryLayerInLocal @@ -22,49 +22,45 @@ class TestQueryLayerInLocal(unittest.TestCase): def setUp(self): self._rpm = '/opt/kyclassifier/test.rpm' - self.isinit = True if self._init_querylayeriniso() else False + self.isinit = True if self._init_querylayerinlocal() else False - def _init_querylayeriniso(self): + def _init_querylayerinlocal(self): """ Try to init querylayerinlocal object Returns: bool """ try: - self.obj = QueryLayerInLocal(self._rpm,self._rpm) + self.obj = QueryLayerInLocal(self._rpm) return True except: return False + + def test_run(self): + if os.path.exists(self._rpm) is False: + self.skipTest("Test File not exists, test_check skiped!") + result = QueryLayerInLocal.run([self.obj.rpm]) + self.assertIsInstance(result, int, "Test QueryLayerInLocal.run failed!") - def test_get_rpm_layer(self): - pass - - def test_get_rpmdeps(self): - pass - def test_get_localpkgs_layer(self): - """ - Test class QueryLayerInLocal method _get_localpkgs_layer() - Returns: - dict - """ - if not self.isinit: - self.skipTest("QueryLayerInIso obj init failed,_get_localpkgs_layer test skiped!") - result = self.obj._get_localpkgs_laye() - self.assertIsInstance(result,dict,"_get_localpkgs_layer test failed!") - - def test_get_isofiles(self): - pass + def test_get_rpm_layer(self): + if self.isinit is False: + self.skipTest("Test initialize for QueryLayerInLocal unfinished, test_get_rpm_layer skiped!") + layer = self.obj.get_rpm_layer() + self.assertIsInstance(layer,int,"QueryLayerInLocal.get_rpm_layer check failed!") + def test_check(self): - pass + if os.path.exists(self._rpm) is False: + self.skipTest("Test File not exists, test_check skiped!") + result = QueryLayerInLocal.check(self.obj.rpm) + self.assertIsInstance(result,bool,"Test QueryLayerInLocal.check failed!") + def test_rpm(self): pass - def test_iso(self): - pass if __name__ == '__main__': - unittest.main(verbosity=2) \ No newline at end of file + unittest.main(verbosity=2) -- Gitee