Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Lib/test/test_msilib.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" Test suite for the code in msilib """
import os.path
import unittest
from test.support import TESTFN, import_module, unlink
msilib = import_module('msilib')
Expand Down Expand Up @@ -41,6 +42,17 @@ def test_view_fetch_returns_none(self):
)
self.addCleanup(unlink, db_path)

def test_database_open_failed(self):
with self.assertRaises(msilib.MSIError) as cm:
msilib.OpenDatabase('non-existent.msi', msilib.MSIDBOPEN_READONLY)
self.assertEqual(str(cm.exception), 'open failed')

def test_database_create_failed(self):
db_path = os.path.join(TESTFN, 'test.msi')
with self.assertRaises(msilib.MSIError) as cm:
msilib.OpenDatabase(db_path, msilib.MSIDBOPEN_CREATE)
self.assertEqual(str(cm.exception), 'create failed')


class Test_make_id(unittest.TestCase):
#http://msdn.microsoft.com/en-us/library/aa369212(v=vs.85).aspx
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:func:`msilib.OpenDatabase` now raises a better exception message when it
couldn't open or create an MSI file. Initial patch by William Tisäter.
6 changes: 6 additions & 0 deletions PC/_msi.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,12 @@ msierror(int status)
case ERROR_INVALID_PARAMETER:
PyErr_SetString(MSIError, "invalid parameter");
return NULL;
case ERROR_OPEN_FAILED:
PyErr_SetString(MSIError, "open failed");
return NULL;
case ERROR_CREATE_FAILED:
PyErr_SetString(MSIError, "create failed");
return NULL;
default:
PyErr_Format(MSIError, "unknown error %x", status);
return NULL;
Expand Down