Skip to content

Commit 5add2af

Browse files
committed
Fix constructor
1 parent 3a93db6 commit 5add2af

File tree

4 files changed

+57
-56
lines changed

4 files changed

+57
-56
lines changed

test/basetest/hooks.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ def __init__(self, original, error):
2727

2828

2929
def json_decoder(string):
30-
"""Attempt to decode a JSON string and in case of error return an
31-
InvalidJSON object
30+
"""Attempt to decode a JSON string and in case of error return an InvalidJSON object
3231
"""
3332
decoder = json.JSONDecoder().decode
3433

@@ -39,9 +38,7 @@ def json_decoder(string):
3938

4039

4140
class Hooks(object):
42-
"""
43-
Abstraction to help interact with hooks (add, remove) during tests and
44-
keep track of which are active.
41+
"""Abstraction to help interact with hooks (add, remove) during tests and keep track of which are active.
4542
"""
4643
def __init__(self, datadir):
4744
"""
@@ -69,8 +66,7 @@ def __repr__(self):
6966
enabled = ", ".join(enabled) or None
7067
disabled = ", ".join(disabled) or None
7168

72-
return "<Hooks: enabled: {0} | disabled: {1}>".format(enabled,
73-
disabled)
69+
return "<Hooks: enabled: {0} | disabled: {1}>".format(enabled, disabled)
7470

7571
def __getitem__(self, name):
7672
return self._hooks[name]
@@ -312,8 +308,7 @@ def __init__(self, *args, **kwargs):
312308
self.wrappedname = "original_" + self.hookname
313309
self.wrappedfile = os.path.join(self.hookdir, self.wrappedname)
314310

315-
self.original_wrapper = os.path.join(self.default_hookpath,
316-
"wrapper.sh")
311+
self.original_wrapper = os.path.join(self.default_hookpath, "wrapper.sh")
317312

318313
self.hooklog_in = self.wrappedfile + ".log.in"
319314
self.hooklog_out = self.wrappedfile + ".log.out"
@@ -373,7 +368,7 @@ def _use_cache(self):
373368
# Cache is outdated
374369
return False
375370
else:
376-
# Cache is up to date
371+
# Cache is up-to-date
377372
return True
378373

379374
def enable(self):

test/basetest/task.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,21 @@
1616

1717
class Task(object):
1818
"""
19-
Manage a task warrior instance
19+
Manage a Taskwarrior instance
2020
21-
A temporary folder is used as data store of task warrior.
22-
This class can be instantiated multiple times if multiple taskw clients are
23-
needed.
24-
25-
This class can be given a Taskd instance for simplified configuration.
21+
A temporary folder is used as data store of Taskwarrior.
22+
This class can be instantiated multiple times if multiple taskw clients are needed.
2623
2724
A taskw client should not be used after being destroyed.
2825
"""
2926
DEFAULT_TASK = task_binary_location()
3027

3128
def __init__(self, taskw=DEFAULT_TASK, datadir=tempfile.mkdtemp(prefix="task_"), taskrc=None):
3229
"""
33-
Initialize a Task warrior (client) that can interact with a taskd server.
34-
The task client runs in a temporary folder.
30+
Initialize a Taskwarrior (client) that can interact with a taskd server.
31+
The program runs in a temporary folder.
3532
36-
:arg taskw: Task binary to use as client (defaults: task in PATH)
33+
:arg taskw: Taskwarrior binary to use as client (defaults: task in PATH)
3734
"""
3835
self.taskw = taskw
3936

@@ -118,8 +115,7 @@ def export(self, export_filter=None):
118115
if export_filter is None:
119116
export_filter = ""
120117

121-
code, out, err = self.runSuccess("rc.json.array=1 {0} export"
122-
"".format(export_filter))
118+
code, out, err = self.runSuccess("rc.json.array=1 {0} export".format(export_filter))
123119

124120
return json.loads(out)
125121

@@ -254,7 +250,7 @@ def destroy(self):
254250
self.destroy = lambda: None
255251

256252
def __destroyed(self, *args, **kwargs):
257-
raise AttributeError("Task instance has been destroyed. "
253+
raise AttributeError("Taskwarrior instance has been destroyed. "
258254
"Create a new instance if you need a new client.")
259255

260256
def diag(self, merge_streams_with=None):

test/basetest/timew.py

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Timew(object):
1515
"""
1616
Manage a Timewarrior instance
1717
18-
A temporary folder is used as data store of timewarrior.
18+
A temporary folder is used as data store of Timewarrior.
1919
2020
A timew client should not be used after being destroyed.
2121
"""
@@ -26,7 +26,7 @@ def __init__(self,
2626
datadir=tempfile.mkdtemp(prefix="timew_"),
2727
configdir=tempfile.mkdtemp(prefix="timew_")):
2828
"""
29-
Initialize a timewarrior (client).
29+
Initialize a Timewarrior client.
3030
The program runs in a temporary folder.
3131
3232
:arg timew: Timewarrior binary to use as client (defaults: timew in PATH)
@@ -48,6 +48,14 @@ def __init__(self,
4848

4949
self.reset_env()
5050

51+
def __repr__(self):
52+
txt = super(Timew, self).__repr__()
53+
return "{0} running from {1}>".format(txt[:-1], self.datadir)
54+
55+
def __call__(self, *args, **kwargs):
56+
"""aka t = Timew() ; t() which is now an alias to t.runSuccess()"""
57+
return self.runSuccess(*args, **kwargs)
58+
5159
def reset(self, keep_config=False, keep_extensions=False):
5260
"""Reset this instance to its maiden state"""
5361

@@ -70,14 +78,6 @@ def add_default_extension(self, filename):
7078

7179
shutil.copy(os.path.join(DEFAULT_EXTENSION_PATH, filename), extfile)
7280

73-
def __repr__(self):
74-
txt = super(Timew, self).__repr__()
75-
return "{0} running from {1}>".format(txt[:-1], self.datadir)
76-
77-
def __call__(self, *args, **kwargs):
78-
"""aka t = Timew() ; t() which is now an alias to t.runSuccess()"""
79-
return self.runSuccess(*args, **kwargs)
80-
8181
def reset_env(self):
8282
"""Set a new environment derived from the one used to launch the test"""
8383
# Copy all env variables to avoid clashing subprocess environments
@@ -86,8 +86,7 @@ def reset_env(self):
8686
# As well as TIMEWARRIORDB
8787
self.env["TIMEWARRIORDB"] = self.datadir
8888

89-
# As well as MANPATH, so that the help tests can find the
90-
# uninstalled man pages
89+
# As well as MANPATH, so that the help tests can find the uninstalled man pages
9190
parts = self.timew.split(os.path.sep)[0:-2]
9291
parts.append("doc")
9392
self.env["MANPATH"] = os.path.sep.join(parts)
@@ -97,6 +96,27 @@ def config(self, var, value):
9796
cmd = (self.timew, ":yes", "config", var, value)
9897
return run_cmd_wait(cmd, env=self.env)
9998

99+
def del_config(self, var):
100+
"""Remove `var` from timew config"""
101+
cmd = (self.timew, ":yes", "config", var)
102+
return run_cmd_wait(cmd, env=self.env)
103+
104+
@property
105+
def timewrc_content(self):
106+
"""Returns the contents of the timewrc file."""
107+
108+
with open(self.timewrc, "r") as f:
109+
return f.readlines()
110+
111+
def export(self, export_filter=None):
112+
"""Run "timew export", return JSON array of exported intervals."""
113+
if export_filter is None:
114+
export_filter = ""
115+
116+
code, out, err = self.runSuccess("{0} export".format(export_filter))
117+
118+
return json.loads(out)
119+
100120
@staticmethod
101121
def _create_exclusion_interval(interval):
102122
if not isinstance(interval, tuple):
@@ -134,27 +154,6 @@ def configure_exclusions(self, intervals):
134154
self.config("exclusions.saturday", exclusion)
135155
self.config("exclusions.sunday", exclusion)
136156

137-
def del_config(self, var):
138-
"""Remove `var` from timew config"""
139-
cmd = (self.timew, ":yes", "config", var)
140-
return run_cmd_wait(cmd, env=self.env)
141-
142-
@property
143-
def timewrc_content(self):
144-
"""Returns the contents of the timewrc file."""
145-
146-
with open(self.timewrc, "r") as f:
147-
return f.readlines()
148-
149-
def export(self, export_filter=None):
150-
"""Run "timew export", return JSON array of exported intervals."""
151-
if export_filter is None:
152-
export_filter = ""
153-
154-
code, out, err = self.runSuccess("{0} export".format(export_filter))
155-
156-
return json.loads(out)
157-
158157
@staticmethod
159158
def _split_string_args_if_string(args):
160159
"""
@@ -258,7 +257,7 @@ def destroy(self):
258257
self.destroy = lambda: None
259258

260259
def __destroyed(self, *args, **kwargs):
261-
raise AttributeError("Program instance has been destroyed. "
260+
raise AttributeError("Timewarrior instance has been destroyed. "
262261
"Create a new instance if you need a new client.")
263262

264263
def faketime(self, faketime=None):

test/test_on-modify_e2e.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def setUp(self):
5353
self.task.reset(keep_config=True, keep_hooks=True)
5454
self.task.deactivate_hooks()
5555

56+
#@pytest.mark.skip
5657
def test_hook_should_process_annotate(self):
5758
"""on-modify hook should process 'task annotate'"""
5859
self.task.deactivate_hooks()
@@ -67,6 +68,7 @@ def test_hook_should_process_annotate(self):
6768
self.assertEqual(len(j), 1)
6869
self.assertOpenInterval(j[0], expectedTags=["Foo"], expectedAnnotation="Annotation")
6970

71+
#@pytest.mark.skip
7072
def test_hook_should_process_append(self):
7173
"""on-modify hook should process 'task append'"""
7274
self.task.deactivate_hooks()
@@ -81,6 +83,7 @@ def test_hook_should_process_append(self):
8183
self.assertEqual(len(j), 1)
8284
self.assertOpenInterval(j[0], expectedTags=["Foo Bar"])
8385

86+
#@pytest.mark.skip
8487
def test_hook_should_process_delete(self):
8588
"""on-modify hook should process 'task delete'"""
8689
self.task.deactivate_hooks()
@@ -95,6 +98,7 @@ def test_hook_should_process_delete(self):
9598
self.assertEqual(len(j), 1)
9699
self.assertClosedInterval(j[0], expectedTags=["Foo"])
97100

101+
#@pytest.mark.skip
98102
def test_hook_should_process_denotate(self):
99103
"""on-modify hook should process 'task denotate'"""
100104
self.task.deactivate_hooks()
@@ -111,6 +115,7 @@ def test_hook_should_process_denotate(self):
111115
self.assertEqual(len(j), 1)
112116
self.assertOpenInterval(j[0], expectedTags=["Foo"], expectedAnnotation="")
113117

118+
#@pytest.mark.skip
114119
def test_hook_should_process_done(self):
115120
"""on-modify hook should process 'task done'"""
116121
self.task.deactivate_hooks()
@@ -125,6 +130,7 @@ def test_hook_should_process_done(self):
125130
self.assertEqual(len(j), 1)
126131
self.assertClosedInterval(j[0], expectedTags=["Foo"])
127132

133+
#@pytest.mark.skip
128134
def test_hook_should_process_modify_description(self):
129135
"""on-modify hook should process 'task modify' for changing description"""
130136
self.task.deactivate_hooks()
@@ -139,6 +145,7 @@ def test_hook_should_process_modify_description(self):
139145
self.assertEqual(len(j), 1)
140146
self.assertOpenInterval(j[0], expectedTags=["Bar"])
141147

148+
#@pytest.mark.skip
142149
def test_hook_should_process_modify_tags(self):
143150
"""on-modify hook should process 'task modify' for changing tags"""
144151
self.task.deactivate_hooks()
@@ -154,6 +161,7 @@ def test_hook_should_process_modify_tags(self):
154161
self.assertEqual(len(j), 1)
155162
self.assertOpenInterval(j[0], expectedTags=["Foo", "Tag", "Baz"])
156163

164+
#@pytest.mark.skip
157165
def test_hook_should_process_modify_project(self):
158166
"""on-modify hook should process 'task modify' for changing project"""
159167
self.task.deactivate_hooks()
@@ -168,6 +176,7 @@ def test_hook_should_process_modify_project(self):
168176
self.assertEqual(len(j), 1)
169177
self.assertOpenInterval(j[0], expectedTags=["Foo", "test"])
170178

179+
#@pytest.mark.skip
171180
def test_hook_should_process_prepend(self):
172181
"""on-modify hook should process 'task prepend'"""
173182
self.task.deactivate_hooks()
@@ -182,6 +191,7 @@ def test_hook_should_process_prepend(self):
182191
self.assertEqual(len(j), 1)
183192
self.assertOpenInterval(j[0], expectedTags=["Prefix Foo"])
184193

194+
#@pytest.mark.skip
185195
def test_hook_should_process_start(self):
186196
"""on-modify hook should process 'task start'"""
187197
self.task.deactivate_hooks()
@@ -194,6 +204,7 @@ def test_hook_should_process_start(self):
194204
self.assertEqual(len(j), 1)
195205
self.assertOpenInterval(j[0], expectedTags=["Foo"])
196206

207+
#@pytest.mark.skip
197208
def test_hook_should_process_stop(self):
198209
"""on-modify hook should process 'task stop'"""
199210
self.task.deactivate_hooks()

0 commit comments

Comments
 (0)