コード例 #1
0
 def test_subst_2(self):
     """_GVarsEnvProxy(env, resubst = {'b' : '${c}}).subst('${a} ${b}') should call env.subst('${a} ${c}')"""
     env = Mock(name = 'env')
     env.subst = Mock(name = 'env.subst')
     GVars._GVarsEnvProxy(env, resubst = {'b' : '${c}'}).subst('${a} ${b}')
     try:
         env.subst.assert_called_with('${a} ${c}')
     except AssertionError as e:
         self.fail(str(e))
コード例 #2
0
 def test___init___2(self):
     """_GVars.__init__(gdecls) should initialize its iternal dicts"""
     gv = GVars._GVars(self._gdecls_mock_2())
     self.assertEqual(gv._GVars__rename, ['rename_dict[0]', 'rename_dict[1]', 'rename_dict[2]'])
     self.assertEqual(gv._GVars__resubst, ['resubst_dict[0]', 'resubst_dict[1]', 'resubst_dict[2]'])
     self.assertEqual(gv._GVars__irename, ['irename_dict[0]', 'irename_dict[1]', 'irename_dict[2]'])
     self.assertEqual(gv._GVars__iresubst, ['iresubst_dict[0]', 'iresubst_dict[1]', 'iresubst_dict[2]'])
コード例 #3
0
 def test___setitem___4(self):
     """_GVarsEnvProxy({'a' : 'B'}, strict = True).__setitem__('a', 'A') should raise KeyError"""
     env = {'a' : 'B'}
     proxy = GVars._GVarsEnvProxy(env, strict = True)
     with self.assertRaises(KeyError):
         proxy.__setitem__('a', 'A')
     self.assertEqual(env['a'], 'B')
コード例 #4
0
 def test___reset_supp_dicts(self):
     """_GVars.__reset_supp_dicts() should reset internal dicts to {}"""
     gv = GVars._GVars(self._gdecls_mock_2())
     gv._GVars__reset_supp_dicts()
     self.assertEqual(gv._GVars__rename, [{},{},{}])
     self.assertEqual(gv._GVars__resubst, [{},{},{}])
     self.assertEqual(gv._GVars__irename, [{},{},{}])
     self.assertEqual(gv._GVars__iresubst, [{},{},{}])
コード例 #5
0
 def test_GetCurrentValues_1(self):
     """_GVars(gdecls).GetCurrentValues(env) works as expected"""
     gv = GVars._GVars(self._gdecls_mock_5())
     env = { 'env_k' : 'K', 'env_e' : 'E', 'env_x' : 'X' }
     current = gv.GetCurrentValues(env)
     self.assertIs(current['env_k'], env['env_k'])
     self.assertIs(current['env_e'], env['env_e'])
     self.assertEqual(current, {'env_k' : 'K', 'env_e' : 'E'})
コード例 #6
0
 def test_set_strict_True_calls__setup_methods_True(self):
     """_GVarsEnvProxy.set_strict(True) should call _GVarsEnvProxy.__setup_methods(True)"""
     proxy = GVars._GVarsEnvProxy('env')
     proxy._GVarsEnvProxy__setup_methods = Mock(name = '__setup_methods')
     proxy.set_strict(True)
     try:
         proxy._GVarsEnvProxy__setup_methods.assert_called_with(True)
     except AssertionError as e:
         self.fail(str(e))
コード例 #7
0
 def test___init___1(self):
     """_GVarsEnvProxy.__init__(env) should set default attributes"""
     env = 'env'
     proxy = GVars._GVarsEnvProxy(env)
     self.assertIs(proxy.env, env)
     self.assertEqual(proxy._GVarsEnvProxy__rename, {})
     self.assertEqual(proxy._GVarsEnvProxy__irename, {})
     self.assertEqual(proxy._GVarsEnvProxy__resubst, {})
     self.assertEqual(proxy._GVarsEnvProxy__iresubst, {})
     self.assertEqual(proxy.is_strict(), False)
コード例 #8
0
 def test___init___2(self):
     """_GVarsEnvProxy.__init__(env, arg1, arg2, arg3, arg4, True) should set attributes"""
     env = 'env'
     arg1, arg2, arg3, arg4 = 'arg1', 'arg2', 'arg3', 'arg4'
     proxy = GVars._GVarsEnvProxy(env, arg1, arg2, arg3, arg4, True)
     self.assertIs(proxy.env, env)
     self.assertIs(proxy._GVarsEnvProxy__rename,   arg1)
     self.assertIs(proxy._GVarsEnvProxy__resubst,  arg2)
     self.assertIs(proxy._GVarsEnvProxy__irename,  arg3)
     self.assertIs(proxy._GVarsEnvProxy__iresubst, arg4)
     self.assertIs(proxy.is_strict(), True)
コード例 #9
0
 def test___setup_methods_False(self):
     """_GVarsEnvProxy.__setup_methods(False) should setup appropriate methods"""
     proxy = GVars._GVarsEnvProxy('env', strict = True)
     proxy._GVarsEnvProxy__setup_methods(False)
     self.assertEqual(proxy._GVarsEnvProxy__delitem__impl, proxy._GVarsEnvProxy__delitem__nonstrict)
     self.assertEqual(proxy._GVarsEnvProxy__getitem__impl, proxy._GVarsEnvProxy__getitem__nonstrict)
     self.assertEqual(proxy._GVarsEnvProxy__setitem__impl, proxy._GVarsEnvProxy__setitem__nonstrict)
     self.assertEqual(proxy.get, proxy._get_nonstrict)
     self.assertEqual(proxy.has_key, proxy._has_key_nonstrict)
     self.assertEqual(proxy._GVarsEnvProxy__contains__impl, proxy._GVarsEnvProxy__contains__nonstrict)
     self.assertEqual(proxy.items, proxy._items_nonstrict)
コード例 #10
0
 def test___init___1(self):
     """_GVars.__init__(gdecls) should call gdecls.keys() and self.__init_supp_dicts(gdecls)"""
     gdecls = self._gdecls_mock_1()
     with patch.object(GVars._GVars, '_GVars__init_supp_dicts', autospec=True) as mock:
         gv = GVars._GVars(gdecls)
         try:
             mock.assert_called_once_with(gv, gdecls)
             gdecls.keys.assert_called_once_with()
         except AssertionError as e:
             self.fail(str(e))
     self.assertIsInstance(gv, GVars._GVars)
     self.assertEqual(gv._GVars__keys, ['k', 'e', 'y', 's'])
コード例 #11
0
 def test_GenerateVariablesHelpText_2(self):
     """_GVars(gdecls).GenerateVariablesHelpText(variables, 'env1', 'arg1', 'arg2')"""
     def VarEnvProxy(arg): return 'var_%s_proxy' % arg
     gv = GVars._GVars(self._gdecls_mock_1())
     gv.VarEnvProxy = Mock(name = 'VarEnvProxy', side_effect = VarEnvProxy)
     variables = Mock(name = 'variables')
     variables.GenerateHelpText = Mock(name = 'GenerateHelpText')
     gv.GenerateVariablesHelpText(variables, 'env1', 'arg1', 'arg2')
     try:
         variables.GenerateHelpText.assert_called_once_with('var_env1_proxy', 'arg1', 'arg2')
     except AssertionError as e:
         self.fail(str(e))
コード例 #12
0
 def test_update_env_from_vars_1(self):
     """_GVars(gdecls).update_env_from_vars('env', variables)"""
     def VarEnvProxy(arg): return 'var_%s_proxy' % arg
     gv = GVars._GVars(self._gdecls_mock_1())
     gv.VarEnvProxy = Mock(name = 'VarEnvProxy', side_effect = VarEnvProxy)
     variables = Mock(name = 'variables')
     variables.Update = Mock(name = 'Update')
     gv.update_env_from_vars('env', variables)
     try:
         variables.Update.assert_called_once_with('var_env_proxy', None)
     except AssertionError as e:
         self.fail(str(e))
コード例 #13
0
 def test_SaveVariables(self):
     """_GVars(gdecls).SaveVariables(variables, 'filename1', 'env1')"""
     def VarEnvProxy(arg): return 'var_%s_proxy' % arg
     gv = GVars._GVars(self._gdecls_mock_1())
     gv.VarEnvProxy = Mock(name = 'VarEnvProxy', side_effect = VarEnvProxy)
     variables = Mock(name = 'variables')
     variables.Save = Mock(name = 'Save')
     gv.SaveVariables(variables, 'filename1', 'env1')
     try:
         variables.Save.assert_called_once_with('filename1','var_env1_proxy')
     except AssertionError as e:
         self.fail(str(e))
コード例 #14
0
 def test_update_env_from_opts_1(self):
     """_GVars(gdecls).update_env_from_opts('env')"""
     proxy = { 'env1' : {} }
     def OptEnvProxy(arg): return proxy[arg]
     gv = GVars._GVars(self._gdecls_mock_4())
     gv.OptEnvProxy = Mock(name = 'OptEnvProxy', side_effect = OptEnvProxy)
     with patch('SCons.Script.Main.GetOption', side_effect = lambda key : 'val_%s' % key) as GetOption:
         gv.update_env_from_opts('env1')
         try:
             GetOption.assert_called_once_with('opt_a')
         except AssertionError as e:
             self.fail(str(e))
         self.assertEqual(proxy['env1']['opt_a'], 'val_opt_a')
コード例 #15
0
 def test___init_supp_dicts(self):
     """_GVars.__init_supp_dicts(gdecls) should initialize internal dicts appropriately"""
     gdecls = self._gdecls_mock_3()
     gv = GVars._GVars(gdecls)
     self.assertEqual(gv._GVars__rename, [None, None, None])
     self.assertEqual(gv._GVars__resubst, [None, None, None])
     self.assertEqual(gv._GVars__irename, [None, None, None])
     self.assertEqual(gv._GVars__iresubst, [None, None, None])
     self._mock_gdecls_supp_dicts_2(gdecls)
     gv._GVars__init_supp_dicts(gdecls)
     self.assertEqual(gv._GVars__rename, ['rename_dict[0]', 'rename_dict[1]', 'rename_dict[2]'])
     self.assertEqual(gv._GVars__resubst, ['resubst_dict[0]', 'resubst_dict[1]', 'resubst_dict[2]'])
     self.assertEqual(gv._GVars__irename, ['irename_dict[0]', 'irename_dict[1]', 'irename_dict[2]'])
     self.assertEqual(gv._GVars__iresubst, ['iresubst_dict[0]', 'iresubst_dict[1]', 'iresubst_dict[2]'])
コード例 #16
0
    def XxxEnvProxy_test(self, x):
        gv = GVars._GVars(self._gdecls_mock_4())
        env = { 'env_a' : 'A', 'env_b' : 'B'}
        with patch('SConsGnu.GVars._GVarsEnvProxy', return_value = 'ok') as ProxyClass:
            if x == 'var_':
                proxy = gv.VarEnvProxy(env)
            elif x == 'opt_':
                proxy = gv.OptEnvProxy(env)
            else:
                proxy = gv.EnvProxy(env)

            try:
                ProxyClass.assert_called_once_with(env, { '%sa' % x : 'env_a' }, {'%sa' % x : '${env_a}'}, {'env_a' : '%sa' % x}, {'env_a' : '${%sa}' % x})
            except AssertionError as e:
                self.fail(str(e))
            self.assertEqual(proxy, 'ok')
コード例 #17
0
 def test_get_xxx_key_VAR_a(self):
     """_GVars(gdecls).get_xxx_key(VAR, 'a') should == 'var_a'"""
     gv = GVars._GVars(self._gdecls_mock_4())
     self.assertEqual(gv.get_xxx_key(GVars.VAR, 'a'), 'var_a')
コード例 #18
0
 def test__resubst_6(self):
     """GVars._resubst('foo ${bar}', {'bar' : 'XBAR'}) should be 'foo XBAR'"""
     self.assertEqual(GVars._resubst('foo ${bar}', {'bar' : 'XBAR'}), 'foo XBAR')
コード例 #19
0
 def test__resubst_5(self):
     """GVars._resubst('$foo $bar', {'foo' : '$bar', 'bar' : 'XBAR'}) should be '$bar XBAR'"""
     self.assertEqual(GVars._resubst('$foo $bar', {'foo' : '$bar', 'bar' : 'XBAR'}), '$bar XBAR')
コード例 #20
0
 def test_opt_key_a(self):
     """_GVars(gdecls).opt_key('a') should == 'opt_a'"""
     gv = GVars._GVars(self._gdecls_mock_4())
     self.assertEqual(gv.opt_key('a'), 'opt_a')
コード例 #21
0
 def test_opt_key_x(self):
     """_GVars(gdecls).opt_key('x') should raise KeyError"""
     gv = GVars._GVars(self._gdecls_mock_4())
     with self.assertRaises(KeyError):
         gv.opt_key('x')
コード例 #22
0
 def test_var_key_a(self):
     """_GVars(gdecls).var_key('a') should == 'var_a'"""
     gv = GVars._GVars(self._gdecls_mock_4())
     self.assertEqual(gv.var_key('a'), 'var_a')
コード例 #23
0
 def test__resubst_2(self):
     """GVars._resubst('foo bar', {'foo' : 'XFOO'}) should be 'foo bar'"""
     self.assertEqual(GVars._resubst('foo bar', {'foo' : 'XFOO'}), 'foo bar')
コード例 #24
0
 def test__build_resubst_dict_1(self):
     """GVars._build_resubst_dict({}) should == {}"""
     self.assertEqual(GVars._build_resubst_dict({}),{})
コード例 #25
0
 def test_get_xxx_key_ENV_a(self):
     """_GVars(gdecls).get_xxx_key(ENV, 'a') should == 'env_a'"""
     gv = GVars._GVars(self._gdecls_mock_4())
     self.assertEqual(gv.get_xxx_key(GVars.ENV, 'a'), 'env_a')
コード例 #26
0
 def test__resubst_1(self):
     """GVars._resubst('foo bar') should be 'foo bar'"""
     self.assertEqual(GVars._resubst('foo bar'), 'foo bar')
コード例 #27
0
 def test__resubst_8(self):
     """GVars._resubst('${foo} ${bar}', {'foo' : '${bar}', 'bar' : 'XBAR'}) should be '${bar} XBAR'"""
     self.assertEqual(GVars._resubst('${foo} ${bar}', {'foo' : '${bar}', 'bar' : 'XBAR'}), '${bar} XBAR')
コード例 #28
0
 def test_get_xxx_key_OPT_a(self):
     """_GVars(gdecls).get_xxx_key(OPT, 'a') should == 'opt_a'"""
     gv = GVars._GVars(self._gdecls_mock_4())
     self.assertEqual(gv.get_xxx_key(GVars.OPT, 'a'), 'opt_a')
コード例 #29
0
 def test__build_resubst_dict_2(self):
     """GVars._build_resubst_dict({'xxx' : 'yyy', 'vvv' : 'www'}) should == {'xxx' : '${yyy}', 'vvv' : '${www}'}"""
     self.assertEqual(GVars._build_resubst_dict({'xxx' : 'yyy', 'vvv' : 'www'}), {'xxx' : '${yyy}', 'vvv' : '${www}'})
コード例 #30
0
 def test_env_key_a(self):
     """_GVars(gdecls).env_key('a') should == 'env_a'"""
     gv = GVars._GVars(self._gdecls_mock_4())
     self.assertEqual(gv.env_key('a'), 'env_a')