def testInstallFile(self, makedirs_mock, rename_mock): mock_file = common.MockFileObject() with patch('__builtin__.open', Mock(return_value=mock_file)): binary_package.InstallFile('fname', 'location1', 'location2') makedirs_mock.assert_called_once_with('location2') rename_mock.assert_has_calls( [call('location1/fname', 'location2/fname')])
def testInfoCommand(self): config = Configuration() options = Mock() file_mock = common.MockFileObject('FOO=bar\n') with patch('sys.stdout', new_callable=StringIO.StringIO) as stdout: with patch('__builtin__.open', Mock(return_value=file_mock), create=True): naclports.__main__.CmdInfo(config, options, ['foo']) self.assertRegexpMatches(stdout.getvalue(), "FOO=bar")
def testWriteStamp(self, mock_get_info): fake_binary_pkg_info = textwrap.dedent('''\ NAME=foo VERSION=1.0 BUILD_CONFIG=release BUILD_ARCH=arm BUILD_TOOLCHAIN=glibc BUILD_SDK_VERSION=38 BUILD_NACLPORTS_REVISION=1414 ''') mock_get_info.return_value = fake_binary_pkg_info pkg = binary_package.BinaryPackage('foo') mock_stamp_file = common.MockFileObject() with patch('__builtin__.open', Mock(return_value=mock_stamp_file), create=True): pkg.WriteStamp() mock_stamp_file.write.assert_called_once_with(fake_binary_pkg_info)
def CreateMockInstalledPackage(): file_mock = common.MockFileObject(test_info) with patch('__builtin__.open', Mock(return_value=file_mock), create=True): return installed_package.InstalledPackage('dummy_file')