Skip to content

Commit

Permalink
Making tests work under Py3
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Uhlir authored and Adam Uhlir committed Nov 21, 2017
1 parent e50cde1 commit 8c687e3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
19 changes: 15 additions & 4 deletions tests.py
Expand Up @@ -16,7 +16,9 @@
import pytz
import time
import toggl

import six
import traceback
import sys

def desc(description):
return "%s%s" % (PREFIX, description)
Expand All @@ -30,7 +32,7 @@ def setUp(self):
self.list = toggl.ClientList()

def test_iterator(self):
num_clients = len(self.list.client_list)
num_clients = len(self.list.client_list) if self.list.client_list else 0
count = 0
for client in self.list:
count += 1
Expand Down Expand Up @@ -356,7 +358,7 @@ def tearDownModule():
Cleans up toggl with all the unittest entries we just created. This
relies on TimeEntryList and TimeEntry.delete.
"""
print "Removing toggl entries created by the test..."
print("Removing toggl entries created by the test...")
for entry in toggl.TimeEntryList():
if entry.get('description') is not None and entry.get('description').startswith('unittest_'):
entry.delete()
Expand All @@ -365,4 +367,13 @@ def tearDownModule():
toggl.CLI() # this initializes Logger to INFO
#toggl.Logger.level = toggl.Logger.DEBUG
toggl.Logger.level = toggl.Logger.NONE
unittest.main()

try:
unittest.main()
except SystemExit:
pass
except Exception as e:
if six.PY3:
traceback.print_tb(e.__traceback__)
else:
traceback.print_tb(sys.exc_info()[2])
11 changes: 6 additions & 5 deletions toggl.py
Expand Up @@ -360,7 +360,7 @@ def __next__(self):
"""
Returns the next client.
"""
if self.iter_index >= len(self.client_list):
if not self.client_list or self.iter_index >= len(self.client_list):
raise StopIteration
else:
self.iter_index += 1
Expand Down Expand Up @@ -423,7 +423,7 @@ def __next__(self):
"""
Returns the next workspace.
"""
if self.iter_index >= len(self.workspace_list):
if not self.workspace_list or self.iter_index >= len(self.workspace_list):
raise StopIteration
else:
self.iter_index += 1
Expand Down Expand Up @@ -499,7 +499,7 @@ def __next__(self):
"""
Returns the next project.
"""
if self.iter_index >= len(self.project_list):
if not self.project_list or self.iter_index >= len(self.project_list):
raise StopIteration
else:
self.iter_index += 1
Expand Down Expand Up @@ -734,7 +734,7 @@ def __str__(self):
"""
Returns a human-friendly string representation of this time entry.
"""
if self.data['duration'] > 0:
if float(self.data['duration']) > 0:
is_running = ' '
else:
is_running = '* '
Expand Down Expand Up @@ -771,6 +771,7 @@ def validate(self, exclude=[]):
* toggl doesn't require a description, but we do.
"""
required = [ 'start', 'duration', 'description', 'created_with' ];

for prop in required:
if not self.has(prop) and prop not in exclude:
Logger.debug(self.json())
Expand Down Expand Up @@ -824,7 +825,7 @@ def __next__(self):
"""
Returns the next time entry object.
"""
if self.iter_index >= len(self.time_entries):
if not self.time_entries or self.iter_index >= len(self.time_entries):
raise StopIteration
else:
self.iter_index += 1
Expand Down

0 comments on commit 8c687e3

Please sign in to comment.