def testGetBuildLocation(self):
     root = self.CreateTestPackage('foo')
     pkg = source_package.SourcePackage(root)
     location = pkg.GetBuildLocation()
     self.assertTrue(location.startswith(paths.BUILD_ROOT))
     self.assertEqual(os.path.basename(location),
                      '%s-%s' % (pkg.NAME, pkg.VERSION))
 def testIsBuiltMalformedBinary(self):
     """test that IsBuilt() can handle malformed package files."""
     root = self.CreateTestPackage('foo')
     pkg = source_package.SourcePackage(root)
     invalid_binary = os.path.join(self.tempdir, 'package.tar.bz2')
     with open(invalid_binary, 'w') as f:
         f.write('this is not valid package file\n')
     pkg.PackageFile = Mock(return_value=invalid_binary)
     self.assertFalse(pkg.IsBuilt())
    def testExtract(self):
        root = self.CreateTestPackage('foo', 'URL=someurl.tar.gz\nSHA1=123')
        pkg = source_package.SourcePackage(root)

        def fake_extract(archive, dest):
            os.mkdir(os.path.join(dest, '%s-%s' % (pkg.NAME, pkg.VERSION)))

        with patch('naclports.source_package.ExtractArchive', fake_extract):
            pkg.Extract()
 def testInstalledInfoContents(self):
   root = self.CreateTestPackage('foo')
   pkg = source_package.SourcePackage(root)
   expected_contents = textwrap.dedent('''\
     NAME=foo
     VERSION=1.0
     BUILD_CONFIG=release
     BUILD_ARCH=pnacl
     BUILD_TOOLCHAIN=pnacl
     BUILD_SDK_VERSION=1234
     ''')
   self.assertRegexpMatches(pkg.InstalledInfoContents(), expected_contents)
    def testConflicts(self):
        root = self.CreateTestPackage('foo', 'CONFLICTS=(bar)')
        pkg = source_package.SourcePackage(root)

        # with no other packages installed
        with patch('naclports.util.IsInstalled', Mock(return_value=False)):
            pkg.CheckInstallable()

        # with all possible packages installed
        with patch('naclports.util.IsInstalled') as is_installed:
            is_installed.return_value = True
            with self.assertRaises(source_package.PkgConflictError):
                pkg.CheckInstallable()
            is_installed.assert_called_once_with('bar', pkg.config)
 def testBuildPackage(self):
     root = self.CreateTestPackage('foo')
     pkg = source_package.SourcePackage(root)
     pkg.Build(True)
 def testValidSourceDir(self):
     """test that valid source directory is loaded correctly."""
     root = self.CreateTestPackage('foo')
     pkg = source_package.SourcePackage(root)
     self.assertEqual(pkg.NAME, 'foo')
     self.assertEqual(pkg.root, root)
 def testInvalidSourceDir(self):
     """test that invalid source directory generates an error."""
     path = '/bad/path'
     expected_error = 'Invalid package folder: ' + path
     with self.assertRaisesRegexp(error.Error, expected_error):
         source_package.SourcePackage(path)
 def testDisabled(self):
     root = self.CreateTestPackage('foo', 'DISABLED=1')
     pkg = source_package.SourcePackage(root)
     with self.assertRaisesRegexp(error.DisabledError,
                                  'package is disabled'):
         pkg.CheckInstallable()
 def testGetInstalledPackage(self):
   root = self.CreateTestPackage('foo')
   pkg = source_package.SourcePackage(root)
   with self.assertRaisesRegexp(error.Error, 'package not installed: foo'):
     pkg.GetInstalledPackage()