示例#1
0
 def test_existent(self):
     with mock.patch('bfg9000.path.exists', return_value=True), \
          mock.patch('bfg9000.path.isfile', return_value=True):  # noqa
         self.assertPathEqual(parser.File()('foo'),
                              path.abspath('foo', absdrive=False))
         self.assertPathEqual(
             parser.File(True)('foo'), path.abspath('foo', absdrive=False))
示例#2
0
    def test_install_dirs(self):
        self.builtin_dict['install_dirs'](prefix='/prefix', bindir='/bin/dir')

        self.assertEqual(self.env.install_dirs[InstallRoot.prefix],
                         abspath('/prefix'))
        self.assertEqual(self.env.install_dirs[InstallRoot.bindir],
                         abspath('/bin/dir'))
示例#3
0
 def test_existent(self):
     with mock.patch('bfg9000.path.exists', return_value=True), \
          mock.patch('bfg9000.path.isdir', return_value=True):
         self.assertPathEqual(parser.Directory()('foo'),
                              path.abspath('foo/', absdrive=False))
         self.assertPathEqual(parser.Directory(True)('foo'),
                              path.abspath('foo/', absdrive=False))
示例#4
0
    def test_windows_default_location(self):
        env = make_env('winnt', clear_variables=True)
        boost_incdir = r'C:\Boost\include\boost-1.23'

        def mock_walk(top):
            yield (top, ) + ([('boost-1.23', ntpath.join(top, 'boost-1.23'))
                              ], [])

        def mock_execute(*args, **kwargs):
            if args[0][1] == '/?':
                return 'cl.exe'
            raise ValueError()

        def mock_exists(x):
            if re.search(r'[/\\]boost[/\\]version.hpp$', x):
                return True
            return False

        with mock.patch('bfg9000.builtins.find._walk_flat', mock_walk), \
             mock.patch('bfg9000.builtins.packages._boost_version',
                        return_value=Version('1.23')), \
             mock.patch('bfg9000.shell.which', return_value=['command']), \
             mock.patch('bfg9000.shell.execute', mock_execute), \
             mock.patch('os.path.exists', mock_exists):  # noqa
            pkg = packages.boost_package(env, 'thread')
            self.assertEqual(pkg.name, 'boost(thread)')
            self.assertEqual(pkg.version, Version('1.23'))
            self.assertEqual(
                pkg._compile_options,
                opts.option_list(
                    opts.include_dir(HeaderDirectory(abspath(boost_incdir)))))
            self.assertEqual(
                pkg._link_options,
                opts.option_list(
                    opts.lib_dir(Directory(abspath(r'C:\Boost\lib')))))
示例#5
0
    def test_windows_default_location(self):
        env = make_env('winnt', clear_variables=True)
        context = self._make_context(env)
        boost_incdir = r'C:\Boost\include\boost-1.23'

        def mock_walk(top, variables=None):
            yield top, [top.append('boost-1.23/')], []

        def mock_execute(*args, **kwargs):
            if args[0][1] == '/?':
                return 'cl.exe'
            raise ValueError()

        def mock_exists(x):
            return bool(re.search(r'[/\\]boost[/\\]version.hpp$', x.string()))

        with mock.patch('bfg9000.builtins.find.walk', mock_walk), \
             mock.patch('bfg9000.builtins.packages._boost_version',
                        return_value=Version('1.23')), \
             mock.patch('bfg9000.shell.which', return_value=['command']), \
             mock.patch('bfg9000.shell.execute', mock_execute), \
             mock.patch('bfg9000.tools.msvc.exists', mock_exists):  # noqa
            pkg = context['boost_package']('thread')
            self.assertEqual(pkg.name, 'boost(thread)')
            self.assertEqual(pkg.version, Version('1.23'))
            self.assertEqual(
                pkg._compile_options,
                opts.option_list(
                    opts.include_dir(HeaderDirectory(abspath(boost_incdir)))))
            self.assertEqual(
                pkg._link_options,
                opts.option_list(
                    opts.lib_dir(Directory(abspath(r'C:\Boost\lib')))))
示例#6
0
 def test_pass_builddir(self):
     args = argparse.Namespace()
     with mock.patch('bfg9000.build.is_srcdir', return_value=False):
         self.pair(None, args, path.abspath('foo'))
     self.assertEqual(
         args,
         argparse.Namespace(srcdir=path.abspath('.'),
                            builddir=path.abspath('foo')))
示例#7
0
 def test_drive(self):
     with mock.patch('os.getcwd', return_value=r'C:\base'):
         self.assertEqual(path.abspath('foo'),
                          path.Path('C:/base/foo', path.Root.absolute))
         self.assertEqual(path.abspath('/foo/bar'),
                          path.Path('C:/foo/bar', path.Root.absolute))
         self.assertEqual(path.abspath('D:/foo/bar'),
                          path.Path('D:/foo/bar', path.Root.absolute))
示例#8
0
def make_env(platform=None, clear_variables=False):
    args = (Path('bfgdir', Root.srcdir), None, None, abspath('srcdir'),
            abspath('builddir'), {}, (False, False), None)
    if platform:
        with mock.patch('bfg9000.platforms.host.platform_name',
                        return_value=platform):
            env = Environment(*(args + (platform, )))
    else:
        env = Environment(*args)

    if clear_variables:
        env.variables = {}
    return env
示例#9
0
def make_env(platform=None, clear_variables=False, variables={}):
    args = (Path('bfgdir', Root.srcdir), None, None, abspath('srcdir'),
            abspath('builddir'), {}, (False, False))
    if platform:
        with mock.patch('bfg9000.platforms.core.platform_name',
                        return_value=platform):
            env = Environment(*args)
    else:
        env = Environment(*args)

    if clear_variables:
        env.variables = {}
    env.variables.update(variables)
    return env
示例#10
0
def make_env(platform=None, clear_variables=False, variables={}):
    args = (abspath('bfgdir'), None, None, abspath('srcdir'),
            abspath('builddir'))
    if platform:
        with mock.patch('bfg9000.platforms.core.platform_name',
                        return_value=platform):
            env = Environment(*args)
    else:
        env = Environment(*args)
    env.finalize({InstallRoot.prefix: abspath('prefix')}, (False, False))

    if clear_variables:
        env.variables = {}
    env.variables.update(variables)
    return env
示例#11
0
    def test_abspath(self):
        with mock.patch('os.getcwd', return_value=r'/base'):
            self.assertPathEqual(path.abspath('foo'),
                                 path.Path('/base/foo', path.Root.absolute))
            self.assertPathEqual(path.abspath('/foo/bar'),
                                 path.Path('/foo/bar', path.Root.absolute))

            self.assertPathEqual(path.abspath('foo/'),
                                 path.Path('/base/foo/', path.Root.absolute))
            self.assertPathEqual(path.abspath('/foo/bar/'),
                                 path.Path('/foo/bar/', path.Root.absolute))

            self.assertPathEqual(path.abspath('foo', directory=True),
                                 path.Path('/base/foo/', path.Root.absolute))
            self.assertRaises(ValueError, path.abspath, 'foo/',
                              directory=False)
示例#12
0
    def test_basic(self):
        env, backend = driver.environment_from_args(self.args)
        self.assertEqual(env.srcdir, path.abspath('.'))
        self.assertTrue('make' in backend.__name__)

        driver.finalize_environment(env, self.args)
        self.assertEqual(env.install_dirs, {
            k: getattr(self.args, k.name) for k in path.InstallRoot
        })
示例#13
0
 def setUp(self):
     self.args = argparse.Namespace(
         backend='make',
         srcdir=path.abspath('.'),
         builddir=path.abspath('build'),
         prefix=path.abspath('.'),
         exec_prefix=path.abspath('.'),
         bindir=path.abspath('bin'),
         libdir=path.abspath('lib'),
         includedir=path.abspath('include'),
         datadir=path.abspath('share'),
         mandir=path.abspath('man'),
         shared=True,
         static=False,
         compdb=True,
     )
示例#14
0
    def test_install_path_directory(self):
        p = path.Path('foo/bar', path.Root.srcdir)
        self.assertEqual(path.install_path(p, path.InstallRoot.bindir, True),
                         path.Path('', path.InstallRoot.bindir, True))

        p = path.Path('foo/bar', path.Root.builddir)
        self.assertEqual(path.install_path(p, path.InstallRoot.bindir, True),
                         path.Path('foo/bar', path.InstallRoot.bindir, True))

        p = path.abspath('/foo/bar')
        with self.assertRaises(TypeError):
            path.install_path(p, path.InstallRoot.bindir, True)
示例#15
0
 def test_format(self):
     with mock.patch('bfg9000.builtins.packages.which', mock_which):
         self.assertEqual(
             self.context['system_executable']('name', 'format'),
             file_types.Executable(abspath('/name'), 'format'))
示例#16
0
 def test_abspath(self):
     self.assertEqual(
         path.abspath('/foo/bar'),
         path.Path(os.path.abspath('/foo/bar'), path.Root.absolute))
示例#17
0
 def test_extra_args(self):
     env, backend = driver.environment_from_args(self.args,
                                                 extra_args=['--foo'])
     self.assertEqual(env.srcdir, path.abspath('.'))
     self.assertEqual(env.extra_args, ['--foo'])
     self.assertTrue('make' in backend.__name__)
示例#18
0
 def test_basic(self):
     env, backend = driver.environment_from_args(self.args)
     self.assertEqual(env.srcdir, path.abspath('.'))
     self.assertTrue('make' in backend.__name__)
示例#19
0
 def test_search_dirs_sysroot(self):
     with mock.patch('bfg9000.shell.execute', mock_execute):
         ld = LdLinker(None, self.env, ['ld'], 'version')
         self.assertEqual(ld.search_dirs(sysroot='/sysroot'),
                          [abspath('/dir1'), abspath('/sysroot/dir2')])
示例#20
0
 def test_format(self):
     with mock.patch('bfg9000.builtins.packages.which', mock_which):
         self.assertEqual(
             packages.system_executable(self.env, 'name', 'format'),
             file_types.Executable(abspath('/command'), 'format'))
示例#21
0
 def test_name(self):
     with mock.patch('bfg9000.builtins.packages.which', mock_which):
         self.assertEqual(
             packages.system_executable(self.env, 'name'),
             file_types.Executable(abspath('/command'),
                                   self.env.target_platform.object_format))
示例#22
0
 def test_nonexistent(self):
     with mock.patch('bfg9000.path.exists', return_value=False):
         self.assertPathEqual(parser.Directory()('foo'),
                              path.abspath('foo/', absdrive=False))
         with self.assertRaises(parser.ArgumentTypeError):
             parser.Directory(True)('foo')
示例#23
0
 def test_boost_version_cant_parse(self):
     data = 'foobar\n'
     with mock.patch(mock_open_name, mock_open(read_data=data)):
         hdr = HeaderDirectory(abspath('path'))
         with self.assertRaises(PackageVersionError):
             packages._boost_version(hdr, SpecifierSet(''))
示例#24
0
 def test_boost_version_too_old(self):
     data = '#define BOOST_LIB_VERSION "1_23_4"\n'
     with mock.patch(mock_open_name, mock_open(read_data=data)):
         hdr = HeaderDirectory(abspath('path'))
         with self.assertRaises(PackageVersionError):
             packages._boost_version(hdr, SpecifierSet('>=1.30'))
示例#25
0
 def test_nonexistent(self):
     with mock.patch('bfg9000.path.exists', return_value=False):
         self.assertEqual(parser.File()('foo'), path.abspath('foo'))
         with self.assertRaises(parser.ArgumentTypeError):
             parser.File(True)('foo')
示例#26
0
 def test_existent(self):
     with mock.patch('bfg9000.path.exists', return_value=True), \
          mock.patch('bfg9000.path.isdir', return_value=True):  # noqa
         self.assertEqual(parser.Directory()('foo'), path.abspath('foo'))
         self.assertEqual(
             parser.Directory(True)('foo'), path.abspath('foo'))
示例#27
0
 def test_boost_version(self):
     data = '#define BOOST_LIB_VERSION "1_23_4"\n'
     with mock.patch(mock_open_name, mock_open(read_data=data)):
         hdr = HeaderDirectory(abspath('path'))
         self.assertEqual(packages._boost_version(hdr, SpecifierSet('')),
                          Version('1.23.4'))