Esempio n. 1
0
 def test__load_dict_decl_14(self):
     """Test SConsArguments.Importer._load_dict_decl('foo', {}, nameconv = 'bleah')"""
     with self.assertRaisesRegexp(
             TypeError,
             "The nameconv must be an instance of _ArgumentNameConv, not %r"
             % 'bleah'):
         tested._load_dict_decl('foo', {}, nameconv='bleah')
Esempio n. 2
0
 def test__load_dict_decl_13(self):
     """Test SConsArguments.Importer._load_dict_decl('foo', decli, option_transform = False)"""
     decli = {
         'env_key': 'env_foo',
         'var_key': 'var_foo',
         'opt_key': 'opt_foo',
         'option': '--option-foo'
     }
     declo = tested._load_dict_decl('foo', decli, option_transform=False)
     xpct = {
         'env_key': 'env_foo',
         'var_key': 'var_foo',
         'opt_key': 'opt_foo',
         'option': '--option-foo'
     }
     self.assertEqual(xpct, declo)
     #
     decli = {
         'env_key': 'env_foo',
         'var_key': 'var_foo',
         'opt_key': 'opt_foo'
     }
     declo = tested._load_dict_decl('foo', decli, option_transform=False)
     xpct = {
         'env_key': 'env_foo',
         'var_key': 'var_foo',
         'opt_key': 'opt_foo'
     }
     self.assertEqual(xpct, declo)
Esempio n. 3
0
    def test__initDefaultArgpath_3(self):
        """Test SConsArguments.Importer._initDefaultArgpath()"""
        def get_option(name):
            if name == 'site_dir':
                return 'site_scons'
            else:
                return None

        def handle_dir(topdir, site_dir):
            tested._defaultArgpath.append(topdir + '/' + site_dir)

        with self.mocks1() as m:

            m.GetOption.side_effect = get_option
            m._handle_site_scons_dir.side_effect = handle_dir

            tested._defaultArgpath = None
            tested._initDefaultArgpath()

            m._handle_site_scons_dir.assert_called_once_with(
                'topdir/path', 'site_scons')
            m._handle_all_site_scons_dirs.assert_not_called()

            self.assertIsInstance(tested._defaultArgpath, list)
            self.assertEqual(tested._defaultArgpath,
                             ['topdir/path/site_scons'])
Esempio n. 4
0
    def test__handle_all_site_scons_dirs_win32(self):

        _defaultArgpath = []

        def _handle_site_scons_dir(topdir):
            _defaultArgpath.insert(
                0, os.path.join(topdir, 'site_scons', 'site_arguments'))

        env = self.fakeEnv('win32')
        with mock.patch('SCons.Platform.platform_default', return_value='win32'), \
             mock.patch('os.path.expandvars', side_effect = lambda x : self.expandvars('win32', x)), \
             mock.patch('os.path.expanduser', side_effect = lambda x : self.expanduser('win32', x)), \
             mock.patch('os.path.join', side_effect = lambda *x : self.pathjoin('win32', *x)), \
             mock.patch('SConsArguments.Importer._handle_site_scons_dir', side_effect = _handle_site_scons_dir):

            tested._handle_all_site_scons_dirs('C:\\Users\\ptomulik\\foo')
            self.assertEqual(_defaultArgpath, [
                'C:\\Users\\ptomulik\\foo\\site_scons\\site_arguments',
                'C:\\Users\\ptomulik\\home\\.scons\\site_scons\\site_arguments',
                '%s\\scons\\site_scons\\site_arguments' % env['$APPDATA'],
                '%s\\Local Settings\\Application Data\\scons\\site_scons\\site_arguments'
                % env['$USERPROFILE'],
                '%s\\Application Data\\scons\\site_scons\\site_arguments' %
                env['$ALLUSERSPROFILE']
            ])
Esempio n. 5
0
 def test__handle_site_scons_dir_4(self):
     """Test SConsArguments.Importer._handle_site_scons_dir()"""
     with mock.patch('os.path.exists', return_value = False), \
          mock.patch('os.path.join', side_effect = lambda *args : '/'.join(args)):
         with self.assertRaisesRegexp(SCons.Errors.UserError,
                                      "site dir top/dir/mysite not found"):
             tested._defaultArgpath = ['initial']
             tested._handle_site_scons_dir('top/dir', 'mysite')
Esempio n. 6
0
 def test__handle_site_scons_dir_3(self):
     """Test SConsArguments.Importer._handle_site_scons_dir()"""
     with mock.patch('os.path.exists', return_value=True):
         tested._defaultArgpath = ['initial']
         tested._handle_site_scons_dir('top/dir', 'mysite')
         self.assertEqual(
             tested._defaultArgpath,
             [os.path.abspath('top/dir/mysite/site_arguments'), 'initial'])
Esempio n. 7
0
 def test__load_decl__dict_2(self):
     """Test _load_decl('foo', {'help' : 'This is foo'}) using mocks"""
     with mock.patch('SConsArguments.Importer.DeclareArgument', side_effect = SConsArguments.Declaration.DeclareArgument) as mock_DeclareArgument, \
          mock.patch('SConsArguments.Importer._load_dict_decl', side_effect = tested._load_dict_decl) as mock_load_dict_decl:
         tested._load_decl('foo', {'help': 'This is foo'})
         mock_load_dict_decl.assert_called_once_with(
             'foo', {'help': 'This is foo'})
         mock_DeclareArgument.assert_called_once_with(env_key='foo',
                                                      help='This is foo',
                                                      var_key='foo')
Esempio n. 8
0
 def test__import_argmod_3(self):
     """Test SConsArguments.Importer._import_argmod('foo')"""
     with mock.patch('SConsArguments.Importer.GetDefaultArgpath') as mock_GetDefaultArgpath, \
          mock.patch('SConsArguments.Importer._load_module_file') as mock_load_module_file:
         mock_GetDefaultArgpath.return_value = ['site_scons/site_arguments']
         mock_load_module_file.side_effect = ImportError
         oldpath = sys.path
         with self.assertRaisesRegexp(RuntimeError,
                                      "No module named %s :" % 'foo'):
             tested._import_argmod('foo')
         self.assertEqual(sys.path, oldpath)
Esempio n. 9
0
 def test_export_arguments_10(self):
     groups = self.groupsFixture
     arguments = self.argsFixture
     expected = arguments
     result = tested.export_arguments('foomod',
                                      arguments,
                                      groups,
                                      exclude_groups=['inexistent'])
     self.assertEqual(result, expected)
     result = tested.export_arguments('foomod',
                                      arguments,
                                      groups,
                                      foomod_exclude_groups=['inexistent'])
     self.assertEqual(result, expected)
Esempio n. 10
0
    def test__initDefaultArgpath_1(self):
        """Test SConsArguments.Importer._initDefaultArgpath()"""
        with self.mocks1() as m:

            m.GetOption.return_value = None

            tested._defaultArgpath = None
            tested._initDefaultArgpath()

            m._handle_site_scons_dir.assert_not_called()
            m._handle_all_site_scons_dirs.assert_called_once_with(
                'topdir/path')

            self.assertIsInstance(tested._defaultArgpath, list)
            self.assertEqual(tested._defaultArgpath, [])
Esempio n. 11
0
 def test__load_decl__dict_3(self):
     """Test _load_decl('foo', {'help' : 'This is foo'}, preprocessor = ...) using mocks"""
     with mock.patch('SConsArguments.Importer.DeclareArgument', side_effect = SConsArguments.Declaration.DeclareArgument) as mock_DeclareArgument, \
          mock.patch('SConsArguments.Importer._load_dict_decl', side_effect = tested._load_dict_decl) as mock_load_dict_decl:
         tested._load_decl('foo', {'help': 'This is foo'},
                           preprocessor=lambda x: dict(x.items(
                           ) + {'env_key': 'env_foo'}.items()))
         mock_load_dict_decl.assert_called_once_with(
             'foo', {
                 'help': 'This is foo',
                 'env_key': 'env_foo'
             })
         mock_DeclareArgument.assert_called_once_with(env_key='env_foo',
                                                      help='This is foo',
                                                      var_key='foo')
Esempio n. 12
0
 def test_export_arguments_5(self):
     groups = self.groupsFixture
     arguments = self.argsFixture
     expected = {k: arguments[k] for k in (groups['g1'] + groups['g2'])}
     result = tested.export_arguments('foomod',
                                      arguments,
                                      groups,
                                      include_groups=['g1', 'g2'])
     self.assertEqual(result, expected)
     result = tested.export_arguments('foomod',
                                      arguments,
                                      groups,
                                      foomod_include_groups=['g1', 'g2'],
                                      include_groups='g3')
     self.assertEqual(result, expected)
Esempio n. 13
0
 def test_ImportArguments_2(self):
     """Test ImportArguments()"""
     with mock.patch('SConsArguments.Importer._import_argmod') as mock_import_argmod, \
          mock.patch('SConsArguments.Importer._load_decls', side_effect = tested._load_decls) as mock_load_decls:
         mock_mod = mock.MagicMock()
         mock_mod.arguments = mock.MagicMock()
         mock_mod.arguments.return_value = {
             'arg1': {
                 'help': 'This is arg1'
             }
         }
         mock_import_argmod.return_value = mock_mod
         declo = tested.ImportArguments('foomod', ['foo/bar'],
                                        name_filter=['arg1', 'baaz'],
                                        foo='FOO')
         self.assertEqual(declo['arg1'].get_var_decl()['help'],
                          'This is arg1')
         mock_import_argmod.assert_called_once_with('foomod', ['foo/bar'])
         mock_load_decls.assert_called_once_with(
             {'arg1': {
                 'help': 'This is arg1'
             }},
             name_filter=['arg1', 'baaz'],
             foo='FOO')
         mock_mod.arguments.assert_called_once_with(
             name_filter=['arg1', 'baaz'], foo='FOO')
Esempio n. 14
0
 def test__load_dict_decl_5(self):
     """Test SConsArguments.Importer._load_dict_decl('foo', decli, nameconv = nc)"""
     nc = tested._ArgumentNameConv()
     decli = {
         'env_key': 'env_foo',
         'var_key': 'var_foo',
         'opt_key': 'opt_foo',
         'option': '--option-foo'
     }
     declo = tested._load_dict_decl('foo', decli, nameconv=nc)
     xpct = {
         'env_key': 'foo',
         'var_key': 'foo',
         'opt_key': 'foo',
         'option': '--foo'
     }
     self.assertEqual(xpct, declo)
Esempio n. 15
0
 def test_export_arguments_7(self):
     groups = self.groupsFixture
     arguments = self.argsFixture
     expected = {
         k: arguments[k]
         for k in (set(arguments.keys()) - set(groups['g2']))
     }
     result = tested.export_arguments('foomod',
                                      arguments,
                                      groups,
                                      exclude_groups='g2')
     self.assertEqual(result, expected)
     result = tested.export_arguments('foomod',
                                      arguments,
                                      groups,
                                      foomod_exclude_groups='g2',
                                      exclude_groups='g1')
     self.assertEqual(result, expected)
Esempio n. 16
0
 def test_export_arguments_2(self):
     groups = self.groupsFixture
     arguments = self.argsFixture
     expected = dict()
     result = tested.export_arguments('foomod',
                                      arguments,
                                      groups,
                                      include_groups=[])
     self.assertEqual(result, expected)
Esempio n. 17
0
    def test_GetDefaultArgpath_2(self):
        """Test SConsArguments.Importer.GetDefaultArgpath() using mocks"""
        def init_argpath():
            tested._defaultArgpath = ['bar']

        with mock.patch('SConsArguments.Importer._initDefaultArgpath',
                        side_effect=init_argpath) as m:
            tested._defaultArgpath = None
            self.assertEqual(tested.GetDefaultArgpath(), ['bar'])
            m.assert_called_once_with()
Esempio n. 18
0
 def test__load_dict_decl_4(self):
     """Test SConsArguments.Importer._load_dict_decl('foo', decli)"""
     decli = {
         'env_key': 'env_foo',
         'var_key': 'var_foo',
         'opt_key': 'opt_foo',
         'option': '--option-foo'
     }
     declo = tested._load_dict_decl('foo', decli)
     self.assertEqual(decli, declo)
Esempio n. 19
0
 def test__import_argmod_2(self):
     """Test SConsArguments.Importer._import_argmod('foo')"""
     with mock.patch('SConsArguments.Importer.GetDefaultArgpath',) as mock_GetDefaultArgpath, \
          mock.patch('SConsArguments.Importer._load_module_file') as mock_load_module_file:
         mock_GetDefaultArgpath.return_value = ['site_scons/site_arguments']
         mock_load_module_file.return_value = 'xyz'
         oldpath = sys.path
         mod = tested._import_argmod('foo')
         self.assertEqual(mod, 'xyz')
         self.assertEqual(sys.path, oldpath)
Esempio n. 20
0
    def test__initDefaultArgpath_2(self):
        """Test SConsArguments.Importer._initDefaultArgpath()"""
        def get_option(name):
            if name == 'no_site_dir':
                return True
            else:
                return None

        with self.mocks1() as m:

            m.GetOption.side_effect = get_option

            tested._defaultArgpath = None
            tested._initDefaultArgpath()

            m._handle_site_scons_dir.assert_not_called()
            m._handle_all_site_scons_dirs.assert_not_called()

            self.assertIsInstance(tested._defaultArgpath, list)
            self.assertEqual(tested._defaultArgpath, [])
Esempio n. 21
0
 def test__load_module_file_py33(self):
     "Test SConsArguments.Importer._load_module_file() with python 3.3"
     m_file = mock.MagicMock()
     with mock.patch('sys.version_info', new = (3,3)), \
          mock.patch('imp.find_module', return_value = (m_file, 'p', 'd')) as m_find_module, \
          mock.patch('imp.load_module', return_value = 'mod') as m_load_module:
         self.assertEqual(tested._load_module_file('mymod', 'my/path'),
                          'mod')
         m_find_module.assert_called_once_with('mymod', 'my/path')
         m_load_module.assert_called_once_with('mymod', m_file, 'p', 'd')
         m_file.close.assert_called_once_with()
Esempio n. 22
0
 def test__import_argmod_4(self):
     """Test SConsArguments.Importer._import_argmod(...)"""
     def fake_load_module_file(modname, path=None):
         if path == ['SConsArguments'] and modname == 'foo':
             return 'SConsArguments.foo'
         else:
             raise ImportError("bleah")
     with mock.patch('SConsArguments.Importer.GetDefaultArgpath') as mock_GetDefaultArgpath, \
          mock.patch('SConsArguments.Importer._load_module_file') as mock_load_module_file:
         mock_GetDefaultArgpath.return_value = ['site_scons/site_arguments']
         mock_load_module_file.side_effect = fake_load_module_file
         oldpath = sys.path
         with self.assertRaisesRegexp(
                 RuntimeError,
                 "No module named %s : %s" % ('bar', 'bleah')):
             tested._import_argmod('bar')
         self.assertEqual(sys.path, oldpath)
         oldpath = sys.path
         self.assertEqual(tested._import_argmod('foo'),
                          'SConsArguments.foo')
         self.assertEqual(sys.path, oldpath)
Esempio n. 23
0
    def test__handle_all_site_scons_dirs_other(self):

        _defaultArgpath = []

        def _handle_site_scons_dir(topdir):
            _defaultArgpath.insert(
                0, os.path.join(topdir, 'site_scons', 'site_arguments'))

        env = self.fakeEnv('other')
        with mock.patch('SCons.Platform.platform_default', return_value='other'), \
             mock.patch('os.path.expandvars', side_effect = lambda x : self.expandvars('other', x)), \
             mock.patch('os.path.expanduser', side_effect = lambda x : self.expanduser('other', x)), \
             mock.patch('os.path.join', side_effect = lambda *x : self.pathjoin('other', *x)), \
             mock.patch('SConsArguments.Importer._handle_site_scons_dir', side_effect = _handle_site_scons_dir):

            tested._handle_all_site_scons_dirs('/home/ptomulik/foo')
            self.assertEqual(_defaultArgpath, [
                '/home/ptomulik/foo/site_scons/site_arguments',
                '/home/ptomulik/.scons/site_scons/site_arguments',
                '/usr/share/scons/site_scons/site_arguments'
            ])
Esempio n. 24
0
 def test__load_decls_2(self):
     """Test SConsArguments.Importer._load_decls({'arg1' : {...}})"""
     declo = tested._load_decls({
         'arg1': {
             'help': 'This is arg1'
         },
         'arg2': {
             'help': 'This is arg2'
         }
     })
     self.assertIsInstance(
         declo, SConsArguments.Declarations._ArgumentDeclarations)
     self.assertEqual(declo['arg1'].get_var_decl()['help'], 'This is arg1')
     self.assertEqual(declo['arg2'].get_var_decl()['help'], 'This is arg2')
Esempio n. 25
0
 def test__load_decls_6(self):
     """Test SConsArguments.Importer._load_decls({'arg1' : {...}}, name_filter = set(...))"""
     decli = {
         'arg1': {
             'help': 'This is arg1'
         },
         'arg2': {
             'help': 'This is arg2'
         }
     }
     declo = tested._load_decls(decli, name_filter={'arg1', 'foo'})
     self.assertIsInstance(
         declo, SConsArguments.Declarations._ArgumentDeclarations)
     self.assertEqual(declo['arg1'].get_var_decl()['help'], 'This is arg1')
     self.assertFalse('arg2' in declo)
Esempio n. 26
0
 def test__load_decls_3(self):
     """Test SConsArguments.Importer._load_decls({'arg1' : {...}}, name_filter = lambda x : ...)"""
     declo = tested._load_decls(
         {
             'arg1': {
                 'help': 'This is arg1'
             },
             'arg2': {
                 'help': 'This is arg2'
             }
         },
         name_filter=lambda x: (x == 'arg1'))
     self.assertIsInstance(
         declo, SConsArguments.Declarations._ArgumentDeclarations)
     self.assertEqual(declo['arg1'].get_var_decl()['help'], 'This is arg1')
     self.assertFalse('arg2' in declo)
Esempio n. 27
0
    def test__load_module_file_py34(self):
        "Test SConsArguments.Importer._load_module_file() with python 3.4"

        find_spec0 = mock.MagicMock(return_value=None)
        finder0 = mock.MagicMock(find_spec=find_spec0, loader=mock.MagicMock())

        spec1 = mock.MagicMock(loader=mock.MagicMock(), __str__='spec1')
        find_spec1 = mock.MagicMock(return_value=spec1)
        finder1 = mock.MagicMock(find_spec=find_spec1)

        with mock.patch('sys.version_info', new = (3,4)), \
             mock.patch('sys.meta_path', new = [ finder0, finder1, finder0 ]), \
             mock.patch('importlib.util.module_from_spec', side_effect = lambda x : 'mod_%s' % x) as m_module_from_spec:
            self.assertEqual(tested._load_module_file('mymod', 'my/path'),
                             'mod_spec1')
            m_module_from_spec.assert_called_once_with('spec1')
            finder1.loader.exec_module.assert_called_once_with('mod_spec1')
Esempio n. 28
0
 def test__load_dict_decl_3(self):
     """Test SConsArguments.Importer._load_dict_decl('foo',{'help' : 'Argument foo'}, nameconv = nc)"""
     nc = tested._ArgumentNameConv()
     decl = tested._load_dict_decl('foo', {'help': 'Argument foo'},
                                   nameconv=nc)
     xpct = {
         'env_key': 'foo',
         'var_key': 'foo',
         'opt_key': 'foo',
         'option': '--foo',
         'help': 'Argument foo'
     }
     self.assertEqual(xpct, decl)
     #
     nc = tested._ArgumentNameConv(env_key_prefix='env_',
                                   var_key_prefix='var_',
                                   opt_key_prefix='opt_')
     decl = tested._load_dict_decl('foo', {'help': 'Argument foo'},
                                   nameconv=nc)
     xpct = {
         'env_key': 'env_foo',
         'var_key': 'var_foo',
         'opt_key': 'opt_foo',
         'option': '--foo',
         'help': 'Argument foo'
     }
     self.assertEqual(xpct, decl)
     # NameConv shall override some entries preset in decli...
     nc = tested._ArgumentNameConv(env_key_prefix='env_',
                                   var_key_prefix='var_',
                                   opt_key_prefix='opt_')
     decli = {
         'env_key': 'foo_env',
         'var_key': 'foo_var',
         'opt_key': 'foo_opt',
         'help': 'Argument foo'
     }
     declo = tested._load_dict_decl('foo', decli, nameconv=nc)
     xpct = {
         'env_key': 'env_foo',
         'var_key': 'var_foo',
         'opt_key': 'opt_foo',
         'option': '--foo',
         'help': 'Argument foo'
     }
     self.assertEqual(xpct, declo)
Esempio n. 29
0
 def test__import_argmod_1(self):
     """Test SConsArguments.Importer._import_argmod(sys)"""
     oldpath = sys.path
     mod = tested._import_argmod(sys)
     self.assertEqual(mod, sys)
Esempio n. 30
0
 def test__load_decls_1(self):
     """SConsArguments.Importer._load_decls('foo') should raise TypeError"""
     with self.assertRaisesRegexp(
             TypeError,
             "Can not load arguments from %r object" % type('foo')):
         tested._load_decls('foo')