aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMykyta Holubakha <hilobakho@gmail.com>2017-06-09 03:28:34 +0300
committerMykyta Holubakha <hilobakho@gmail.com>2017-06-09 03:28:34 +0300
commit7bbe65901f12b2b63e4c690e0ba6ad66ee833e7f (patch)
tree88689b2dd482992ba04818201afcf61cc6aec272 /tests
parentActually return Result.Ok when a package is found (diff)
downloadpomu-7bbe65901f12b2b63e4c690e0ba6ad66ee833e7f.tar.gz
pomu-7bbe65901f12b2b63e4c690e0ba6ad66ee833e7f.tar.bz2
pomu-7bbe65901f12b2b63e4c690e0ba6ad66ee833e7f.zip
Numerous fixes all over the tree
Added dispatcher and repository package (un)installation tests
Diffstat (limited to 'tests')
-rw-r--r--tests/test_dispatch.py73
-rw-r--r--tests/test_init.py1
2 files changed, 60 insertions, 14 deletions
diff --git a/tests/test_dispatch.py b/tests/test_dispatch.py
index c851c0a..7ccf830 100644
--- a/tests/test_dispatch.py
+++ b/tests/test_dispatch.py
@@ -1,28 +1,75 @@
+import shutil
import unittest
+
from os import path
from tempfile import mkdtemp
-import pomu.source
from pomu.package import Package
-from pomu.repo.repo import pomu_status, portage_repos, portage_active_repo
+from pomu.repo.init import init_plain_repo
+from pomu.repo.repo import Repository
+from pomu.source import dispatcher
from pomu.util.result import Result
@dispatcher.source
class DummySource():
- def __init__(self, _path):
- self.path = _path
-
@dispatcher.handler
- def parse(self, uri):
- return Result.Ok(uri)
+ @classmethod
+ def parse(cls, uri):
+ if uri.startswith('/'):
+ return Result.Ok(uri[1:])
+ return Result.Err()
+
+ @classmethod
+ def fetch_package(cls, uri):
+ return Package('test', cls.path)
+
+class DispatcherTests(unittest.TestCase):
+ def setUp(self):
+ self.source_path = mkdtemp()
+ with path.join(self.source_path, 'test.ebuild') as f:
+ f.write('# Copytight 1999-2017\nAll Rights Reserved\nEAPI="0"\n')
+ DummySource.path = self.source_path
- def fetch_package(self, uri):
- return Package('test', self.path)
+ def testDispatch(self):
+ self.assertEqual(dispatcher.get_package_source('/test').unwrap(), 'test')
+ self.assertTrue(dispatcher.get_package_source('test').is_err())
-class InstallTests(unittests.TestCase):
+ def testFetch(self):
+ pkg = dispatcher.get_package('/test').unwrap()
+ self.assertEqual(pkg.files, [('', 'test.ebuild')])
+ def tearDown(self):
+ shutil.rmtree(self.source_path)
+
+class InstallTests(unittest.TestCase):
def setUp(self):
- source_path = mkdtemp()
- with path.join(source_path, 'test.ebuild') as f:
+ self.source_path = mkdtemp()
+ with path.join(self.source_path, 'test.ebuild') as f:
f.write('# Copytight 1999-2017\nAll Rights Reserved\nEAPI="0"\n')
- self.source = DummySource(source_path)
+ DummySource.path = self.source_path
+
+ self.repo_dir = mkdtemp()
+ shutil.rmtree(self.repo_dir)
+ init_plain_repo(True, self.repo_dir).expect()
+ self.repo = Repository(self.repo_dir)
+
+ def tearDown(self):
+ shutil.rmtree(self.repo_dir)
+
+ def testPkgCreate(self):
+ pkg = Package('test', self.source_path, files=['test.ebuild'])
+ self.assertEqual(pkg.files, [('', 'test.ebuild')])
+
+ def testPkgMerge(self):
+ pkg = Package('test', self.source_path)
+ self.repo.merge(pkg).expect()
+
+ def testPkgUnmerge(self):
+ pkg = Package('test', self.source_path)
+ self.repo.merge(pkg).expect()
+ with self.subTest(i=0):
+ self.repo.unmerge(pkg).expect()
+ with self.subTest(i=1):
+ self.repo.remove_package('test').expect()
+ with self.subTest(i=2):
+ self.repo.remove_package('tset').expect_err()
diff --git a/tests/test_init.py b/tests/test_init.py
index 8341bce..5f0bd2d 100644
--- a/tests/test_init.py
+++ b/tests/test_init.py
@@ -7,7 +7,6 @@ import portage
from pomu.repo.init import init_plain_repo, init_pomu, init_portage_repo
from pomu.repo.repo import pomu_status, portage_repos, pomu_active_repo
-from pomu.util.result import Result
REPO_DIR = 'test_repo'
REPO_PATH = os.path.join(os.getcwd(), REPO_DIR)