Skip to content

Commit ea72762

Browse files
authored
Merge pull request #65 from AlexanderWillner/main
implement things.trash for #16
2 parents 1d07864 + 278b2d7 commit ea72762

File tree

12 files changed

+114
-22
lines changed

12 files changed

+114
-22
lines changed

.coveragerc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
exclude_lines =
44
if __name__ == .__main__.:
5+
pragma: no cover
56

67
omit =
78
setup.py

.pre-commit-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ repos:
88
- id: end-of-file-fixer
99
- id: check-yaml
1010
- id: check-added-large-files
11+
- repo: https://github.com/pycqa/isort
12+
rev: 5.8.0
13+
hooks:
14+
- id: isort
1115
- repo: https://github.com/psf/black
1216
rev: 20.8b1
1317
hooks:

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ clean: ## Cleanup
5454
@rm -rf .tox
5555

5656
auto-style: ## Style the code
57+
@if type isort >/dev/null 2>&1 ; then isort . ; \
58+
else echo "SKIPPED. Run '$(PIP) install isort' first." >&2 ; fi
59+
@if type autoflake >/dev/null 2>&1 ; then autoflake -r --in-place --remove-unused-variables . ; \
60+
else echo "SKIPPED. Run '$(PIP) install isort' first." >&2 ; fi
5761
@if type black >/dev/null 2>&1 ; then black $(SRC_CORE) ; \
5862
else echo "SKIPPED. Run '$(PIP) install black' first." >&2 ; fi
5963

@@ -107,8 +111,8 @@ upload: build ## Upload the code
107111
@echo "########################"
108112
@twine upload dist/things.py*
109113

110-
get-db:
114+
db-to-things:
111115
@cp tests/main.sqlite* ~/Library/Group\ Containers/JLMPQHK86H.com.culturedcode.ThingsMac/Things\ Database.thingsdatabase/
112116

113-
copy-db:
117+
db-from-things:
114118
@cp ~/Library/Group\ Containers/JLMPQHK86H.com.culturedcode.ThingsMac/Things\ Database.thingsdatabase/main.sqlite* tests/

setup.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ ignore = E501,E203,W503
1212

1313
[pylama]
1414
ignore = E501,E203,W503
15+
16+
[isort]
17+
lines_after_imports = 2
18+
force_sort_within_sections = True

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""A simple Python 3 library to read your Things app data."""
22

33
import os
4-
from setuptools import setup, find_packages # type: ignore
4+
5+
from setuptools import find_packages, setup # type: ignore
56

67

78
def package_files(directory):

tests/main.sqlite

0 Bytes
Binary file not shown.

tests/main.sqlite-shm

0 Bytes
Binary file not shown.

tests/main.sqlite-wal

23.9 KB
Binary file not shown.

tests/test_things.py

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
"""Module documentation goes here."""
55

6+
import contextlib
7+
import io
68
import os
79
import unittest
810

@@ -71,6 +73,26 @@ def test_inbox(self):
7173
tasks = things.inbox()
7274
self.assertEqual(2, len(tasks))
7375

76+
def test_trashed(self):
77+
"""Test getting trashed tasks."""
78+
tasks = things.trash()
79+
self.assertEqual(5, len(tasks))
80+
todos = things.todos(trashed=True)
81+
self.assertEqual(2, len(todos))
82+
projects = things.projects(trashed=True)
83+
self.assertEqual(1, len(projects))
84+
projects = things.projects(trashed=None)
85+
self.assertEqual(4, len(projects))
86+
projects = things.trash(type="project")
87+
self.assertEqual(1, len(projects))
88+
projects = things.trash(type="project", include_items=True)
89+
# TOOD: doesn't inlucde items
90+
# self.assertEqual(1, len(projects[0]["items"]))
91+
# tasks = list(
92+
# filter(lambda _: "in Deleted Project" in _["title"], projects[0]["items"])
93+
# )
94+
# self.assertEqual(1, len(tasks))
95+
7496
def test_upcoming(self):
7597
"""Test upcoming."""
7698
tasks = things.upcoming()
@@ -84,7 +106,7 @@ def test_deadlines(self):
84106
def test_today(self):
85107
"""Test today."""
86108
tasks = things.today()
87-
self.assertEqual(2, len(tasks))
109+
self.assertEqual(3, len(tasks))
88110

89111
def test_checklist(self):
90112
"""Test checklist."""
@@ -96,7 +118,7 @@ def test_checklist(self):
96118
def test_anytime(self):
97119
"""Test anytime."""
98120
tasks = things.anytime()
99-
self.assertEqual(11, len(tasks))
121+
self.assertEqual(12, len(tasks))
100122
self.assertTrue(any(task.get("area_title") == "Area 1" for task in tasks))
101123

102124
def test_logbook(self):
@@ -138,6 +160,8 @@ def test_todos(self):
138160
self.assertEqual(10, len(todos))
139161
todos = things.todos(include_items=True)
140162
self.assertEqual(12, len(todos))
163+
tasks = things.tasks(include_items=True)
164+
self.assertEqual(16, len(tasks))
141165
with self.assertRaises(ValueError):
142166
things.todos(status="wrong_value")
143167
todo = things.todos("A2oPvtt4dXoypeoLc8uYzY")
@@ -147,18 +171,36 @@ def test_tags(self):
147171
"""Test all tags."""
148172
tags = things.tags()
149173
self.assertEqual(5, len(tags))
150-
tasks = things.tasks(tag="Errand")
151-
self.assertEqual(1, len(tasks))
174+
tags = things.tags(include_items=True)
175+
self.assertEqual(5, len(tags))
176+
tags = things.tasks(tag="Errand")
177+
self.assertEqual(1, len(tags))
178+
tag = things.tags(title="Errand")
179+
self.assertEqual("Errand", tag["title"])
180+
181+
def test_get_link(self):
182+
link = things.link("uuid")
183+
self.assertEqual("things:///show?id=uuid", link)
152184

153185
def test_projects(self):
154186
"""Test all projects."""
155187
projects = things.projects()
156-
self.assertEqual(2, len(projects))
188+
self.assertEqual(3, len(projects))
189+
projects = things.projects(include_items=True)
190+
self.assertEqual(2, len(projects[0]["items"]))
157191

158192
def test_areas(self):
159193
"""Test all test_areas."""
160194
areas = things.areas()
161195
self.assertEqual(3, len(areas))
196+
areas = things.areas(include_items=True)
197+
self.assertEqual(3, len(areas))
198+
count = things.areas(count_only=True)
199+
self.assertEqual(3, count)
200+
with self.assertRaises(ValueError):
201+
things.areas("wrong-uuid")
202+
area = things.areas("Y3JC4XeyGWxzDocQL4aobo")
203+
self.assertEqual("Area 3", area["title"])
162204

163205
def test_database_version(self):
164206
"""Test database version."""
@@ -167,18 +209,21 @@ def test_database_version(self):
167209

168210
def test_last(self):
169211
"""Test last parameter"""
170-
last_tasks = things.last("1d")
212+
last_tasks = things.last("0d")
171213
self.assertEqual(len(last_tasks), 0)
172214

173215
last_tasks = things.last("10000w")
174-
self.assertEqual(len(last_tasks), 15)
216+
self.assertEqual(len(last_tasks), 16)
175217

176218
last_tasks = things.last("100y", status="completed")
177219
self.assertEqual(len(last_tasks), 10)
178220

179221
with self.assertRaises(ValueError):
180222
things.last(None)
181223

224+
with self.assertRaises(ValueError):
225+
things.last([])
226+
182227
with self.assertRaises(ValueError):
183228
things.last("XYZ")
184229

@@ -192,7 +237,6 @@ def test_tasks(self):
192237
"""Test tasks"""
193238
count = things.tasks(status="completed", last="100y", count_only=True)
194239
self.assertEqual(count, 10)
195-
196240
# special characters
197241
tasks = things.tasks(area='"')
198242
self.assertEqual(len(tasks), 0)
@@ -203,6 +247,20 @@ def test_tasks(self):
203247
with self.assertRaises(ValueError):
204248
things.tasks(area="\0")
205249

250+
def test_database(self):
251+
"""Test some database details"""
252+
output = io.StringIO()
253+
with contextlib.redirect_stdout(output):
254+
db = things.api.pop_database({})
255+
db.debug = True
256+
db.get_tags()
257+
self.assertTrue("H96sVJwE7VJveAnv7itmux" in output.getvalue())
258+
with contextlib.redirect_stdout(output):
259+
things.areas(print_sql=True)
260+
self.assertTrue("ORDER BY" in output.getvalue())
261+
with self.assertRaises(SystemExit): # noqa TODO: should actually NOT crash
262+
db.execute_query('"')
263+
206264

207265
if __name__ == "__main__":
208266
unittest.main()

things/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
today,
3131
todos,
3232
token,
33+
trash,
3334
upcoming,
3435
)
3536
from things.database import Database # noqa

0 commit comments

Comments
 (0)