Skip to content

Commit

Permalink
Fix unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
bergercookie committed Dec 31, 2023
1 parent 26d758e commit a00eb73
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
4 changes: 2 additions & 2 deletions syncall/taskwarrior/taskw_duration.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ def parse_iso8601_duration(string: str) -> timedelta:

def taskw_duration_serialize(value: timedelta) -> str:
"""
>>> duration_serialize(timedelta(days=300))
>>> taskw_duration_serialize(timedelta(days=300))
'PT25920000S'
>>> duration_serialize(timedelta(minutes=3))
>>> taskw_duration_serialize(timedelta(minutes=3))
'PT180S'
"""
# TODO atm (220220529) taskwarrior does not support float notation for its fields (i.e.,
Expand Down
9 changes: 3 additions & 6 deletions tests/test_data/sample_items.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ tw_item:
id: 276
modified: 2019-03-05 00:03:09
status: pending
twgcalsyncduration: "PT1200S"
syncallduration: "PT1200S"
tags:
- remindme
urgency: 0
Expand Down Expand Up @@ -104,22 +104,20 @@ gcal_item_w_date:
updated: '2019-03-16T16:01:32.486Z'
caldav_item_w_date:
priority: ''
created: 2019-03-16 16:01:32.00
due: 2019-03-09 00:00:00
id: 2s3acrn586e4ed7eff49ja91oh
start: 2019-03-10 23:00:00
status: 'needs-action'
summary: 'gcal original event'
last-modified: 2019-03-16 16:01:32.486
tw_item_w_date_expected:
twgcalsyncduration: "PT86400S"
syncallduration: "PT86400S"
annotations: []
description: gcal original event
due: 2019-03-09 00:00:00
status: pending
modified: 2019-03-16 16:01:32.486000
gcal_item:
created: '2019-03-08T00:29:06.000Z'
creator: {email: [email protected]}
description: '
Expand Down Expand Up @@ -152,7 +150,6 @@ gcal_item:
summary: another summary goes here
updated: '2019-03-08T00:29:06.602Z'
caldav_item:
created: 2019-03-08 00:29:06.000
description: '
The same old description
Expand All @@ -172,7 +169,7 @@ caldav_item:
last-modified: 2019-03-08 00:29:06.602
priority: ''
tw_item_expected:
twgcalsyncduration: "PT3600S"
syncallduration: "PT3600S"
annotations:
- kalimera
- kalinuxta kai kali vradia
Expand Down
21 changes: 15 additions & 6 deletions tests/test_tw_caldav_conversions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path
from typing import Dict

import yaml

Expand All @@ -24,7 +25,7 @@ def load_sample_items(self):
self.caldav_item = conts["caldav_item"]
self.tw_item_expected = conts["tw_item_expected"]

self.tw_item = conts["tw_item"]
self.tw_item: Dict[str, Any] = conts["tw_item"]
self.tw_item_w_due = conts["tw_item_w_due"]
self.caldav_item_expected = conts["caldav_item_expected"]
self.caldav_item_w_date_expected = conts["caldav_item_w_date_expected"]
Expand All @@ -33,20 +34,28 @@ def load_sample_items(self):
self.tw_item_w_date_expected = conts["tw_item_w_date_expected"]

# we don't care about this field yet.
self.tw_item.pop("twgcalsyncduration")
self.tw_item_expected.pop("twgcalsyncduration")
self.tw_item_w_date_expected.pop("twgcalsyncduration")
self.tw_item.pop("syncallduration")
self.tw_item_expected.pop("syncallduration")

self.tw_item_w_date_expected.pop("syncallduration")
if "entry" in self.tw_item_w_date_expected:
self.tw_item_w_date_expected.pop("entry")
if "created" in self.tw_item_w_date_expected:
self.tw_item_w_date_expected.pop("created")

def test_tw_caldav_basic_convert(self):
"""Basic TW -> Caldav conversion."""
self.load_sample_items()
tw_item = self.tw_item
caldav_item_out = convert_tw_to_caldav(self.tw_item)
caldav_item_out.pop("created", "")
self.assertDictEqual(caldav_item_out, self.caldav_item_expected)

def test_tw_caldav_w_due_convert(self):
"""Basic TW (with 'due' subfield) -> Caldav conversion."""
self.load_sample_items()
caldav_item_out = convert_tw_to_caldav(self.tw_item_w_due)
caldav_item_out.pop("created", "")
self.assertDictEqual(caldav_item_out, self.caldav_item_w_date_expected)

def test_caldav_tw_basic_convert(self):
Expand All @@ -68,11 +77,12 @@ def test_tw_caldav_n_back(self):
# UGLY - Rewrite how we do testing for caldav<>tw and gcal<>tw
intermediate_caldav = convert_tw_to_caldav(self.tw_item)
intermediate_caldav["priority"] = ""
intermediate_caldav.pop("created", "")

tw_item_out = convert_caldav_to_tw(intermediate_caldav)
self.assertSetEqual(
set(self.tw_item) ^ set(tw_item_out),
set({"id", "urgency", "entry"}),
set({"id", "urgency", "entry", "entry"}),
)

intersection = set(self.tw_item) & set(tw_item_out)
Expand All @@ -93,7 +103,6 @@ def test_caldav_tw_n_back(self):
set(self.caldav_item) ^ set(caldav_item_out),
set(
{
"created",
"id",
}
),
Expand Down

0 comments on commit a00eb73

Please sign in to comment.