piknik

Unnamed repository; edit this file 'description' to name the repository.
Info | Log | Files | Refs | README | LICENSE

commit a8a6074d4bcda4435b6457e1e57b0816c9135ae1
parent f2a8bf524e750fc7d79a8c1da93b84684735e4c8
Author: lash <dev@holbrook.no>
Date:   Sun,  6 Nov 2022 21:46:24 +0000

Set up tag state directory

Diffstat:
Mpiknik/basket.py | 24+++++++++++++++++++++---
Mpiknik/store/__init__.py | 12+++++++++---
Atests/common.py | 21+++++++++++++++++++++
Mtests/test_basic.py | 20++++++++++----------
Mtests/test_issue.py | 1+
Mtests/test_store.py | 19++++++++++++++-----
Atests/test_tag.py | 41+++++++++++++++++++++++++++++++++++++++++
7 files changed, 117 insertions(+), 21 deletions(-)

diff --git a/piknik/basket.py b/piknik/basket.py @@ -8,19 +8,21 @@ class Basket: def __init__(self, state_factory): self.no_resurrect = True - self.state = state_factory(default_state='backlog', verifier=self.__check_resurrect) + self.state = state_factory.create_states(default_state='backlog', verifier=self.__check_resurrect) self.state.add('pending') self.state.add('doing') self.state.add('review') self.state.add('finished') self.state.add('blocked') - self.state.alias('doingblocked', self.state.DOING | self.state.BLOCKED) self.state.alias('pendingblocked', self.state.PENDING | self.state.BLOCKED) + self.limit = self.state.FINISHED + self.state.sync() - self.limit = self.state.FINISHED + self.tags = state_factory.create_tags() + self.issues_rev = {} @@ -88,3 +90,19 @@ class Basket: def states(self): return self.state.all(pure=True) + + + def tag(self, issue_id, tag): + v = 0 + try: + v = self.tags.from_name(tag) + except AttributeError: + self.tags.add(tag) + v = self.tags.from_name(tag) + + try: + self.tags.put(issue_id) + except shep.error.StateItemExists: + pass + + self.tags.set(issue_id, v) diff --git a/piknik/store/__init__.py b/piknik/store/__init__.py @@ -10,8 +10,14 @@ class FileStoreFactory: if directory == None: directory = os.path.join(os.environ['HOME'], '.piknik') self.directory = directory - self.factory = SimpleFileStoreFactory(directory).add - def create(self, logger=None, default_state=None, verifier=None): - return PersistedState(self.factory, 6, logger=logger, verifier=verifier, default_state=default_state) + def create_states(self, logger=None, default_state=None, verifier=None): + factory = SimpleFileStoreFactory(self.directory).add + return PersistedState(factory, 6, logger=logger, verifier=verifier, default_state=default_state) + + + def create_tags(self, logger=None, default_state=None, verifier=None): + directory = os.path.join(self.directory, '.tags') + factory = SimpleFileStoreFactory(directory).add + return PersistedState(factory, 0, logger=logger, check_alias=False, default_state='untagged') diff --git a/tests/common.py b/tests/common.py @@ -0,0 +1,21 @@ +# standard imports +import logging + +# external imports +import shep + +logg = logging.getLogger() + + +def debug_out(self, k, v): + logg.debug('TRACE: {} {}'.format(k, v)) + + +class TestStates: + + def create_states(*args, **kwargs): + return shep.State(6, *args, event_callback=debug_out, **kwargs) + + + def create_tags(*args, **kwargs): + return shep.State(0, *args, event_callback=debug_out, check_alias=False, **kwargs) diff --git a/tests/test_basic.py b/tests/test_basic.py @@ -1,29 +1,29 @@ +# standard imports import unittest -import shep import logging -logging.basicConfig(level=logging.DEBUG) -logg = logging.getLogger() +# external imports +import shep +# local imports from piknik import ( Basket, Issue, ) from piknik.error import DeadIssue +# tests imports +from tests.common import debug_out +from tests.common import TestStates -def debug_out(self, k, v): - logg.debug('TRACE: {} {}'.format(k, v)) - - -def create_test_state(*args, **kwargs): - return shep.State(6, *args, event_callback=debug_out, **kwargs) +logging.basicConfig(level=logging.DEBUG) +logg = logging.getLogger() class TestBasic(unittest.TestCase): def setUp(self): - self.b = Basket(create_test_state) + self.b = Basket(TestStates()) def test_issue_basic(self): diff --git a/tests/test_issue.py b/tests/test_issue.py @@ -1,3 +1,4 @@ +# standard imports import unittest import logging import json diff --git a/tests/test_store.py b/tests/test_store.py @@ -1,12 +1,13 @@ +# standard imports import unittest -import shep import logging import tempfile import shutil -logging.basicConfig(level=logging.DEBUG) -logg = logging.getLogger() +# external imports +import shep +# local imports from piknik import ( Basket, Issue, @@ -14,6 +15,14 @@ from piknik import ( from piknik.error import DeadIssue from piknik.store import FileStoreFactory +# tests imports +from tests.common import debug_out +from tests.common import TestStates + + +logging.basicConfig(level=logging.DEBUG) +logg = logging.getLogger() + def debug_out(self, k, v): logg.debug('TRACE: {} {}'.format(k, v)) @@ -25,7 +34,7 @@ class TestStore(unittest.TestCase): self.d = tempfile.mkdtemp() logg.debug('tempdir is {}'.format(self.d)) self.store_factory = FileStoreFactory(self.d) - self.b = Basket(self.store_factory.create) + self.b = Basket(self.store_factory) def tearDown(self): @@ -47,7 +56,7 @@ class TestStore(unittest.TestCase): self.b.advance(va) - b = Basket(self.store_factory.create) + b = Basket(self.store_factory) print('get va {}'.format(va)) r = b.get(va) diff --git a/tests/test_tag.py b/tests/test_tag.py @@ -0,0 +1,41 @@ +# standard imports +import unittest +import logging + +# external imports +import shep + +# local imports +from piknik import ( + Basket, + Issue, + ) +from piknik.error import DeadIssue + +# tests imports +from tests.common import debug_out +from tests.common import TestStates + +logging.basicConfig(level=logging.DEBUG) +logg = logging.getLogger() + + +def debug_out(self, k, v): + logg.debug('TRACE: {} {}'.format(k, v)) + + +class TestBasic(unittest.TestCase): + + def setUp(self): + self.b = Basket(TestStates()) + + + def test_setget(self): + o = Issue('foo') + v = self.b.add(o) + self.b.tag(v, 'inky') + self.b.tag(v, 'pinky') + + +if __name__ == '__main__': + unittest.main()