mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-19 09:53:08 +02:00
Tests: Create compat.py for Python 3 compatibility
Individual tests are not yet fully compatible with Python 3. Some still have issues with I/O encoding/decoding. The painful part...
This commit is contained in:
parent
341b528980
commit
3c7187d801
3 changed files with 15 additions and 10 deletions
9
test/basetest/compat.py
Normal file
9
test/basetest/compat.py
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
try:
|
||||||
|
STRING_TYPE = basestring
|
||||||
|
except NameError:
|
||||||
|
# Python 3
|
||||||
|
STRING_TYPE = str
|
||||||
|
|
||||||
|
# vim: ai sts=4 et sw=4
|
|
@ -10,6 +10,7 @@ import unittest
|
||||||
from .exceptions import CommandError
|
from .exceptions import CommandError
|
||||||
from .hooks import Hooks
|
from .hooks import Hooks
|
||||||
from .utils import run_cmd_wait, run_cmd_wait_nofail, which, task_binary_location
|
from .utils import run_cmd_wait, run_cmd_wait_nofail, which, task_binary_location
|
||||||
|
from .compat import STRING_TYPE
|
||||||
|
|
||||||
|
|
||||||
class Task(object):
|
class Task(object):
|
||||||
|
@ -163,14 +164,7 @@ class Task(object):
|
||||||
argument. The string is literally the same as if written in the shell.
|
argument. The string is literally the same as if written in the shell.
|
||||||
"""
|
"""
|
||||||
# Enable nicer-looking calls by allowing plain strings
|
# Enable nicer-looking calls by allowing plain strings
|
||||||
try:
|
if isinstance(args, STRING_TYPE):
|
||||||
# Python 2.x
|
|
||||||
type_check = basestring
|
|
||||||
except NameError:
|
|
||||||
# Python 3.x
|
|
||||||
type_check = str
|
|
||||||
|
|
||||||
if isinstance(args, type_check):
|
|
||||||
args = shlex.split(args)
|
args = shlex.split(args)
|
||||||
|
|
||||||
return args
|
return args
|
||||||
|
|
|
@ -38,6 +38,7 @@ sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
from basetest import Task, TestCase
|
from basetest import Task, TestCase
|
||||||
from basetest.utils import UUID_REGEXP
|
from basetest.utils import UUID_REGEXP
|
||||||
|
from basetest.compat import STRING_TYPE
|
||||||
|
|
||||||
DATETIME_FORMAT = "%Y%m%dT%H%M%SZ"
|
DATETIME_FORMAT = "%Y%m%dT%H%M%SZ"
|
||||||
|
|
||||||
|
@ -60,7 +61,7 @@ class TestExportCommand(TestCase):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Timestamps should be exported as strings
|
# Timestamps should be exported as strings
|
||||||
self.assertType(value, unicode)
|
self.assertType(value, STRING_TYPE)
|
||||||
# And they should follow the %Y%m%dT%H%M%SZ format
|
# And they should follow the %Y%m%dT%H%M%SZ format
|
||||||
datetime.datetime.strptime(value, DATETIME_FORMAT)
|
datetime.datetime.strptime(value, DATETIME_FORMAT)
|
||||||
|
|
||||||
|
@ -71,7 +72,7 @@ class TestExportCommand(TestCase):
|
||||||
regular expression object.
|
regular expression object.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.assertType(value, unicode)
|
self.assertType(value, STRING_TYPE)
|
||||||
|
|
||||||
if expected_value is not None:
|
if expected_value is not None:
|
||||||
if regexp:
|
if regexp:
|
||||||
|
@ -192,6 +193,7 @@ class TestExportCommand(TestCase):
|
||||||
self.t('add estimate:month test duration uda')
|
self.t('add estimate:month test duration uda')
|
||||||
self.assertString(self.export('2')['estimate'], 'month')
|
self.assertString(self.export('2')['estimate'], 'month')
|
||||||
|
|
||||||
|
|
||||||
class TestExportCommandLimit(TestCase):
|
class TestExportCommandLimit(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.t = Task()
|
self.t = Task()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue