autocommit transactions to sqlite db in python 3.6+

This commit is contained in:
Alan Hamlett 2017-02-16 12:46:04 -08:00
parent 414d3e4312
commit 9c45df622a
6 changed files with 15 additions and 11 deletions

View file

@ -51,11 +51,11 @@ class LoggingTestCase(utils.TestCase):
self.assertEquals(logfile, logging.getLogger('WakaTime').handlers[0].baseFilename) self.assertEquals(logfile, logging.getLogger('WakaTime').handlers[0].baseFilename)
output = [u(' ').join(x) for x in logs.actual()] output = [u(' ').join(x) for x in logs.actual()]
expected = u('WakaTime WARNING Regex error (unbalanced parenthesis) for include pattern: \\(invalid regex)') expected = u('WakaTime WARNING Regex error (unbalanced parenthesis) for include pattern: \\(invalid regex)')
if self.isPy35: if self.isPy35OrNewer:
expected = u('WakaTime WARNING Regex error (unbalanced parenthesis at position 15) for include pattern: \\(invalid regex)') expected = u('WakaTime WARNING Regex error (unbalanced parenthesis at position 15) for include pattern: \\(invalid regex)')
self.assertEquals(output[0], expected) self.assertEquals(output[0], expected)
expected = u('WakaTime WARNING Regex error (unbalanced parenthesis) for exclude pattern: \\(invalid regex)') expected = u('WakaTime WARNING Regex error (unbalanced parenthesis) for exclude pattern: \\(invalid regex)')
if self.isPy35: if self.isPy35OrNewer:
expected = u('WakaTime WARNING Regex error (unbalanced parenthesis at position 15) for exclude pattern: \\(invalid regex)') expected = u('WakaTime WARNING Regex error (unbalanced parenthesis at position 15) for exclude pattern: \\(invalid regex)')
self.assertEquals(output[1], expected) self.assertEquals(output[1], expected)
@ -144,11 +144,11 @@ class LoggingTestCase(utils.TestCase):
self.assertEquals(logfile, logging.getLogger('WakaTime').handlers[0].baseFilename) self.assertEquals(logfile, logging.getLogger('WakaTime').handlers[0].baseFilename)
output = [u(' ').join(x) for x in logs.actual()] output = [u(' ').join(x) for x in logs.actual()]
expected = u('WakaTime WARNING Regex error (unbalanced parenthesis) for include pattern: \\(invalid regex)') expected = u('WakaTime WARNING Regex error (unbalanced parenthesis) for include pattern: \\(invalid regex)')
if self.isPy35: if self.isPy35OrNewer:
expected = u('WakaTime WARNING Regex error (unbalanced parenthesis at position 15) for include pattern: \\(invalid regex)') expected = u('WakaTime WARNING Regex error (unbalanced parenthesis at position 15) for include pattern: \\(invalid regex)')
self.assertEquals(output[0], expected) self.assertEquals(output[0], expected)
expected = u('WakaTime WARNING Regex error (unbalanced parenthesis) for exclude pattern: \\(invalid regex)') expected = u('WakaTime WARNING Regex error (unbalanced parenthesis) for exclude pattern: \\(invalid regex)')
if self.isPy35: if self.isPy35OrNewer:
expected = u('WakaTime WARNING Regex error (unbalanced parenthesis at position 15) for exclude pattern: \\(invalid regex)') expected = u('WakaTime WARNING Regex error (unbalanced parenthesis at position 15) for exclude pattern: \\(invalid regex)')
self.assertEquals(output[1], expected) self.assertEquals(output[1], expected)
self.assertEquals(output[2], u('WakaTime DEBUG Sending heartbeat to api at https://api.wakatime.com/api/v1/heartbeats')) self.assertEquals(output[2], u('WakaTime DEBUG Sending heartbeat to api at https://api.wakatime.com/api/v1/heartbeats'))

View file

@ -539,8 +539,10 @@ class MainTestCase(utils.TestCase):
self.assertEquals(sys.stderr.getvalue(), '') self.assertEquals(sys.stderr.getvalue(), '')
log_output = u("\n").join([u(' ').join(x) for x in logs.actual()]) log_output = u("\n").join([u(' ').join(x) for x in logs.actual()])
expected = 'WakaTime WARNING Regex error' expected = u('WakaTime WARNING Regex error (unexpected end of regular expression) for projectmap pattern: invalid(regex')
self.assertIn(expected, log_output) if self.isPy35OrNewer:
expected = 'WakaTime WARNING Regex error (missing ), unterminated subpattern at position 7) for include pattern: invalid(regex'
self.assertEquals(expected, log_output)
self.patched['wakatime.session_cache.SessionCache.get'].assert_called_once_with() self.patched['wakatime.session_cache.SessionCache.get'].assert_called_once_with()
self.patched['wakatime.session_cache.SessionCache.delete'].assert_called_once_with() self.patched['wakatime.session_cache.SessionCache.delete'].assert_called_once_with()

View file

@ -396,7 +396,7 @@ class ProjectTestCase(utils.TestCase):
output = [u(' ').join(x) for x in logs.actual()] output = [u(' ').join(x) for x in logs.actual()]
expected = u('WakaTime WARNING Regex error (unexpected end of regular expression) for projectmap pattern: invalid[({regex') expected = u('WakaTime WARNING Regex error (unexpected end of regular expression) for projectmap pattern: invalid[({regex')
if self.isPy35: if self.isPy35OrNewer:
expected = u('WakaTime WARNING Regex error (unterminated character set at position 7) for projectmap pattern: invalid[({regex') expected = u('WakaTime WARNING Regex error (unterminated character set at position 7) for projectmap pattern: invalid[({regex')
self.assertEquals(output[0], expected) self.assertEquals(output[0], expected)

View file

@ -50,8 +50,10 @@ class TestCase(unittest.TestCase):
self.assertEquals(self.normalize_list(first_list), self.normalize_list(second_list)) self.assertEquals(self.normalize_list(first_list), self.normalize_list(second_list))
@property @property
def isPy35(self): def isPy35OrNewer(self):
return (sys.version_info[0] == 3 and sys.version_info[1] == 5) if sys.version_info[0] > 3:
return True
return (sys.version_info[0] >= 3 and sys.version_info[1] >= 5)
try: try:

View file

@ -34,7 +34,7 @@ class Queue(object):
return self.db_file return self.db_file
def connect(self): def connect(self):
conn = sqlite3.connect(self.get_db_file()) conn = sqlite3.connect(self.get_db_file(), isolation_level=None)
c = conn.cursor() c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS {0} ( c.execute('''CREATE TABLE IF NOT EXISTS {0} (
entity text, entity text,

View file

@ -33,7 +33,7 @@ class SessionCache(object):
DB_FILE = os.path.join(os.path.expanduser('~'), '.wakatime.db') DB_FILE = os.path.join(os.path.expanduser('~'), '.wakatime.db')
def connect(self): def connect(self):
conn = sqlite3.connect(self.DB_FILE) conn = sqlite3.connect(self.DB_FILE, isolation_level=None)
c = conn.cursor() c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS session ( c.execute('''CREATE TABLE IF NOT EXISTS session (
value BLOB) value BLOB)