import unittest

from ..task import BaseSimpleTask
from ..task.cachedtask import BaseCachedTask
from ..runner import simple
from ..datastore.inmemory import DataStoreNestableInMemory


class ImMemoryCachedTask(BaseCachedTask, BaseSimpleTask):
    num_run = 0

    def run(self):
        self.num_run += 1

    def get_taskvalue(self):
        return self.taskvalue


class TestSimpleRunner(unittest.TestCase):

    runner = simple
    """Runner module."""

    class Task(ImMemoryCachedTask):

        num_parents = 3

        def generate_parents(self):
            return [
                ImMemoryCachedTask(datastore=self.datastore.get_substore(i),
                                   taskvalue=())
                for i in range(self.num_parents)]

    def assert_run_once(self):
        self.assertEqual(self.task.num_run, 1)
        for p in self.task.get_parents():
            self.assertEqual(p.num_run, 1)

    def test_simple_run(self):
        self.ds = DataStoreNestableInMemory()
        self.task = self.Task(taskvalue=(), datastore=self.ds)
        self.runner.run(self.task)
        self.assert_run_once()

    def test_cached_run(self):
        self.test_simple_run()
        for i in range(2):
            self.runner.run(self.task)
            self.assert_run_once()

@@ -1260,28 +1260,534 @@
      self.assert_run_once()%0A
+%0A    def test_invalidate_parent(self):%0A        self.test_simple_run()%0A        # Invalidate 0-th parent node cache%0A        ptask = self.task.get_parents()%5B0%5D%0A        pths = ptask.get_taskhashstore()%0A        pths.clear()%0A        self.runner.run(self.task)%0A%0A        self.assertRaises(AssertionError, self.assert_run_once)%0A        self.assertEqual(self.task.num_run, 2)%0A        self.assertEqual(ptask.num_run, 2)%0A        for other in self.task.get_parents()%5B1:%5D:%0A            self.assertEqual(other.num_run, 1)%0A

Add test_invalidate_parent for BaseCachedTask