Exemplo n.º 1
0
    def test_linux_no_lsb(self):
        def bad_lsb(*args, **kwargs):
            raise OSError()

        with mock.patch('platform.system', return_value='Linux'), \
             mock.patch('subprocess.check_output', bad_lsb):  # noqa
            self.assertEqual(platforms.platform_name(), 'linux')
Exemplo n.º 2
0
    def test_windows(self):
        def mock_execute(*args, **kwargs):
            raise OSError()

        with mock.patch('platform.system', return_value='Windows'), \
             mock.patch('subprocess.check_output', mock_execute):  # noqa:
            self.assertEqual(platforms.platform_name(), 'windows')
Exemplo n.º 3
0
    def test_upgrade_from_v4(self):
        env = Environment.load(os.path.join(test_data_dir, 'environment',
                                            'v4'),
                               save_on_upgrade=False)

        self.assertEqual(env.bfgdir, Path('/path/to', Root.absolute))
        self.assertEqual(env.backend, 'make')

        self.assertEqual(env.srcdir, Path('/root/srcdir', Root.absolute))
        self.assertEqual(env.builddir, Path('/root/builddir', Root.absolute))
        self.assertDictsEqual(
            env.install_dirs, {
                InstallRoot.prefix: Path('/root/prefix', Root.absolute),
                InstallRoot.exec_prefix: Path('', InstallRoot.prefix),
                InstallRoot.bindir: Path('bin', InstallRoot.exec_prefix),
                InstallRoot.libdir: Path('lib', InstallRoot.exec_prefix),
                InstallRoot.includedir: Path('include', InstallRoot.prefix),
            })

        self.assertEqual(env.library_mode, LibraryMode(True, False))
        self.assertEqual(env.extra_args, [])

        variables = {u'HOME': u'/home/user'}
        if platform_name() == 'windows' and sys.version_info[0] == 2:
            variables = {str(k): str(v) for k, v in iteritems(variables)}
        self.assertEqual(env.variables, variables)

        self.assertEqual(env.host_platform.name, 'linux')
        self.assertEqual(env.target_platform.name, 'linux')
Exemplo n.º 4
0
 def test_write_jbos_shell(self):
     out = Writer(StringIO())
     s = safe_str.jbos('$foo', safe_str.escaped_str('$bar'))
     out.write(s, Syntax.shell)
     if platform_name() == 'windows':
         expected = '$$foo$bar'
     else:
         expected = quoted('$$foo') + '$bar'
     self.assertEqual(out.stream.getvalue(), expected)
Exemplo n.º 5
0
def shared_library(name, version=None):
    head, tail = os.path.split(name)
    ext = platform_info().shared_library_ext
    if version:
        if not platform_info().has_versioned_library:
            raise ValueError('no versioned libraries on this platform')
        if platform_name() == 'darwin':
            tail += '.' + version
        else:
            ext += '.' + version
    return Target(name, os.path.normpath(os.path.join(
        '.', head, _library_prefix + tail + ext
    )))
Exemplo n.º 6
0
    def test_realize_absolute(self):
        p = Path('/foo/bar', Root.builddir)
        self.assertEqual(p.realize(path_variables),
                         os.path.join(os.path.sep, 'foo', 'bar'))
        self.assertEqual(p.realize(path_variables, executable=True),
                         os.path.join(os.path.sep, 'foo', 'bar'))

        if platform_name() == 'windows':
            p = Path(r'C:\foo\bar', Root.builddir)
            self.assertEqual(p.realize(path_variables),
                             os.path.join('C:', os.path.sep, 'foo', 'bar'))
            self.assertEqual(p.realize(path_variables, executable=True),
                             os.path.join('C:', os.path.sep, 'foo', 'bar'))
Exemplo n.º 7
0
 def test_android(self):
     with mock.patch('platform.system', return_value='Linux'), \
          mock.patch('subprocess.check_output',
                     return_value='Android'):  # noqa
         self.assertEqual(platforms.platform_name(), 'android')
Exemplo n.º 8
0
import os
import unittest
from six.moves import cStringIO as StringIO

from bfg9000 import path
from bfg9000 import safe_str
from bfg9000.backends.ninja.syntax import *
from bfg9000.platforms import platform_name

quote_char = '"' if platform_name() == 'windows' else "'"


def quoted(s):
    return quote_char + s + quote_char


class TestNinjaWriter(unittest.TestCase):
    # strings
    def test_write_string_output(self):
        out = Writer(StringIO())
        out.write('foo: $bar', Syntax.output)
        self.assertEqual(out.stream.getvalue(), 'foo$:$ $$bar')

    def test_write_string_input(self):
        out = Writer(StringIO())
        out.write('foo: $bar', Syntax.input)
        self.assertEqual(out.stream.getvalue(), 'foo:$ $$bar')

    def test_write_string_shell(self):
        out = Writer(StringIO())
        out.write('foo: $bar', Syntax.shell)
Exemplo n.º 9
0
 def test_unknown(self):
     with mock.patch('platform.system', return_value='Goofy'):
         self.assertEqual(platforms.platform_name(), 'goofy')
Exemplo n.º 10
0
 def test_cygwin_native_python(self):
     with mock.patch('platform.system', return_value='Windows'), \
          mock.patch('subprocess.check_output',
                     return_value='CYGWIN_NT-6.1-WOW64'):  # noqa
         self.assertEqual(platforms.platform_name(), 'cygwin')
Exemplo n.º 11
0
 def test_cygwin(self):
     with mock.patch('platform.system', return_value='CYGWIN_NT-6.1-WOW64'):
         self.assertEqual(platforms.platform_name(), 'cygwin')
Exemplo n.º 12
0
 def test_windows_with_uname(self):
     with mock.patch('platform.system', return_value='Windows'), \
          mock.patch('platform.version', return_value='10'), \
          mock.patch('subprocess.check_output',
                     return_value='foobar'):  # noqa:
         self.assertEqual(platforms.platform_name(), 'winnt')
Exemplo n.º 13
0
 def test_ios(self):
     with mock.patch('platform.system', return_value='Darwin'), \
          mock.patch('platform.machine', return_value='iPhone'):  # noqa
         self.assertEqual(platforms.platform_name(), 'ios')
Exemplo n.º 14
0
 def test_macos(self):
     with mock.patch('platform.system', return_value='Darwin'):
         self.assertEqual(platforms.platform_name(), 'macos')
Exemplo n.º 15
0
 def test_linux(self):
     with mock.patch('platform.system', return_value='Linux'):
         self.assertEqual(platforms.platform_name(), 'linux')
Exemplo n.º 16
0
 def test_info(self):
     self.assertEqual(platforms.platform_tuple()[1],
                      platforms.platform_name())
Exemplo n.º 17
0
import os
import unittest
from six.moves import cStringIO as StringIO

from bfg9000 import path
from bfg9000 import safe_str
from bfg9000.backends.make.syntax import *
from bfg9000.platforms import platform_name

esc_colon = ':' if platform_name() == 'windows' else '\\:'


def quoted(s):
    return "'" + s + "'"


class TestMakeWriter(unittest.TestCase):
    # strings
    def test_write_string_target(self):
        out = Writer(StringIO())
        out.write('foo: $bar|baz,quux', Syntax.target)
        self.assertEqual(out.stream.getvalue(),
                         'foo' + esc_colon + '\\ $$bar|baz,quux')

    def test_write_string_dependency(self):
        out = Writer(StringIO())
        out.write('foo: $bar|baz,quux', Syntax.dependency)
        self.assertEqual(out.stream.getvalue(),
                         'foo' + esc_colon + '\\ $$bar\\|baz,quux')

    def test_write_string_function(self):
Exemplo n.º 18
0
def xfail_if_platform(platform):
    return xfail_if(platform_name() == platform)