Closed tdhopper closed 6 years ago
First, thanks for the PR. Glancing through the changes and trying it out locally, here are few things 1) Revert all the test names changes and any other formatting/style changes. It may be idiomatically more correct, but the current master matches with the upstream branch where I forked from and I'd still like to see this repo get merged back in there at some point, and unnecessary test name changes only make that much more difficult. 2) I noticed multiple cases where your changes seemed broke encoding of some special characters. Fix that. 3) What was the reason for the error message name change around "file is encrypted or is not a database"? What this a change in a recent version of sqlchiper? Speaking of which, I noticed some tests seemed to be failing because of this (I was using the build amalgamation in the upstream repo)
=================================================== FAILURES ====================================================
________________________________________ SqlCipherTests.testAddPassword _________________________________________
self =
def assertDatabaseError(self, password):
conn = sqlite.connect(self.db)
self.setPassword(conn, password)
try:
col_value = self.queryData(conn)
lib/test/python3/sqlcipher.py:97:
self =
def queryData(self, conn):
return conn.execute('select col from tbl').fetchone()[0]
E pysqlcipher3.dbapi2.DatabaseError: file is encrypted or is not a database
lib/test/python3/sqlcipher.py:84: DatabaseError
During handling of the above exception, another exception occurred:
self =
def testAddPassword(self):
""" Test for adding a password to a plaintext database """
self.createDatabase(encrypt=False)
self.assertSuccessfulQuery(None)
encrypted_db = os.path.join(self.temp_dir, 'encrypted.db')
conn = sqlite.connect(self.db)
conn.executescript("ATTACH DATABASE '" + encrypted_db + "'" +
"AS encrypted KEY '" + self.password + "'")
conn.executescript("SELECT sqlcipher_export('encrypted')")
conn.executescript("DETACH DATABASE encrypted")
conn.close()
if os.path.exists(self.db):
os.remove(self.db)
os.rename(encrypted_db, self.db)
self.assertDatabaseError(None)
lib/test/python3/sqlcipher.py:51:
lib/test/python3/sqlcipher.py:100: in assertDatabaseError self.assertEqual('file is not a database', str(ex)) E AssertionError: 'file is not a database' != 'file is encrypted or is not a database' E - file is not a database E + file is encrypted or is not a database SqlCipherTests.testChangePassword
self =
def assertDatabaseError(self, password):
conn = sqlite.connect(self.db)
self.setPassword(conn, password)
try:
col_value = self.queryData(conn)
lib/test/python3/sqlcipher.py:97:
self =
def queryData(self, conn):
return conn.execute('select col from tbl').fetchone()[0]
E pysqlcipher3.dbapi2.DatabaseError: file is encrypted or is not a database
lib/test/python3/sqlcipher.py:84: DatabaseError
During handling of the above exception, another exception occurred:
self =
def testChangePassword(self):
""" Test for changing the database password """
new_password = "New password"
self.createDatabase()
self.assertSuccessfulQuery(self.password)
self.changePassword(self.password, new_password)
self.assertDatabaseError(self.password)
lib/test/python3/sqlcipher.py:33:
lib/test/python3/sqlcipher.py:100: in assertDatabaseError self.assertEqual('file is not a database', str(ex)) E AssertionError: 'file is not a database' != 'file is encrypted or is not a database' E - file is not a database E + file is encrypted or is not a database _____ SqlCipherTests.testNoPasswordEntered __
self =
def assertDatabaseError(self, password):
conn = sqlite.connect(self.db)
self.setPassword(conn, password)
try:
col_value = self.queryData(conn)
lib/test/python3/sqlcipher.py:97:
self =
def queryData(self, conn):
return conn.execute('select col from tbl').fetchone()[0]
E pysqlcipher3.dbapi2.DatabaseError: file is encrypted or is not a database
lib/test/python3/sqlcipher.py:84: DatabaseError
During handling of the above exception, another exception occurred:
self =
def testNoPasswordEntered(self):
""" Test for database exception when entering no password """
self.createDatabase()
self.assertDatabaseError(None)
lib/test/python3/sqlcipher.py:20:
lib/test/python3/sqlcipher.py:100: in assertDatabaseError self.assertEqual('file is not a database', str(ex)) E AssertionError: 'file is not a database' != 'file is encrypted or is not a database' E - file is not a database E + file is encrypted or is not a database ____ SqlCipherTests.testWrongPasswordEntered ____
self =
def assertDatabaseError(self, password):
conn = sqlite.connect(self.db)
self.setPassword(conn, password)
try:
col_value = self.queryData(conn)
lib/test/python3/sqlcipher.py:97:
self =
def queryData(self, conn):
return conn.execute('select col from tbl').fetchone()[0]
E pysqlcipher3.dbapi2.DatabaseError: file is encrypted or is not a database
lib/test/python3/sqlcipher.py:84: DatabaseError
During handling of the above exception, another exception occurred:
self =
def testWrongPasswordEntered(self):
""" Test for database exception when entering wrong password """
self.createDatabase()
self.assertDatabaseError("Wrong password")
lib/test/python3/sqlcipher.py:25:
lib/test/python3/sqlcipher.py:100: in assertDatabaseError self.assertEqual('file is not a database', str(ex)) E AssertionError: 'file is not a database' != 'file is encrypted or is not a database' E - file is not a database E + file is encrypted or is not a database ===================================== 4 failed, 236 passed in 4.59 seconds ======================================
Someone else can feel free to pick up on my work. I don't have the time to dig into all that.
This makes running the tests easier using Tox, pytest, and pyenv. Hopefully addresses the concerns in #6.
You can now run the Python 3 tests on Python 3.4, 3.5, 3.6, and 3.7 by calling
$ tox
.Tox creates a virtualenv for each, builds the library, and runs the tests using pytest. Pytest does the collection and test running; it provides more clear output of the tests. It also sets an error code in the terminal if the tests fail.
python setup.py test
will now run Pytest testes.