def test_ls(self): """Tests :func:`hkshell.ls`.""" class MyOutput(): @staticmethod def write(str): output_list.append(str) self.init_hkshell() output = MyOutput() hkshell.options.output = output hklib.localtime_fun = time.gmtime # ls with default parameters output_list = [] hkshell.ls() self.assertEquals( output_list, ['<0> author0 (2008.08.20. 15:41)\n', ' <1> author1 (2008.08.20. 15:41)\n', ' <2> author2 (2008.08.20. 15:41)\n', ' <3> author3 (2008.08.20. 15:41)\n', '<4> author4 (2008.08.20. 15:41)\n']) # ls with given parameters hkshell.aTr(1,['mytag1','mytag2']) output_list = [] hkshell.ls(hkshell.ps([1,2,4]), show_author=False, show_tags=True, show_date=False, indent=4) self.assertEquals( output_list, [' <1> [mytag1,mytag2]\n', ' <2> [mytag1,mytag2]\n', '<4> []\n'])
def test_sT_AND_sTr(self): self.init_hkshell() hkshell.aTr(0, ['t', 'u']) self.ae(self.tags(), [['t','u'],['t','u'],['t','u'],['t','u'],[]]) hkshell.sT(1, ['x', 'y']) self.ae(self.tags(), [['t','u'],['x','y'],['t','u'],['t','u'],[]]) hkshell.sTr(1, 'z') self.ae(self.tags(), [['t','u'],['z'],['z'],['t','u'],[]])
def test_rT_AND_rTr(self): self.init_hkshell() hkshell.aTr(0, ['t', 'u']) self.ae(self.tags(), [['t','u'],['t','u'],['t','u'],['t','u'],[]]) hkshell.rT(1, ['t']) self.ae(self.tags(), [['t','u'],['u'],['t','u'],['t','u'],[]]) hkshell.rTr(1, ['u']) self.ae(self.tags(), [['t','u'],[],['t'],['t','u'],[]])
def set_to_reviewed(prepost=None): """Sets the given thread to reviewed and commits all changes to the heap in which the thread is. **Argument:** - `prepost` (|PrePost| | ``None``) -- If all touched post are within one thread, this parameter may be ``None``, in which case Heapkeeper will find this thread. """ if prepost is None: modified = hkshell.postdb().all().collect.is_modified() roots = modified.expb().collect.is_root() if len(roots) == 0: hkutils.log( 'No modified posts. No action. Use the r(<post id>) format.') return elif len(roots) > 1: hkutils.log('More than one modified threads. No action.') return post = roots.pop() hkutils.log('Thread: ' + post.post_id_str()) else: post = hkshell.p(prepost) if hkshell.postdb().parent(post) is not None: hkutils.log('The post is not a root. No action.') return # Saving the modifications hkshell.aTr(post, 'reviewed') hkshell.s() # Calculating the subject to be mentioned in the commit message subject = post.subject() if len(subject) > 33: subject = subject[:30] + '...' # Writing the commit message into a temp file f, filename = tempfile.mkstemp() os.write(f, 'Review: "' + subject + '" thread\n' '\n' '[review]\n') os.close(f) # Commiting the change in git heap_dir = hkshell.postdb()._heaps[post.heap_id()] oldcwd = os.getcwd() try: os.chdir(heap_dir) hkutils.call(['git', 'commit', '-aF', filename]) finally: os.chdir(oldcwd) os.remove(filename)
def test_ls(self): """Tests :func:`hkshell.ls`.""" class MyOutput(): # Class has no __init__ method # pylint: disable=W0232 @staticmethod def write(str): output_list.append(str) self.init_hkshell() output = MyOutput() hkshell.options.output = output hklib.localtime_fun = time.gmtime # ls with default parameters output_list = [] hkshell.ls() self.assertEqual( output_list, ['<my_heap/0> subject0 author0 (2008.08.20. 15:41)\n', ' <my_heap/1> subject1 author1 (2008.08.20. 15:41)\n', ' <my_heap/2> subject2 author2 (2008.08.20. 15:41)\n', ' <my_heap/3> subject3 author3 (2008.08.20. 15:41)\n', '<my_other_heap/0> subject0 author0 (2008.08.20. 15:41)\n', '<my_heap/4> subject4 author4 (2008.08.20. 15:41)\n']) # ls with given parameters hkshell.aTr('my_heap/1', ['mytag1', 'mytag2']) output_list = [] hkshell.ls(hkshell.ps([1, 2, 4]), show_author=False, show_tags=True, show_date=False, indent=4) self.assertEqual( output_list, [' <my_heap/1> subject1 [mytag1,mytag2]\n', ' <my_heap/2> subject2 [mytag1,mytag2]\n', '<my_heap/4> subject4 []\n'])
def test_aTr(self): self.init_hkshell() hkshell.aTr(1, 't') self.assertEqual(self.tags(), [[], ['t'], ['t'], [], []]) hkshell.aTr(1, ['t', 'u']) self.assertEqual(self.tags(), [[], ['t', 'u'], ['t', 'u'], [], []])
def R(pps): """Mark thread as reviewed.""" hkshell.aTr(pps, 'r')