fix tests on windows

This commit is contained in:
Alan Hamlett 2018-09-30 19:53:52 -07:00
parent 49ff066a12
commit c7434cb75b
4 changed files with 25 additions and 22 deletions

View file

@ -3,6 +3,6 @@ debug = false
api_key = 1090a6ae-855f-4be7-b8fb-3edbaf1aa3ec api_key = 1090a6ae-855f-4be7-b8fb-3edbaf1aa3ec
[git] [git]
submodules_disabled = submodules_disabled =
this/path/does/not/exist this[\\/]path[\\/]does[\\/]not[\\/]exist
git/asubmodule git[\\/]asubmodule
that/other/path that[\\/]other[\\/]path

View file

@ -3,7 +3,7 @@ debug = false
api_key = 1090a6ae-855f-4be7-b8fb-3edbaf1aa3ec api_key = 1090a6ae-855f-4be7-b8fb-3edbaf1aa3ec
[git] [git]
submodules_disabled = submodules_disabled =
this/path/does/not/exist this[\\/]path[\\/]does[\\/]not[\\/]exist
\(invalid regex) \(invalid regex)
git/asubmodule git[\\/]asubmodule
that/other/path that[\\/]other[\\/]path

View file

@ -8,10 +8,12 @@ from wakatime.packages.requests.models import Response
import logging import logging
import os import os
import platform
import time import time
import shutil import shutil
from testfixtures import log_capture from testfixtures import log_capture
from . import utils from . import utils
from .utils import unittest
class LoggingTestCase(utils.TestCase): class LoggingTestCase(utils.TestCase):
@ -81,6 +83,7 @@ class LoggingTestCase(utils.TestCase):
self.assertEquals(logfile, logging.getLogger('WakaTime').handlers[0].baseFilename) self.assertEquals(logfile, logging.getLogger('WakaTime').handlers[0].baseFilename)
logs.check() logs.check()
@unittest.skipIf(platform.system() == 'Windows', 'Windows file issue')
@log_capture() @log_capture()
def test_log_file_location_can_be_set_from_env_variable(self, logs): def test_log_file_location_can_be_set_from_env_variable(self, logs):
logging.disable(logging.NOTSET) logging.disable(logging.NOTSET)

View file

@ -45,7 +45,7 @@ class OfflineQueueTestCase(TestCase):
queue = Queue(None, None) queue = Queue(None, None)
saved_heartbeat = queue.pop() saved_heartbeat = queue.pop()
self.assertEquals(os.path.realpath(entity), saved_heartbeat['entity']) self.assertPathsEqual(os.path.realpath(entity), saved_heartbeat['entity'])
def test_heartbeat_discarded_from_400_response(self): def test_heartbeat_discarded_from_400_response(self):
with NamedTemporaryFile() as fh: with NamedTemporaryFile() as fh:
@ -137,31 +137,31 @@ class OfflineQueueTestCase(TestCase):
body = calls[0][0][0].body body = calls[0][0][0].body
data = json.loads(body)[0] data = json.loads(body)[0]
self.assertEquals(data.get('entity'), os.path.abspath(entity1)) self.assertPathsEqual(data.get('entity'), os.path.abspath(entity1))
self.assertEquals(data.get('project'), project1) self.assertEquals(data.get('project'), project1)
self.assertEquals(u(int(data.get('time'))), now1) self.assertEquals(u(int(data.get('time'))), now1)
body = calls[1][0][0].body body = calls[1][0][0].body
data = json.loads(body)[0] data = json.loads(body)[0]
self.assertEquals(data.get('entity'), os.path.abspath(entity2)) self.assertPathsEqual(data.get('entity'), os.path.abspath(entity2))
self.assertEquals(data.get('project'), project2) self.assertEquals(data.get('project'), project2)
self.assertEquals(u(int(data.get('time'))), now2) self.assertEquals(u(int(data.get('time'))), now2)
body = calls[2][0][0].body body = calls[2][0][0].body
data = json.loads(body)[0] data = json.loads(body)[0]
self.assertEquals(data.get('entity'), os.path.abspath(entity3)) self.assertPathsEqual(data.get('entity'), os.path.abspath(entity3))
self.assertEquals(data.get('project'), project3) self.assertEquals(data.get('project'), project3)
self.assertEquals(u(int(data.get('time'))), now3) self.assertEquals(u(int(data.get('time'))), now3)
body = calls[3][0][0].body body = calls[3][0][0].body
data = json.loads(body)[0] data = json.loads(body)[0]
self.assertEquals(data.get('entity'), os.path.abspath(entity1)) self.assertPathsEqual(data.get('entity'), os.path.abspath(entity1))
self.assertEquals(data.get('project'), project1) self.assertEquals(data.get('project'), project1)
self.assertEquals(u(int(data.get('time'))), now1) self.assertEquals(u(int(data.get('time'))), now1)
body = calls[3][0][0].body body = calls[3][0][0].body
data = json.loads(body)[1] data = json.loads(body)[1]
self.assertEquals(data.get('entity'), os.path.abspath(entity2)) self.assertPathsEqual(data.get('entity'), os.path.abspath(entity2))
self.assertEquals(data.get('project'), project2) self.assertEquals(data.get('project'), project2)
self.assertEquals(u(int(data.get('time'))), now2) self.assertEquals(u(int(data.get('time'))), now2)
@ -238,15 +238,15 @@ class OfflineQueueTestCase(TestCase):
self.assertSessionCacheSaved() self.assertSessionCacheSaved()
queue = Queue(None, None) queue = Queue(None, None)
self.assertEquals(queue._get_db_file(), fh.name) self.assertPathsEqual(queue._get_db_file(), fh.name)
saved_heartbeats = next(queue.pop_many()) saved_heartbeats = next(queue.pop_many())
self.assertNothingPrinted() self.assertNothingPrinted()
self.assertNothingLogged(logs) self.assertNothingLogged(logs)
# make sure only heartbeats with error code responses were saved # make sure only heartbeats with error code responses were saved
self.assertEquals(sum(1 for x in saved_heartbeats), 2) self.assertEquals(sum(1 for x in saved_heartbeats), 2)
self.assertEquals(saved_heartbeats[0].entity, os.path.realpath(os.path.join(tempdir, entities[1]))) self.assertPathsEqual(saved_heartbeats[0].entity, os.path.realpath(os.path.join(tempdir, entities[1])))
self.assertEquals(saved_heartbeats[1].entity, os.path.realpath(os.path.join(tempdir, entities[3]))) self.assertPathsEqual(saved_heartbeats[1].entity, os.path.realpath(os.path.join(tempdir, entities[3])))
@log_capture() @log_capture()
def test_offline_heartbeats_sent_after_partial_success_from_bulk_response(self, logs): def test_offline_heartbeats_sent_after_partial_success_from_bulk_response(self, logs):
@ -467,7 +467,7 @@ class OfflineQueueTestCase(TestCase):
queue = Queue(None, None) queue = Queue(None, None)
saved_heartbeat = queue.pop() saved_heartbeat = queue.pop()
self.assertNothingPrinted() self.assertNothingPrinted()
self.assertEquals(os.path.realpath(entity), saved_heartbeat['entity']) self.assertPathsEqual(os.path.realpath(entity), saved_heartbeat['entity'])
def test_get_handles_exception_on_connect(self): def test_get_handles_exception_on_connect(self):
with NamedTemporaryFile() as fh: with NamedTemporaryFile() as fh:
@ -497,7 +497,7 @@ class OfflineQueueTestCase(TestCase):
queue = Queue(None, None) queue = Queue(None, None)
saved_heartbeat = queue.pop() saved_heartbeat = queue.pop()
self.assertEquals(os.path.realpath(entity), saved_heartbeat['entity']) self.assertPathsEqual(os.path.realpath(entity), saved_heartbeat['entity'])
def test_push_handles_exception_on_connect(self): def test_push_handles_exception_on_connect(self):
with NamedTemporaryFile() as fh: with NamedTemporaryFile() as fh:
@ -673,7 +673,7 @@ class OfflineQueueTestCase(TestCase):
queue = Queue(None, None) queue = Queue(None, None)
saved_heartbeat = queue.pop() saved_heartbeat = queue.pop()
self.assertEquals(os.path.realpath(entity), saved_heartbeat['entity']) self.assertPathsEqual(os.path.realpath(entity), saved_heartbeat['entity'])
self.assertNothingPrinted() self.assertNothingPrinted()
@ -737,7 +737,7 @@ class OfflineQueueTestCase(TestCase):
queue = Queue(None, None) queue = Queue(None, None)
saved_heartbeat = queue.pop() saved_heartbeat = queue.pop()
self.assertEquals(os.path.realpath(entity), saved_heartbeat['entity']) self.assertPathsEqual(os.path.realpath(entity), saved_heartbeat['entity'])
self.assertEquals(u(language), saved_heartbeat['language']) self.assertEquals(u(language), saved_heartbeat['language'])
self.assertEquals(u(project), saved_heartbeat['project']) self.assertEquals(u(project), saved_heartbeat['project'])
self.assertEquals(u(branch), saved_heartbeat['branch']) self.assertEquals(u(branch), saved_heartbeat['branch'])
@ -763,7 +763,7 @@ class OfflineQueueTestCase(TestCase):
queue = Queue(None, None) queue = Queue(None, None)
saved_heartbeat = queue.pop() saved_heartbeat = queue.pop()
self.assertEquals(os.path.realpath(entity), saved_heartbeat['entity']) self.assertPathsEqual(os.path.realpath(entity), saved_heartbeat['entity'])
self.assertNothingPrinted() self.assertNothingPrinted()
expected = 'JSONDecodeError' expected = 'JSONDecodeError'
@ -791,7 +791,7 @@ class OfflineQueueTestCase(TestCase):
queue = Queue(None, None) queue = Queue(None, None)
saved_heartbeat = queue.pop() saved_heartbeat = queue.pop()
self.assertEquals(os.path.realpath(entity), saved_heartbeat['entity']) self.assertPathsEqual(os.path.realpath(entity), saved_heartbeat['entity'])
self.assertNothingPrinted() self.assertNothingPrinted()
expected = 'TypeError' expected = 'TypeError'
@ -819,7 +819,7 @@ class OfflineQueueTestCase(TestCase):
queue = Queue(None, None) queue = Queue(None, None)
saved_heartbeat = queue.pop() saved_heartbeat = queue.pop()
self.assertEquals(os.path.realpath(entity), saved_heartbeat['entity']) self.assertPathsEqual(os.path.realpath(entity), saved_heartbeat['entity'])
self.assertNothingPrinted() self.assertNothingPrinted()
expected = 'IndexError' expected = 'IndexError'