Example #1
0
 def test_passing_extra_kwargs(self):
     used_input = {'x': 2}
     input_kwargs = {**used_input, 'y': 3}
     for sig in [self.sig_func_a, self.sig_func_b]:
         with self.subTest(sig.__str__()):
             bog = BagOfGoodies(sig, (), input_kwargs)
             args, kwargs = bog.split_for_signature()
             self.assertDictEqual(kwargs, used_input)
             self.assertListEqual(args, [])
             self.assertDictEqual(bog.get_bag(), input_kwargs)
     for sig in [self.sig_func_c, self.sig_func_d, self.sig_func_e]:
         with self.subTest(sig.__str__()):
             bog = BagOfGoodies(sig, (), input_kwargs)
             args, kwargs = bog.split_for_signature()
             self.assertDictEqual(kwargs, input_kwargs)
             self.assertListEqual(args, [])
             self.assertDictEqual(bog.get_bag(), input_kwargs)
Example #2
0
 def test_bog_update(self):
     value = 3
     input_args = (value, )
     for sig in [
             self.sig_func_a, self.sig_func_b, self.sig_func_d,
             self.sig_func_e
     ]:
         with self.subTest(sig.__str__()):
             bog = BagOfGoodies(sig, input_args, {})
             args, kwargs = bog.split_for_signature()
             self.assertDictEqual(kwargs, {})
             self.assertListEqual(args, [value])
             self.assertDictEqual(bog.get_bag(), {'x': value})
             new_value = 2
             bog.update({'x': new_value})
             args, kwargs = bog.split_for_signature()
             self.assertListEqual(args, [new_value])
             self.assertDictEqual(kwargs, {})
             self.assertDictEqual(bog.get_bag(), {'x': new_value})
Example #3
0
 def test_passing_more_than_exact_requirement_from_bog(self):
     useful_return = {'x': 1}
     nonuseful_return = {'y': 1}
     previous_returns = {**useful_return, **nonuseful_return}
     input_args = (previous_returns, )
     for sig in [self.sig_func_a, self.sig_func_b]:
         with self.subTest(sig.__str__()):
             bog = BagOfGoodies(sig, input_args, {})
             args, kwargs = bog.split_for_signature()
             self.assertDictEqual(kwargs, useful_return)
             self.assertListEqual(args, [])
             self.assertDictEqual(bog.return_args, previous_returns)
     for sig in [self.sig_func_c, self.sig_func_d, self.sig_func_e]:
         with self.subTest(sig.__str__()):
             bog = BagOfGoodies(sig, input_args, {})
             args, kwargs = bog.split_for_signature()
             self.assertDictEqual(kwargs, previous_returns)
             self.assertListEqual(args, [])
             self.assertDictEqual(bog.get_bag(), previous_returns)
Example #4
0
 def test_passing_from_bog_with_indirect(self):
     previous_returns = {'y': 2}
     new_inputs = {'x': '@y'}
     new_inputs_after_resolving = {'x': 2}
     expected_returns = {**new_inputs_after_resolving, **previous_returns}
     input_args = (previous_returns, )
     for sig in [self.sig_func_a, self.sig_func_b]:
         with self.subTest(sig.__str__()):
             bog = BagOfGoodies(sig, input_args, new_inputs)
             args, kwargs = bog.split_for_signature()
             self.assertDictEqual(kwargs, new_inputs_after_resolving)
             self.assertListEqual(args, [])
             self.assertDictEqual(bog.get_bag(), expected_returns)
     for sig in [self.sig_func_c, self.sig_func_d, self.sig_func_e]:
         with self.subTest(sig.__str__()):
             bog = BagOfGoodies(sig, input_args, new_inputs)
             args, kwargs = bog.split_for_signature()
             self.assertDictEqual(kwargs, expected_returns)
             self.assertListEqual(args, [])
             self.assertDictEqual(bog.get_bag(), expected_returns)
Example #5
0
    def test_positional_arg_is_a_dict(self):
        # noinspection PyUnusedLocal
        def func(some_key):
            # Should not reach here. We only want the signature
            pass  # pragma: no cover

        sig = inspect.signature(func)

        with self.subTest(
                'positional dict is first arg, but no previous returns'):
            args = ({'k1': 'v1'}, )
            kwargs = {}
            bog = BagOfGoodies(sig,
                               args,
                               kwargs,
                               has_returns_from_previous_task=False)
            self.assertDictEqual(bog.get_bag(), {'some_key': {'k1': 'v1'}})
            a, k = bog.split_for_signature()
            self.assertEqual(len(a), 1)
            self.assertEqual(a[0], {'k1': 'v1'})

        with self.subTest('old value should be trumped by positional dict'):
            old_bog = {'some_key': {'k1': 'wrong_value'}, 'k2': 'other_value'}
            args = (
                old_bog,
                {
                    'k1': 'v1'
                },
            )
            kwargs = {}
            bog = BagOfGoodies(sig, args, kwargs)
            self.assertDictEqual(bog.get_bag(), {
                'some_key': {
                    'k1': 'v1'
                },
                'k2': 'other_value'
            })
            a, k = bog.split_for_signature()
            self.assertEqual(len(a), 1)
            self.assertEqual(a[0], {'k1': 'v1'})
Example #6
0
 def test_passing_from_bog_with_an_kwarg_overwrite(self):
     previous_returns = {'x': 1}
     input_args = (previous_returns, )
     input_kwargs = {'x': 2}
     for sig in [
             self.sig_func_a, self.sig_func_b, self.sig_func_c,
             self.sig_func_d, self.sig_func_e
     ]:
         with self.subTest(sig.__str__()):
             bog = BagOfGoodies(sig, input_args, input_kwargs)
             args, kwargs = bog.split_for_signature()
             self.assertDictEqual(kwargs, input_kwargs)
             self.assertListEqual(args, [])
             self.assertDictEqual(bog.get_bag(), input_kwargs)
Example #7
0
    def test_first_with_explicit_args(self):

        # noinspection PyUnusedLocal
        def a_simple_task(value, value2="unimportant"):
            # Should not reach here. We only want the signature
            pass  # pragma: no cover

        sig = inspect.signature(a_simple_task)
        args = ('nope', )
        kwargs = {}
        bog = BagOfGoodies(sig, args, kwargs)
        self.assertDictEqual(bog.get_bag(), {"value": 'nope'})
        bog.update({"value": 'yup'})
        self.assertDictEqual(bog.get_bag(), {"value": 'yup'})
        a, k = bog.split_for_signature()
        self.assertEqual(len(a), 1)
        self.assertEqual(a[0], 'yup')
Example #8
0
    def test_bind_goodies(self):
        old_bog = {'geo_loc': 'OTT'}
        args = (old_bog, )
        kwargs = {'expected_module': 'additional_for_plugin_propagation.py'}
        a_self = self

        class Thing:
            # noinspection PyMethodMayBeStatic
            def a_func(self, expected_module):
                a_self.assertEqual(expected_module,
                                   "additional_for_plugin_propagation.py")

        t = Thing()
        sig = inspect.signature(t.a_func)
        bog = BagOfGoodies(sig, args, kwargs)
        a, k = bog.split_for_signature()
        t.a_func(*a, **k)
Example #9
0
    def test_indirect_from_default(self):
        def fun(arg_zero,
                arg_one="@do_not_use",
                arg_two="@first_value",
                arg_three="@second_value",
                arg_four="@do_not_use"):
            self.assertEqual('success', arg_zero)
            self.assertEqual('success', arg_one)
            self.assertEqual('success', arg_two)
            self.assertEqual('success', arg_three)
            self.assertEqual('success', arg_four)

        sig = inspect.signature(fun)

        old_bog = {'first_value': 'success'}
        args = (old_bog, "@first_value", "success")
        kwargs = {
            "second_value": 'success',
            "do_not_use": "failure",
            "arg_four": "success"
        }
        bog = BagOfGoodies(sig, args, kwargs)
        a, k = bog.split_for_signature()
        fun(*a, **k)
Example #10
0
    def test_indirect_from_return(self):

        # noinspection PyUnusedLocal
        def ending(final, missing):
            self.assertTrue(True)

        sig = inspect.signature(ending)

        old_bog = {
            'concurrent_runs_limit':
            6,
            'cc_firex':
            False,
            'log_level':
            'debug',
            'sync':
            True,
            'start':
            'yep',
            'group':
            'me',
            'plugins':
            '~/firex7/flow_tests/argument_validation_tests.py',
            'no_email':
            True,
            'final':
            'pass',  # <-- This is what we are testing
            'submission_dir':
            '~/firex7',
            'unconverted_chain_args': {
                'missing': '@final',
                'cc_firex': 'False',
                'start': 'yep',
                'disable_blaze': True,
                'plugins': '~/firex7/flow_tests/'
                'argument_validation_tests.py'
            },
            'chain':
            'beginning,ending',
            'missing':
            '@final',  # <-- This is what we are testing
            'argv': [
                '~/firex7/firex.py', 'submit', '--chain', 'beginning,ending',
                '--start', 'yep', '--missing', '@final', '--sync',
                '--no_email', '--cc_firex', 'False', '--monitor_verbosity',
                'none', '--flame_port', '54560', '--flame_timeout', '60',
                '--disable_blaze', 'True', '--external',
                '~/firex7/flow_tests/argument_validation_tests.py'
            ]
        }
        args = (old_bog, )
        kwargs = {}
        bog = BagOfGoodies(sig, args, kwargs)

        self.assertTrue('missing' in bog.get_bag())
        self.assertEqual(bog.get_bag()['missing'], 'pass')

        a, k = bog.split_for_signature()
        ending(*a, **k)
        self.assertTrue(len(k), 2)
        self.assertEqual(k['missing'], 'pass')

        # noinspection PyUnusedLocal
        def ending_v2(final, missing, **the_kwargs):
            self.assertTrue(True)

        sig_v2 = inspect.signature(ending_v2)
        bog_v2 = BagOfGoodies(sig_v2, args, kwargs)
        a, k = bog_v2.split_for_signature()
        ending_v2(*a, **k)
        self.assertTrue(len(k), 16)