-
-
Notifications
You must be signed in to change notification settings - Fork 241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
time only support for watson add #282
Open
jdckr
wants to merge
5
commits into
jazzband:master
Choose a base branch
from
jdckr:addTimeOnly
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f28f554
improve usability of watson add
jdckr 449181f
updated documentation
jdckr db1968c
bugfix for watson add with 2 datetimes
jdckr c759b46
fixed line endings for documentation
jdckr 5729d3e
moved helper functions to utils.py + added tests
jdckr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
from watson import cli | ||
from click.testing import CliRunner | ||
import json | ||
import os | ||
import arrow | ||
import pytest | ||
|
||
@pytest.fixture | ||
def setup(tmpdir): | ||
os.environ["WATSON_DIR"] = tmpdir.strpath | ||
|
||
# test for watson add <project> --from "hh:mm" --to "hh:mm" | ||
def test_time_only(setup): | ||
|
||
runner = CliRunner() | ||
|
||
test_data = [("13:00", "15:00"), | ||
("3:00", "17:00"), | ||
("1:00", "3:41")] | ||
|
||
project = "test_time_only" | ||
data_index = 0 | ||
|
||
for data in test_data: | ||
from_time = data[0] | ||
to_time = data[1] | ||
|
||
result = runner.invoke(cli.cli, ["add", project, '--from' , from_time, '--to', to_time]) | ||
|
||
result = runner.invoke(cli.cli, ["log", "-j"]) | ||
output = json.loads(result.output)[data_index] | ||
|
||
assert output["project"] == project | ||
today = arrow.now().floor("day").format("YYYY-MM-DD") | ||
assert today in output["start"] | ||
assert from_time in output["start"] | ||
assert today in output["stop"] | ||
assert to_time in output["stop"] | ||
|
||
data_index += 1 | ||
|
||
# test for watson add <project> --from "yyyy-mm-dd hh:mm" --to "hh:mm" | ||
def test_from_date_time(setup): | ||
runner = CliRunner() | ||
|
||
test_data = [("2016-03-24", "07:32", "08:54"), | ||
("2017-04-28", "14:00", "17:31")] | ||
|
||
project = "test_date_time" | ||
|
||
for data in test_data: | ||
date = data[0] | ||
from_time = data[1] | ||
to_time = data[2] | ||
|
||
result = runner.invoke(cli.cli, ["add", project, '--from' , "{} {}".format(date, from_time), '--to', to_time]) | ||
|
||
# as watson log -a crashes, I use -f <date> | ||
result = runner.invoke(cli.cli, ["log", "-f", date, "-j"]) | ||
runner.invoke(cli.cli, ["log"]) | ||
output = json.loads(result.output)[0] | ||
|
||
assert output["project"] == project | ||
assert date in output["start"] | ||
assert from_time in output["start"] | ||
assert date in output["stop"] | ||
assert to_time in output["stop"] | ||
|
||
# test for watson add <project> --from "yyyy-mm-dd hh:mm" --to ""yyyy-mm-dd hh:mm" | ||
def test_date_time(setup): | ||
runner = CliRunner() | ||
|
||
test_data = [("2016-03-24", "07:32", "08:54"), | ||
("2017-04-28", "14:00", "17:31")] | ||
|
||
project = "test_date_time" | ||
|
||
for data in test_data: | ||
date = data[0] | ||
from_time = data[1] | ||
to_time = data[2] | ||
|
||
result = runner.invoke(cli.cli, ["add", project, '--from' , "{} {}".format(date, from_time), '--to', "{} {}".format(date, to_time)]) | ||
|
||
# as watson log -a crashes, I use -f <date> | ||
result = runner.invoke(cli.cli, ["log", "-f", date, "-j"]) | ||
runner.invoke(cli.cli, ["log"]) | ||
output = json.loads(result.output)[0] | ||
|
||
assert output["project"] == project | ||
assert date in output["start"] | ||
assert from_time in output["start"] | ||
assert date in output["stop"] | ||
assert to_time in output["stop"] | ||
|
||
def test_format_not_supported(setup): | ||
runner = CliRunner() | ||
|
||
result = runner.invoke(cli.cli, ["add", "test", "--from", "crash 13:30", "--to", "13:37"]) | ||
assert "Format not supported" in result.output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if Arrow doesn't provide something to help with that. It feels a bit tedious to introduce our own regexp to parse the date & times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have checked the api and didn't find s.th. appropriate. But I am open for suggestions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been looking into it and there's something I don't understand: why are there two different click types
Date
andTime
incli.py
?It turns out that both accept the full date, but using different formats!
TimeParamType
(aka,Time
) is only used inwatson stop
:DateParamType
(aka,Date
) is used in every other place where a date is required:In my opinion, the following changes might solve issue #278 in a simpler way:
Date
toDateTime
which is more appropriate to what it does. Of course, rename also the correspondingParamType
classes.DateTime
to receive time only dates, which is precisely what theTime
type does. You could reuse the code.DateTime
whereTime
was used (i.e.watson stop
).Time
andTimeParamType
.Please, remember that I'm not a member of this project, so I might be missing important stuff!! :-) what do you think @k4nar?
I think date/time input format is one of the aspects where Watson could get a nice improvement, so it's great that there's someone working on it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea. I didn't dive deep so I was not aware of TimeParamType which is basically doing what I implemented to handle time only.
I also couldn't agree more that the api is not consistent for the different cmds and it felt like adding another balcony.
The only drawback I see so far is that it will be hard to handle the case where we want to reuse the date specified for --from for --to as the parameter processing would be done without the knowledge about the other parameter.