diff options
author | Andoni Morales Alastruey <ylatuya@gmail.com> | 2012-07-13 19:42:40 +0200 |
---|---|---|
committer | Andoni Morales Alastruey <ylatuya@gmail.com> | 2012-08-08 13:02:27 +0200 |
commit | 3aa0eefa960e4ff6cb912b8639e91f535fefd08a (patch) | |
tree | 395023b179459f6bb75f09b5d74ef8cf2004816a /test/test_cerbero_build_build.py | |
parent | a650cb1315643c7fd3ec247a535f5c10456db73c (diff) |
Add an easier way to modify the environment in recipes
Diffstat (limited to 'test/test_cerbero_build_build.py')
-rw-r--r-- | test/test_cerbero_build_build.py | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/test/test_cerbero_build_build.py b/test/test_cerbero_build_build.py new file mode 100644 index 00000000..b7102080 --- /dev/null +++ b/test/test_cerbero_build_build.py @@ -0,0 +1,89 @@ +# cerbero - a multi-platform build system for Open Source software +# Copyright (C) 2012 Andoni Morales Alastruey <ylatuya@gmail.com> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +import unittest +import os + +from test.test_common import DummyConfig +from cerbero.build import build + + +class MakefilesBase(build.MakefilesBase): + + srcdir = '' + build_dir = '' + + def __init__(self, config): + self.config = config + build.MakefilesBase.__init__(self) + + @build.modify_environment + def get_env_var(self, var): + if var not in os.environ: + return None + return os.environ[var] + + @build.modify_environment + def get_env_var_nested(self, var): + return self.get_env_var(var) + + +class ModifyEnvTest(unittest.TestCase): + + def setUp(self): + self.var = 'TEST_VAR' + self.val1 = 'test' + self.val2 = 'test2' + self.mk = MakefilesBase(DummyConfig()) + + def testAppendEnv(self): + os.environ[self.var] = self.val1 + self.mk.append_env = {self.var: self.val2} + val = self.mk.get_env_var(self.var) + self.assertEquals(val, self.val1 + self.val2) + + def testNewEnv(self): + os.environ[self.var] = self.val1 + self.mk.new_env = {self.var: self.val2} + val = self.mk.get_env_var(self.var) + self.assertEquals(val, self.val2) + + def testAppendAndNewEnv(self): + os.environ[self.var] = '' + self.mk.append_env = {self.var: self.val1} + self.mk.new_env = {self.var: self.val2} + val = self.mk.get_env_var(self.var) + self.assertEquals(val, self.val2) + + def testSystemLibs(self): + os.environ['PKG_CONFIG_PATH'] = '/path/1' + os.environ['PKG_CONFIG_LIBDIR'] = '/path/2' + self.mk.config.allow_system_libs = True + self.mk.use_system_libs = True + val = self.mk.get_env_var('PKG_CONFIG_PATH') + self.assertEquals(val, '/path/1:/path/2') + val = self.mk.get_env_var('PKG_CONFIG_LIBDIR') + self.assertIsNone(val) + + def testNestedModif(self): + os.environ[self.var] = self.val1 + self.mk.append_env = {self.var: self.val2} + val = self.mk.get_env_var(self.var) + self.assertEquals(val, self.val1 + self.val2) + val = self.mk.get_env_var_nested(self.var) + self.assertEquals(val, self.val1 + self.val2) |