Exemple #1
0
    def test_invoke_as_part_of_workflow(self):
        resource = get_resource('workflows/three_ops.json')
        workflow = Workflow.load(resource)
        step = WorkflowStep(workflow, resource, node_id='jojo_87')

        workflow = Workflow(
            OpMetaInfo('contains_jojo_87',
                       has_monitor=True,
                       inputs=OrderedDict(x={}),
                       outputs=OrderedDict(y={})))
        workflow.add_step(step)
        step.inputs.p.source = workflow.inputs.x
        workflow.outputs.y.source = step.outputs.q

        value_cache = ValueCache()
        workflow.inputs.x.value = 4
        workflow.invoke(context=dict(value_cache=value_cache))
        output_value = workflow.outputs.y.value
        self.assertEqual(output_value, 2 * (4 + 1) + 3 * (2 * (4 + 1)))
        self.assertEqual(
            value_cache, {
                'jojo_87._child': {
                    'op1': {
                        'y': 5
                    },
                    'op2': {
                        'b': 10
                    },
                    'op3': {
                        'w': 40
                    }
                }
            })
Exemple #2
0
    def test_get_id(self):
        vc = ValueCache()
        vc['bibo1'] = object()
        vc['bibo2'] = object()
        vc['bibo3'] = object()

        self.assertEqual(vc.get_id('bibo1'), 1)
        self.assertEqual(vc.get_id('bibo2'), 2)
        self.assertEqual(vc.get_id('bibo3'), 3)

        vc['bibo1'] = object()
        vc['bibo2'] = object()
        vc['bibo3'] = object()

        self.assertEqual(vc.get_id('bibo1'), 1)
        self.assertEqual(vc.get_id('bibo2'), 2)
        self.assertEqual(vc.get_id('bibo3'), 3)

        vc.clear()

        self.assertEqual(vc.get_id('bibo1'), None)
        self.assertEqual(vc.get_id('bibo2'), None)
        self.assertEqual(vc.get_id('bibo3'), None)

        vc['bibo1'] = object()
        vc['bibo2'] = object()
        vc['bibo3'] = object()

        self.assertEqual(vc.get_id('bibo1'), 4)
        self.assertEqual(vc.get_id('bibo2'), 5)
        self.assertEqual(vc.get_id('bibo3'), 6)
Exemple #3
0
    def test_del(self):
        bibo = ValueCacheTest.ClosableBibo()

        vc = ValueCache()
        vc['bibo'] = bibo
        self.assertIn('bibo', vc)
        self.assertIs(vc['bibo'], bibo)

        self.assertFalse(bibo.closed)
        del vc['bibo']
        self.assertTrue(bibo.closed)
        self.assertNotIn('bibo', vc)
Exemple #4
0
 def __init__(self,
              base_dir: str,
              workflow: Workflow,
              is_modified: bool = False):
     assert base_dir
     assert workflow
     self._base_dir = base_dir
     self._workflow = workflow
     self._is_scratch = (base_dir or '').startswith(SCRATCH_WORKSPACES_PATH)
     self._is_modified = is_modified
     self._is_closed = False
     self._resource_cache = ValueCache()
Exemple #5
0
    def test_child(self):
        bibo = object()

        vc = ValueCache()
        vc['bibo'] = bibo

        child_vc = vc.child('bibo')
        self.assertIsInstance(child_vc, ValueCache)
        self.assertIn('bibo', vc)
        self.assertIs(vc['bibo'], bibo)
        self.assertIn('bibo._child', vc)
        self.assertIs(vc['bibo._child'], child_vc)
        self.assertIsNot(child_vc, vc)
Exemple #6
0
    def test_set(self):
        bibo = ValueCacheTest.ClosableBibo()

        vc = ValueCache()
        vc['bibo'] = bibo
        self.assertIn('bibo', vc)
        self.assertIs(vc['bibo'], bibo)

        self.assertFalse(bibo.closed)
        vc['bibo'] = None
        self.assertTrue(bibo.closed)
        self.assertIn('bibo', vc)
        self.assertIs(vc['bibo'], None)
Exemple #7
0
    def test_close(self):
        bibo1 = ValueCacheTest.ClosableBibo()
        bibo2 = ValueCacheTest.ClosableBibo()
        bibo3 = ValueCacheTest.ClosableBibo()

        vc = ValueCache()
        vc['bibo1'] = bibo1
        vc['bibo2'] = bibo2
        vc['bibo3'] = bibo3

        self.assertFalse(bibo1.closed)
        self.assertFalse(bibo2.closed)
        self.assertFalse(bibo3.closed)
        vc.close()
        self.assertTrue(bibo1.closed)
        self.assertTrue(bibo2.closed)
        self.assertTrue(bibo3.closed)
Exemple #8
0
    def test_close_with_child(self):
        bibo1 = ValueCacheTest.ClosableBibo()
        bibo2 = ValueCacheTest.ClosableBibo()
        bibo3 = ValueCacheTest.ClosableBibo()

        vc = ValueCache()
        vc['bibo1'] = bibo1
        vc['bibo2'] = bibo2
        bibo2_child = vc.child('bibo2')
        bibo2_child['bibo3'] = bibo3

        self.assertFalse(bibo1.closed)
        self.assertFalse(bibo2.closed)
        self.assertFalse(bibo3.closed)
        vc.close()
        self.assertTrue(bibo1.closed)
        self.assertTrue(bibo2.closed)
        self.assertTrue(bibo3.closed)
Exemple #9
0
    def test_rename_key(self):
        bibo = object()

        vc = ValueCache()
        vc['bibo'] = bibo

        bibo_id = vc.get_id('bibo')
        bibo_child = vc.child('bibo')

        vc.rename_key('bibo', 'bert')

        self.assertNotIn('bibo', vc)
        self.assertNotIn('bibo._child', vc)

        self.assertIn('bert', vc)
        self.assertIs(vc['bert'], bibo)
        self.assertIn('bert._child', vc)
        self.assertIs(vc['bert._child'], bibo_child)
        self.assertEqual(vc.get_id('bert'), bibo_id)
Exemple #10
0
    def test_get_update_count(self):
        vc = ValueCache()
        vc['bibo1'] = object()
        vc['bibo2'] = object()
        vc['bibo3'] = object()

        self.assertEqual(vc.get_update_count('bibo1'), 0)
        self.assertEqual(vc.get_update_count('bibo2'), 0)
        self.assertEqual(vc.get_update_count('bibo3'), 0)

        vc['bibo2'] = object()
        vc['bibo3'] = object()
        vc['bibo2'] = object()
        vc['bibo2'] = None

        self.assertEqual(vc.get_update_count('bibo1'), 0)
        self.assertEqual(vc.get_update_count('bibo2'), 3)
        self.assertEqual(vc.get_update_count('bibo3'), 1)

        vc.clear()

        self.assertEqual(vc.get_update_count('bibo1'), None)
        self.assertEqual(vc.get_update_count('bibo2'), None)
        self.assertEqual(vc.get_update_count('bibo3'), None)