def testContains(self): # Create an empty package index and add a single entry to it index = package_index.PackageIndex('dummy_file', '') config_debug = Configuration('arm', 'glibc', True) config_release = Configuration('arm', 'glibc', False) self.assertFalse(index.Contains('foo', config_release)) index.packages[('foo', config_release)] = { 'NAME': 'dummy', 'BUILD_SDK_VERSION': 123 } with patch('webports.util.GetSDKVersion') as mock_version: # Setting the mock SDK version to 123 should mean that the # index contains the 'foo' package and it is installable' mock_version.return_value = 123 self.assertTrue(index.Contains('foo', config_release)) self.assertTrue(index.Installable('foo', config_release)) # Setting the mock SDK version to some other version should # mean the index contains that package but it is not installable. mock_version.return_value = 124 self.assertTrue(index.Contains('foo', config_release)) self.assertFalse(index.Installable('foo', config_release)) self.assertFalse(index.Contains('foo', config_debug)) self.assertFalse(index.Contains('bar', config_release))
def testParsingValid(self): index = package_index.PackageIndex('dummy_file', test_index) arm_config = Configuration('arm', 'glibc', False) i686_config = Configuration('i686', 'glibc', False) self.assertEqual(len(index.packages), 2) self.assertTrue(index.Contains('agg-demo', arm_config)) self.assertTrue(index.Contains('agg-demo', i686_config))
def testDefaultArch(self): # We default to x86_64 except in the special case where the build # machine is i686 hardware, in which case we default to i686. with patch('platform.machine', Mock(return_value='i686')): self.assertEqual(Configuration().arch, 'pnacl') with patch('platform.machine', Mock(return_value='dummy')): self.assertEqual(Configuration().arch, 'pnacl') with patch('platform.machine', Mock(return_value='i686')): self.assertEqual( Configuration(toolchain='clang-newlib').arch, 'i686') with patch('platform.machine', Mock(return_value='dummy')): self.assertEqual( Configuration(toolchain='clang-newlib').arch, 'x86_64')
def testDefaults(self): config = Configuration() self.assertEqual(config.toolchain, 'pnacl') self.assertEqual(config.arch, 'pnacl') self.assertEqual(config.debug, False) self.assertEqual(config.config_name, 'release') self.assertEqual(config.libc, 'newlib')
def testDisabledArch(self): self.CreateTestPackage('bar', 'DISABLED_ARCH=(x86_64)') pkg = source_package.CreatePackage( 'bar', config=Configuration(toolchain='clang-newlib')) with self.assertRaisesRegexp(error.DisabledError, 'disabled for architecture: x86_64'): pkg.CheckInstallable()
def test_disabled_arch(self): self.create_mock_package('bar', 'DISABLED_ARCH=(x86_64)') pkg = source_package.create_package( 'bar', config=Configuration(toolchain='clang-newlib')) with self.assertRaisesRegex(error.DisabledError, 'disabled for architecture: x86_64'): pkg.check_installable()
def test_get_install_root(self): expected = '/sdk/root/toolchain/linux_pnacl/le32-nacl/usr' self.assertEqual(util.get_install_root(Configuration()), expected) expected = '/sdk/root/toolchain/linux_x86_glibc/x86_64-nacl/usr' self.assertEqual(util.get_install_root(Configuration(toolchain='glibc')), expected) expected = '/sdk/root/toolchain/linux_pnacl/le32-nacl/usr' self.assertEqual(util.get_install_root(Configuration('pnacl')), expected) expected = '/emscripten/root/system/local' self.assertEqual(util.get_install_root(Configuration('emscripten')), expected) expected = '/sdk/root/toolchain/linux_pnacl/x86_64-nacl/usr' self.assertEqual( util.get_install_root(Configuration(toolchain='clang-newlib')), expected)
def test_info_command(self): config = Configuration() options = Mock() file_mock = common.mock_file_object('FOO=bar\n') with patch('sys.stdout', new_callable=io.StringIO) as stdout: with patch('__builtin__.open', Mock(return_value=file_mock), create=True): webports.__main__.cmd_info(config, options, ['foo']) self.assertRegex(stdout.getvalue(), "FOO=bar")
def test_list_command_verbose(self): config = Configuration() pkg = Mock(NAME='foo', VERSION='0.1') with patch('webports.installed_package.installed_package_iterator', Mock(return_value=[pkg])): with patch('sys.stdout', new_callable=io.StringIO) as stdout: options = Mock(verbosity=0, all=False) webports.__main__.cmd_list(config, options, []) lines = stdout.getvalue().splitlines() self.assertRegex(lines[0], "^foo$") self.assertEqual(len(lines), 1)
def testListCommand(self): config = Configuration() pkg = Mock(NAME='foo', VERSION='0.1') with patch('webports.installed_package.InstalledPackageIterator', Mock(return_value=[pkg])): with patch('sys.stdout', new_callable=StringIO.StringIO) as stdout: options = Mock(all=False) webports.__main__.CmdList(config, options, []) lines = stdout.getvalue().splitlines() self.assertRegexpMatches(lines[0], '^foo\\s+0.1$') self.assertEqual(len(lines), 1)
def test_disabled_toolchain_arch(self): self.create_mock_package('bar', 'DISABLED_TOOLCHAIN=(glibc/x86_64)') pkg = source_package.create_package( 'bar', config=Configuration(toolchain='glibc')) with self.assertRaisesRegexp(error.DisabledError, 'cannot be built with glibc for x86_64$'): pkg.check_installable() self.create_mock_package('bar2', 'DISABLED_TOOLCHAIN=(pnacl/arm)') pkg = source_package.create_package('bar2') pkg.check_installable()
def testDisabledToolchainArch(self): self.CreateTestPackage('bar', 'DISABLED_TOOLCHAIN=(glibc/x86_64)') pkg = source_package.CreatePackage( 'bar', config=Configuration(toolchain='glibc')) with self.assertRaisesRegexp(error.DisabledError, 'cannot be built with glibc for x86_64$'): pkg.CheckInstallable() self.CreateTestPackage('bar2', 'DISABLED_TOOLCHAIN=(pnacl/arm)') pkg = source_package.CreatePackage('bar2') pkg.CheckInstallable()
def testInvalidArch(self): expected_error = 'Invalid arch: not_arch' with self.assertRaisesRegexp(error.Error, expected_error): Configuration('not_arch')
def testConfigEquality(self): config1 = Configuration('arm', 'glibc', True) config2 = Configuration('arm', 'glibc', True) config3 = Configuration('arm', 'glibc', False) self.assertEqual(config1, config2) self.assertNotEqual(config1, config3)
def testConfigStringForm(self): config = Configuration('arm', 'glibc', True) self.assertEqual(str(config), 'arm/glibc/debug') self.assertRegexpMatches(repr(config), '<Configuration .*>')
def testDefaultLibc(self): self.assertEqual(Configuration(toolchain='pnacl').libc, 'newlib') self.assertEqual( Configuration(toolchain='clang-newlib').libc, 'newlib') self.assertEqual(Configuration(toolchain='glibc').libc, 'glibc')
def testDefaultToolchain(self): self.assertEqual(Configuration(arch='pnacl').toolchain, 'pnacl') self.assertEqual(Configuration(arch='arm').libc, 'newlib')
def testEnvironmentVariables(self): with patch.dict('os.environ', {'NACL_ARCH': 'arm'}): self.assertEqual(Configuration().arch, 'arm') with patch.dict('os.environ', {'NACL_DEBUG': '1'}): self.assertEqual(Configuration().debug, True)
def test_config_string_form(self): config = Configuration('arm', 'glibc', True) self.assertEqual(str(config), 'arm/glibc/debug') self.assertRegex(repr(config), '<Configuration .*>')
def test_clean_all(self, mock_rmtree): config = Configuration() webports.__main__.clean_all(config) mock_rmtree.assert_any_call('/package/install/path')
def test_main_clean_all(self, clean_all_mock): webports.__main__.run_main(['clean', '--all']) clean_all_mock.assert_called_once_with(Configuration())
def testDownload(self, download_file_mock): index = package_index.PackageIndex('dummy_file', test_index) arm_config = Configuration('arm', 'glibc', False) index.Download('agg-demo', arm_config) self.assertEqual(download_file_mock.call_count, 1)