Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions taskwiki/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,14 @@ def task_info_or_vimwiki_follow_link():
']]' in line,
column >= line.find('[['),
column <= line.find(']]') + 1
]) or all([
'[' in line,
'](' in line,
')' in line,
line.find('[') < line.find(']('),
line.find('](') < line.find(')'),
column >= line.find('['),
column <= line.find(')') + 1
])

if inside_vimwiki_link:
Expand Down
12 changes: 8 additions & 4 deletions taskwiki/regexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@
re.compile(
r'^' # Starts at the begging of the line
r'(?P<header_start>[=]+)' # Heading begging
r'(?P<name>[^=\|\[\{]*)' # Name of the viewport, all before the | sign
# Cannot include '[', '=', '|', and '{'

r'(?P<name>([^=\|\[\{]*)|(\s*\{\{.*}}\s*)|(.*\[\[.*]].*))'
# Name of the viewport, either with
# a vimwiki link or without
# Cannot include '='

r'\|' # Bar
r'(?!\|)' # (But not two, that would be a preset)
r'(?P<filter>[^=\|]*?)' # Filter
Expand All @@ -68,8 +72,8 @@
re.compile(
r'^' # Starts at the begging of the line
r'(?P<header_start>[#]+)' # Heading begging
r'(?P<name>[^#\|\[\{]*)' # Name of the viewport, all before the | sign
# Cannot include '[', '#', '|', and '{'
r'(?P<name>[^#\|]*)' # Name of the viewport, all before the | sign
# Cannot include '#'
r'\|' # Bar
r'(?!\|)' # (But not two, that would be a preset)
r'(?P<filter>[^#\|]*?)' # Filter
Expand Down
12 changes: 6 additions & 6 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def configure_global_variables(self):
self.command('let g:taskwiki_taskrc_location="{0}"'.format(self.taskrc_path))
self.command('let g:vimwiki_list = [{"syntax": "%s", "ext": ".txt","path": "%s"}]' % (self.markup, self.dir))

def setup(self):
def setup_method(self):
assert not self.client

self.generate_data()
Expand All @@ -89,7 +89,7 @@ def setup(self):
self.filepath = os.path.join(self.dir, 'testwiki.txt')
self.client.edit(self.filepath)

def teardown(self):
def teardown_method(self):
if not self.client:
return

Expand Down Expand Up @@ -213,8 +213,8 @@ def test_execute(self):
success = True
break
else:
self.teardown()
self.setup()
self.teardown_method()
self.setup_method()

if not success:
self.check_sanity(soft=False)
Expand Down Expand Up @@ -242,9 +242,9 @@ class MultiSyntaxIntegrationTest(IntegrationTest):

markup = None

def setup(self):
def setup_method(self):
if self.markup:
super(MultiSyntaxIntegrationTest, self).setup()
super(MultiSyntaxIntegrationTest, self).setup_method()
else:
pass

Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def header_expand(string):
inclusive.
"""
for header_level, format_header in format_header_dict.items():
regex = header_level + '\((.*?)\)'
regex = header_level + r'\((.*)\)'
string = re.sub(regex,
lambda match: format_header % match.group(1),
string)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_preset_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@


class TestParsingPresetHeader(object):
def setup(self):
def setup_method(self):
self.mockvim = MockVim()
self.cache = MockCache()

sys.modules['vim'] = self.mockvim
from taskwiki.preset import PresetHeader
self.PresetHeader = PresetHeader

def teardown(self):
def teardown_method(self):
self.mockvim.reset()
self.cache.reset()

Expand Down
28 changes: 13 additions & 15 deletions tests/test_selected.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import re

from datetime import datetime
from tasklib import local_zone
from tests.base import IntegrationTest


Expand Down Expand Up @@ -578,7 +577,7 @@ def execute(self):
for task in self.tasks:
task.refresh()

now = local_zone.localize(datetime.now())
now = datetime.now().astimezone()

assert self.tasks[0]['status'] == "pending"
assert self.tasks[1]['status'] == "pending"
Expand Down Expand Up @@ -621,7 +620,7 @@ def execute(self):
for task in self.tasks:
task.refresh()

now = local_zone.localize(datetime.now())
now = datetime.now().astimezone()

assert self.tasks[0]['status'] == "pending"
assert self.tasks[1]['status'] == "pending"
Expand Down Expand Up @@ -659,7 +658,7 @@ def execute(self):
for task in self.tasks:
task.refresh()

now = local_zone.localize(datetime.now())
now = datetime.now().astimezone()

assert self.tasks[0]['status'] == "pending"
assert self.tasks[1]['status'] == "pending"
Expand Down Expand Up @@ -696,7 +695,7 @@ def execute(self):
for task in self.tasks:
task.refresh()

now = local_zone.localize(datetime.now())
now = datetime.now().astimezone()

assert self.tasks[0]['status'] == "pending"
assert self.tasks[1]['status'] == "pending"
Expand Down Expand Up @@ -744,7 +743,7 @@ def execute(self):
for task in self.tasks:
task.refresh()

now = local_zone.localize(datetime.now())
now = datetime.now().astimezone()

assert self.tasks[0]['status'] == "pending"
assert self.tasks[1]['status'] == "pending"
Expand Down Expand Up @@ -782,7 +781,7 @@ def execute(self):
for task in self.tasks:
task.refresh()

now = local_zone.localize(datetime.now())
now = datetime.now().astimezone().astimezone()

assert self.tasks[0]['status'] == "pending"
assert self.tasks[1]['status'] == "pending"
Expand Down Expand Up @@ -820,7 +819,7 @@ def execute(self):
for task in self.tasks:
task.refresh()

now = local_zone.localize(datetime.now())
now = datetime.now().astimezone()

assert self.tasks[0]['status'] == "pending"
assert self.tasks[1]['status'] == "pending"
Expand Down Expand Up @@ -899,7 +898,7 @@ def execute(self):
for task in self.tasks:
task.refresh()

now = local_zone.localize(datetime.now())
now = datetime.now().astimezone()

assert self.tasks[0]['status'] == "pending"
assert self.tasks[1]['status'] == "pending"
Expand Down Expand Up @@ -1056,8 +1055,7 @@ class TestModVisibleAction(IntegrationTest):
]

def execute(self):
today = local_zone.localize(
datetime.now().replace(hour=0,minute=0,second=0,microsecond=0))
today = datetime.now().replace(hour=0,minute=0,second=0,microsecond=0).astimezone()

self.command(
"TaskWikiMod due:today",
Expand Down Expand Up @@ -1164,7 +1162,7 @@ def execute(self):
for task in self.tasks:
task.refresh()

now = local_zone.localize(datetime.now())
now = datetime.now().astimezone()

assert self.tasks[0]['status'] == "completed"
assert self.tasks[1]['status'] == "pending"
Expand Down Expand Up @@ -1231,7 +1229,7 @@ def execute(self):
for task in self.tasks:
task.refresh()

now = local_zone.localize(datetime.now())
now = datetime.now().astimezone()

assert self.tasks[0]['status'] == "pending"
assert self.tasks[1]['status'] == "completed"
Expand Down Expand Up @@ -1268,7 +1266,7 @@ def execute(self):
for task in self.tasks:
task.refresh()

now = local_zone.localize(datetime.now())
now = datetime.now().astimezone()

assert self.tasks[0]['status'] == "completed"
assert self.tasks[1]['status'] == "completed"
Expand Down Expand Up @@ -1315,7 +1313,7 @@ def execute(self):
for task in self.tasks:
task.refresh()

now = local_zone.localize(datetime.now())
now = datetime.now().astimezone()

assert self.tasks[0]['status'] == "completed"
assert self.tasks[1]['status'] == "completed"
Expand Down
5 changes: 2 additions & 3 deletions tests/test_splits.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import re

from tests.base import IntegrationTest
from tasklib import local_zone
from datetime import datetime


def current_year():
return local_zone.localize(datetime.now()).year
return datetime.now().astimezone().year


def current_month():
current_month_number = local_zone.localize(datetime.now()).month
current_month_number = datetime.now().astimezone().month
months = ["January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December"]
Expand Down
76 changes: 74 additions & 2 deletions tests/test_viewport_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class TestParsingVimwikiTask(object):
def setup(self):
def setup_method(self):
self.mockvim = MockVim()
self.cache = MockCache()

Expand All @@ -19,7 +19,7 @@ def setup(self):
from taskwiki.viewport import ViewPort
self.ViewPort = ViewPort

def teardown(self):
def teardown_method(self):
self.mockvim.reset()
self.cache.reset()

Expand Down Expand Up @@ -159,3 +159,75 @@ def test_override_default_virtual_tags_positive_without_forcing(self, test_synta
assert port.defaults == {'project':'Home'}
assert port.sort == DEFAULT_SORT_ORDER
assert port.tw == 'default'

def test_vimwiki_link_as_header_name_simple(self, test_syntax):
if test_syntax[0] == 'default':
example_viewport = "HEADER2([[Test|https://www.vim.org]] | project:Home)"
elif test_syntax[0] == 'markdown':
example_viewport = "HEADER2([Test](https://www.vim.org) | project:Home)"

port = self.process_viewport(example_viewport, test_syntax)

assert port.taskfilter == list(DEFAULT_VIEWPORT_VIRTUAL_TAGS) + ["(", "project:Home", ")"]

if test_syntax[0] == 'default':
assert port.name == "[[Test|https://www.vim.org]]"
elif test_syntax[0] == 'markdown':
assert port.name == "[Test](https://www.vim.org)"

assert port.defaults == {'project':'Home'}
assert port.sort == DEFAULT_SORT_ORDER
assert port.tw == 'default'

def test_vimwiki_link_as_header_name_with_defaults(self, test_syntax):
if test_syntax[0] == 'default':
example_viewport = "HEADER2([[Test|https://www.vim.org]] | project:Home)"
elif test_syntax[0] == 'markdown':
example_viewport = "HEADER2([Test](https://www.vim.org) | project:Home)"

port = self.process_viewport(example_viewport, test_syntax)

assert port.taskfilter == list(DEFAULT_VIEWPORT_VIRTUAL_TAGS) + ["(", "project:Home", ")"]
if test_syntax[0] == 'default':
assert port.name == "[[Test|https://www.vim.org]]"
elif test_syntax[0] == 'markdown':
assert port.name == "[Test](https://www.vim.org)"
assert port.defaults == {'project':'Home'}
assert port.sort == DEFAULT_SORT_ORDER
assert port.tw == 'default'

def test_vimwiki_link_in_header_name_simple(self, test_syntax):
if test_syntax[0] == 'default':
example_viewport = "HEADER2(Link to [[this|https://www.vim.org]] | project:Home)"
elif test_syntax[0] == 'markdown':
example_viewport = "HEADER2(Link to [this](https://www.vim.org) | project:Home)"

port = self.process_viewport(example_viewport, test_syntax)

assert port.taskfilter == list(DEFAULT_VIEWPORT_VIRTUAL_TAGS) + ["(", "project:Home", ")"]

if test_syntax[0] == 'default':
assert port.name == "Link to [[this|https://www.vim.org]]"
elif test_syntax[0] == 'markdown':
assert port.name == "Link to [this](https://www.vim.org)"

assert port.defaults == {'project':'Home'}
assert port.sort == DEFAULT_SORT_ORDER
assert port.tw == 'default'

def test_vimwiki_link_in_header_name_with_defaults(self, test_syntax):
if test_syntax[0] == 'default':
example_viewport = "HEADER2(Link to [[this|https://www.vim.org]] | project:Home)"
elif test_syntax[0] == 'markdown':
example_viewport = "HEADER2(Link to [this](https://www.vim.org) | project:Home)"

port = self.process_viewport(example_viewport, test_syntax)

assert port.taskfilter == list(DEFAULT_VIEWPORT_VIRTUAL_TAGS) + ["(", "project:Home", ")"]
if test_syntax[0] == 'default':
assert port.name == "Link to [[this|https://www.vim.org]]"
elif test_syntax[0] == 'markdown':
assert port.name == "Link to [this](https://www.vim.org)"
assert port.defaults == {'project':'Home'}
assert port.sort == DEFAULT_SORT_ORDER
assert port.tw == 'default'
7 changes: 3 additions & 4 deletions tests/test_vwtask.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-

from datetime import datetime
from tasklib import local_zone
from tests.base import IntegrationTest, MultipleSourceTest


Expand Down Expand Up @@ -292,7 +291,7 @@ def execute(self):
task = self.tw.tasks.pending()[0]
assert task['description'] == 'This is a test task'
assert task['status'] == 'pending'
assert task['due'] == local_zone.localize(due)
assert task['due'] == due.astimezone()


class TestSimpleTaskWithFlawedDueDatetimeCreation(IntegrationTest):
Expand Down Expand Up @@ -338,7 +337,7 @@ def execute(self):
task = self.tw.tasks.pending()[0]
assert task['description'] == 'This is a test task'
assert task['status'] == 'pending'
assert task['due'] == local_zone.localize(due)
assert task['due'] == due.astimezone()


class TestSimpleTaskWithDueDatetimeModification(IntegrationTest):
Expand Down Expand Up @@ -373,7 +372,7 @@ def execute(self):
task = self.tw.tasks.pending()[0]
assert task['description'] == 'This is a test task'
assert task['status'] == 'pending'
assert task['due'] == local_zone.localize(due)
assert task['due'] == due.astimezone()


class TestSimpleTaskWithPriorityCreation(IntegrationTest):
Expand Down
Loading