diff options
author | 2017-06-09 03:28:34 +0300 | |
---|---|---|
committer | 2017-06-09 03:28:34 +0300 | |
commit | 7bbe65901f12b2b63e4c690e0ba6ad66ee833e7f (patch) | |
tree | 88689b2dd482992ba04818201afcf61cc6aec272 | |
parent | Actually return Result.Ok when a package is found (diff) | |
download | pomu-7bbe65901f12b2b63e4c690e0ba6ad66ee833e7f.tar.gz pomu-7bbe65901f12b2b63e4c690e0ba6ad66ee833e7f.tar.bz2 pomu-7bbe65901f12b2b63e4c690e0ba6ad66ee833e7f.zip |
Numerous fixes all over the tree
Added dispatcher and repository package (un)installation tests
-rw-r--r-- | pomu/package.py | 8 | ||||
-rw-r--r-- | pomu/repo/repo.py | 8 | ||||
-rw-r--r-- | pomu/source/manager.py | 1 | ||||
-rw-r--r-- | pomu/util/fs.py | 2 | ||||
-rw-r--r-- | tests/test_dispatch.py | 73 | ||||
-rw-r--r-- | tests/test_init.py | 1 |
6 files changed, 69 insertions, 24 deletions
diff --git a/pomu/package.py b/pomu/package.py index 24fdf00..470d76b 100644 --- a/pomu/package.py +++ b/pomu/package.py @@ -4,7 +4,7 @@ A package can be installed into a repository. A package is supposed to be created by a package source from a set of files. """ -from os import path +from os import path, walk from pomu.util.fs import strip_prefix @@ -36,13 +36,13 @@ class Package(): def strip_root(self, d_path): # the path should be either relative, or a child of root if d_path.startswith('/'): - if path.commonprefix(d_path, root) != root: + if path.commonprefix(d_path, self.root) != self.root: raise ValueError('Path should be a subdirectory of root') - return strip_prefix(strip_prefix(d_path, root), '/') + return strip_prefix(strip_prefix(d_path, self.root), '/') return d_path def read_path(self, d_path): - for wd, dirs, files in os.walk(d_path): + for wd, dirs, files in walk(d_path): wd = self.strip_root(wd) self.files.extend([(wd, f) for f in files]) diff --git a/pomu/repo/repo.py b/pomu/repo/repo.py index a30eaab..c907db3 100644 --- a/pomu/repo/repo.py +++ b/pomu/repo/repo.py @@ -13,13 +13,11 @@ class Repository(): raise ValueError('This path is not a valid pomu repository') self.root = root - repo = property() - @repo.getter + @property def repo(self): return Repo(repo_path) - pomu_dir = property() - @pomu_dir.getter + @property def pomu_dir(self): return path.join(self.root, 'metadata/pomu') @@ -34,7 +32,7 @@ class Repository(): f.write('{}/{}'.format(wd, f)) r.index.add(path.join(self.pomu_dir, package.name)) r.index.commit('Merged package ' + package.name) - return Result.Ok('Merged package ' + package.name ' successfully') + return Result.Ok('Merged package ' + package.name + ' successfully') def unmerge(self, package): r = self.repo diff --git a/pomu/source/manager.py b/pomu/source/manager.py index 7f34679..a887956 100644 --- a/pomu/source/manager.py +++ b/pomu/source/manager.py @@ -29,6 +29,7 @@ Example: #import bisect import inspect +from pomu.repo.repo import pomu_active_repo from pomu.util.result import Result class PackageDispatcher(): diff --git a/pomu/util/fs.py b/pomu/util/fs.py index f5f448c..3e69e2e 100644 --- a/pomu/util/fs.py +++ b/pomu/util/fs.py @@ -7,7 +7,7 @@ def strip_prefix(string, prefix): """Returns a string, stripped from its prefix""" if string.startswith(prefix): return string[len(prefix):] - else + else: return string def remove_file(repo, dst): 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) |