Beispiel #1
0
    def testGetWithFlags(self):
        '''
        Test get with flags
        '''
        ns = Namespace()
        ns._DeclareFlag('win32', 'Windows-OS')

        ns['lib_dir'] = 'lib'
        ns['win32:lib_dir'] = 'lib/win32'
        assert ns.GetValue('lib_dir', as_string=True) == 'lib'
        assert ns.GetValue('win32:lib_dir', as_string=True) == 'lib/win32'

        ns['win32:lib_dir'] = 'library/windows'
        assert ns.GetValue('lib_dir', as_string=True) == 'lib'
        assert ns.GetValue('win32:lib_dir', as_string=True) == 'library/windows'

        ns['win32:lib_dir'] = 'lib-w32'
        assert ns.GetValue('lib_dir', as_string=True) == 'lib'
        assert ns.GetValue('win32:lib_dir', as_string=True) == 'lib-w32'

        # Indirect flagged value
        ns['win32:lib_dir'] = 'lib-w32'
        ns['lib_dir2'] = 'LIB `lib_dir`'

        assert ns.GetValue('lib_dir2', as_string=True) == 'LIB lib'
        assert ns.GetValue('win32:lib_dir2', as_string=True) == 'LIB lib-w32'
Beispiel #2
0
    def testVariableNotFound(self):
        ns = Namespace()
        with pytest.raises(NamespaceKeyError):
            ns.GetValue('alpha')

        ns._DeclareFlag('win32', 'Platform flag for all Windows systems.')
        ns['win32:alpha'] = 'Alpha'

        with pytest.raises(NamespaceKeyError):
            ns.GetValue('alpha')
Beispiel #3
0
    def testFlagsDeclaration(self):
        '''
        Test the declaration of flags and the error raised when trying to declare a variable
        using an undeclared flag.
        '''
        ns = Namespace()
        ns['name'] = 'alpha-flagless'

        # Declare the flag and then declare the name using it.
        ns._DeclareFlag('win32', 'Platform flag for all Windows systems.')
        ns['win32:name'] = 'alpha-w32'
Beispiel #4
0
    def testNegativeFlags(self):
        '''
        Using negative flags
        '''
        ns = Namespace(flags=['win32'])
        ns._DeclareFlag('win32', 'Windows-OS')
        ns['win32:variable'] = 'Windows'
        ns['!win32:variable'] = 'NotWindows'
        assert ns.GetValue('variable', as_string=True) == 'Windows'

        ns = Namespace()
        ns._DeclareFlag('win32', 'Windows-OS')
        ns['win32:variable'] = 'Windows'
        ns['!win32:variable'] = 'NotWindows'
        assert ns.GetValue('variable', as_string=True) == 'NotWindows'
Beispiel #5
0
    def testPrint(self):
        ns = Namespace(flags=['win32'])
        ns._DeclareFlag('win32', 'Windows-OS')
        ns._DeclareFlag('mac', 'Mac-OS')
        ns['alpha'] = 'Alpha'
        ns['win32:alpha'] = 'Alpha-W32'
        ns['mac:alpha'] = 'Alpha-MAC'

        oss = StringIO()
        ns.Print(oss)

        assert (
            oss.getvalue()
            == '\n'
            '  alpha = STRING:Alpha\n'
            '        = (mac) STRING:Alpha-MAC\n'
            '        = (win32) STRING:Alpha-W32\n'
        )

        oss = StringIO()
        ns.Print(oss, evaluate=True)
        assert (
            oss.getvalue()
            == '\n'
            '  alpha = Alpha-W32\n'
        )

        oss = StringIO()
        ns.PrintDeclaredFlags(oss)
        assert (
            oss.getvalue()
            == '\n'
            '  mac = Mac-OS\n'
            '  win32 = Windows-OS\n',
        )

        oss = StringIO()
        ns.PrintImplicitFlags(oss)
        assert (
            oss.getvalue()
            == '\n'
            '  win32\n',
        )
Beispiel #6
0
    def testEvaluateFlags(self):
        ns = Namespace(flags=['win32', 'other_flag'])
        ns._DeclareFlag('other_flag', 'Flag for testing')
        ns._DeclareFlag('win32', 'Windows-OS')
        ns._DeclareFlag('linux', 'Linux-OS')

        assert ns.EvaluateFlags('')
        assert ns.EvaluateFlags('win32')
        assert ns.EvaluateFlags('win32:other_flag')
        assert not ns.EvaluateFlags('!win32')