Пример #1
0
    def testEnvironment_set_params(self):
        # Make instant with params and args.
        env = Environment(params=['KEY_1', 'KEY_2'], args=['VAL_1', 'VAL_2'])

        # `find` method must return self and we can get values for keys.
        self.assertEqual(env.find('KEY_1')['KEY_1'], 'VAL_1')
        self.assertEqual(env.find('KEY_2')['KEY_2'], 'VAL_2')
Пример #2
0
    def testEnvironment_extend(self):
        env = Environment()

        # A environment that have itself as an outer environment.
        extended_env = env.extend()

        # An outer environment must be itself.
        self.assertTrue(extended_env.outer is env)
Пример #3
0
    def testEnvironment_find_value(self):
        env = Environment()

        # Add key-value pair for testing `find` method.
        env['KEY'] = 'VAL'

        # `find` method must return self and we can get value for key.
        self.assertEqual(env.find('KEY')['KEY'], 'VAL')
Пример #4
0
    def testEnvironment_find(self):
        env = Environment()

        # Add key-value pair for testing `find` method.
        env['KEY'] = 'VAL'

        # `find` method must return self.
        self.assertEqual(env.find('KEY'), env)
Пример #5
0
    def testEnvironment_find_outer_value(self):
        # Set outer environment.
        outer = Environment()
        env = Environment(outer=outer)

        # Add key-value pari to outer environment.
        env.outer['OUTER_KEY'] = 'OUTER_VAL'

        # `find` method must retrun outer environment and we can get outer value for outer key.
        self.assertEqual(env.find('OUTER_KEY')['OUTER_KEY'], 'OUTER_VAL')
Пример #6
0
    def testEnvironment_find_outer(self):
        # Set outer environment.
        outer = Environment()
        env = Environment(outer=outer)

        # Add key-value pari to outer environment.
        env.outer['OUTER_KEY'] = ['OUTER_VAL']

        # `find` method must retrun outer environment.
        self.assertEqual(env.find('OUTER_KEY'), outer)
Пример #7
0
    def testEnvironment_find_raise_exception(self):
        env = Environment()

        # Raise exception if key-value pair does not exist.
        self.assertRaises(LookupError, env.find, 'KEY')
Пример #8
0
    def testEnvironment(self):
        env = Environment()

        # Check instance.
        self.assertIsInstance(env, Environment)