Skip to content

Commit

Permalink
Merge branch 'master' into note-flag
Browse files Browse the repository at this point in the history
  • Loading branch information
joelostblom committed Jun 18, 2020
2 parents c8e5edd + 2cb871e commit 3745115
Show file tree
Hide file tree
Showing 13 changed files with 267 additions and 62 deletions.
21 changes: 20 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Log output order can now be controlled via the `--reverse/--no-reverse` flag
and the `reverse_log` configuration option (#369)
- Add `--at` flag to the `start` and `restart` commands (#364).

### Changed

- Require latest Arrow version 0.15.6 to support ISO week dates (#380)

## [1.9.0] - 2020-05-27

### Added

- Improve Arrow 0.15.0 support after changes in `arrow.get()` behavior (#296)
- Watson now suggests correct command if users make small typo (#318)

### Changed

- Always show total time at bottom of report (#356)
- Use the default system newline character for CSV output (#366).

### Fixed

- Stylize prompt to create new project or tag (#310).
- Aggregate calculates wrong time if used with `--current` (#293)
- The `start` command now correctly checks if project is empty (#322)
- Aggregate ignores frames that crosses aggregate boundary (#248)
- The `report` and `aggregate` commands with `--json` option now correctly
encode Arrow objects (#329)

Expand Down Expand Up @@ -223,7 +241,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

First stable public release 🎉

[unreleased]: https://github.com/tailordev/watson/compare/1.8.0...HEAD
[unreleased]: https://github.com/tailordev/watson/compare/1.9.0...HEAD
[1.9.0]: https://github.com/tailordev/watson/compare/1.8.0...1.9.0
[1.8.0]: https://github.com/tailordev/watson/compare/1.7.0...1.8.0
[1.7.0]: https://github.com/tailordev/watson/compare/1.6.0...1.7.0
[1.6.0]: https://github.com/tailordev/watson/compare/1.5.2...1.6.0
Expand Down
22 changes: 22 additions & 0 deletions docs/about/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.9.0] - 2020-05-27

### Added

- Improve Arrow 0.15.0 support after changes in `arrow.get()` behavior (#296)
- Watson now suggests correct command if users make small typo (#318)

### Changed

- Always show total time at bottom of report (#356)
- Use the default system newline character for CSV output (#366).

### Fixed

- Stylize prompt to create new project or tag (#310).
- Aggregate calculates wrong time if used with `--current` (#293)
- The `start` command now correctly checks if project is empty (#322)
- Aggregate ignores frames that crosses aggreagate boundary (#248)
- The `report` and `aggregate` commands with `--json` option now correctly
encode Arrow objects (#329)

## [1.8.0] - 2019-08-26

### Added
Expand Down Expand Up @@ -207,6 +228,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

First stable public release 🎉

[1.9.0]: https://github.com/tailordev/watson/compare/1.8.0...1.9.0
[1.8.0]: https://github.com/tailordev/watson/compare/1.7.0...1.8.0
[1.7.0]: https://github.com/tailordev/watson/compare/1.6.0...1.7.0
[1.6.0]: https://github.com/tailordev/watson/compare/1.5.2...1.6.0
Expand Down
9 changes: 5 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ Each frame consists of the name of a project and some tags. Your tags
can be shared across projects and can be used to generate detailed
reports.

Watson stores everything on your computer, but you can go wild and use
[crick.io](https://crick.io/?pk_campaign=GitHubWatson) to store
your sessions remotely and share it with your colleagues.
Watson stores everything on your computer, but you can go wild and
upload to your own [crick server](https://github.com/TailorDev/crick)
via the `sync` command to store your sessions remotely and share them
with your colleagues.

![screenshot](img/screenshot.png)

Expand Down Expand Up @@ -79,7 +80,7 @@ The latest development version can be installed using the following commands:
```bash
$ git clone https://github.com/TailorDev/Watson.git
$ cd Watson/
$ python setup.py install
$ pip install -e .
```

### Command line completion
Expand Down
8 changes: 8 additions & 0 deletions docs/user-guide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ If `true`, the output of the `report` command will include the currently
running frame (if any) by default. The option can be overridden on the
command line with the `-c/-C` resp. `--current/--no-current` flags.

#### `options.reverse_log` (default: `true`)

If `true`, the output of the `log` command will reverse the order of the days
to display the latest day's entries on top and the oldest day's entries at the
bottom. The option can be overridden on the command line with the `-r/-R` resp.
`--reverse/--no-reverse` flags.

#### `options.stop_on_start` (default: `false`)

If `true`, starting a new project will stop running projects:
Expand Down Expand Up @@ -230,6 +237,7 @@ week_start = monday
log_current = false
pager = true
report_current = false
reverse_log = true
```

## Application folder
Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
arrow!=0.11,!=0.12.0
click
arrow>=0.15.6
click>=7.0
click-didyoumean
colorama; sys_platform == "win32"
requests
20 changes: 16 additions & 4 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
.replace(hour=14, minute=5, second=0)
.format('YYYY-MM-DD HH:mm:ss')
),
('2018-W08', '2018-02-19 00:00:00'), # week dates
('2018W08', '2018-02-19 00:00:00'),
('2018-W08-2', '2018-02-20 00:00:00'),
('2018W082', '2018-02-20 00:00:00'),
]

INVALID_DATES_DATA = [
Expand All @@ -52,10 +56,6 @@
('201804'),
('18-04-10'),
('180410'), # truncated representation not allowed
('2018-W08'), # despite week dates being part of ISO-8601
('2018W08'),
('2018-W08-2'),
('2018W082'),
('hello 2018'),
('yesterday'),
('tomorrow'),
Expand Down Expand Up @@ -182,3 +182,15 @@ def test_stop_valid_time(runner, watson, mocker, at_dt):
arrow.arrow.datetime.now.return_value = (start_dt + timedelta(hours=1))
result = runner.invoke(cli.stop, ['--at', at_dt], obj=watson)
assert result.exit_code == 0


# watson start

@pytest.mark.parametrize('at_dt', VALID_TIMES_DATA)
def test_start_valid_time(runner, watson, mocker, at_dt):
# Simulate a start date so that 'at_dt' is older than now().
mocker.patch('arrow.arrow.datetime', wraps=datetime)
start_dt = datetime(2019, 4, 10, 14, 0, 0, tzinfo=tzlocal())
arrow.arrow.datetime.now.return_value = (start_dt + timedelta(hours=1))
result = runner.invoke(cli.start, ['a-project', '--at', at_dt], obj=watson)
assert result.exit_code == 0
32 changes: 30 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import json
import os
import datetime
import operator

try:
from StringIO import StringIO
Expand All @@ -32,6 +33,7 @@
get_start_time_for_period,
make_json_writer,
safe_save,
sorted_groupby,
parse_tags,
PY2,
json_arrow_encoder,
Expand Down Expand Up @@ -245,14 +247,14 @@ def test_build_csv_empty_data():


def test_build_csv_one_col():
lt = csv.get_dialect('excel').lineterminator
lt = os.linesep
data = [{'col': 'value'}, {'col': 'another value'}]
result = lt.join(['col', 'value', 'another value']) + lt
assert build_csv(data) == result


def test_build_csv_multiple_cols():
lt = csv.get_dialect('excel').lineterminator
lt = os.linesep
dm = csv.get_dialect('excel').delimiter
data = [
co.OrderedDict([('col1', 'value'),
Expand All @@ -270,6 +272,32 @@ def test_build_csv_multiple_cols():
assert build_csv(data) == result


# sorted_groupby

def test_sorted_groupby(watson):
end = arrow.utcnow()
watson.add('foo', end.shift(hours=-25), end.shift(hours=-24), ['A'])
watson.add('bar', end.shift(hours=-1), end, ['A'])

result = list(sorted_groupby(
watson.frames,
operator.attrgetter('day'),
reverse=False))
assert result[0][0] < result[1][0]


def test_sorted_groupby_reverse(watson):
end = arrow.utcnow()
watson.add('foo', end.shift(hours=-25), end.shift(hours=-24), ['A'])
watson.add('bar', end.shift(hours=-1), end, ['A'])

result = list(sorted_groupby(
watson.frames,
operator.attrgetter('day'),
reverse=True))
assert result[0][0] > result[1][0]


# frames_to_csv

def test_frames_to_csv_empty_data(watson):
Expand Down
64 changes: 60 additions & 4 deletions tests/test_watson.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,26 @@ def test_start_nogap(watson):
assert watson.frames[-1].stop == watson.current['start']


def test_start_project_at(watson):
now = arrow.now()
watson.start('foo', start_at=now)
watson.stop()

# Task can't start before the previous task ends
with pytest.raises(WatsonError):
time_str = '1970-01-01T00:00'
time_obj = arrow.get(time_str)
watson.start('foo', start_at=time_obj)

# Task can't start in the future
with pytest.raises(WatsonError):
time_str = '2999-12-31T23:59'
time_obj = arrow.get(time_str)
watson.start('foo', start_at=time_obj)

assert watson.frames[-1].start == now


# stop

def test_stop_started_project(watson):
Expand Down Expand Up @@ -385,13 +405,15 @@ def test_stop_started_project_at(watson):
watson.start('foo')
now = arrow.now()

# Task can't end before it starts
with pytest.raises(WatsonError):
time_str = '1970-01-01T00:00'
time_obj = arrow.get(time_str)
watson.stop(stop_at=time_obj)

with pytest.raises(ValueError):
time_str = '2999-31-12T23:59'
# Task can't end in the future
with pytest.raises(WatsonError):
time_str = '2999-12-31T23:59'
time_obj = arrow.get(time_str)
watson.stop(stop_at=time_obj)

Expand Down Expand Up @@ -710,14 +732,14 @@ def json(self):
{
'id': '1c006c6e-6cc1-4c80-ab22-b51c857c0b06',
'project': 'foo',
'start_at': 4003,
'begin_at': 4003,
'end_at': 4004,
'tags': ['A']
},
{
'id': 'c44aa815-4d77-4a58-bddd-1afa95562141',
'project': 'bar',
'start_at': 4004,
'begin_at': 4004,
'end_at': 4005,
'tags': []
}
Expand Down Expand Up @@ -923,6 +945,40 @@ def test_report_current(mocker, config_dir):
assert len(report['projects']) == 0


@pytest.mark.parametrize(
"date_as_unixtime,include_partial,sum_", (
(3600 * 24, False, 0.0),
(3600 * 48, False, 0.0),
(3600 * 24, True, 7200.0),
(3600 * 48, True, 3600.0),
)
)
def test_report_include_partial_frames(mocker, watson, date_as_unixtime,
include_partial, sum_):
"""Test report building with frames that cross report boundaries
1 event is added that has 2 hours in one day and 1 in the next. The
parametrization checks that the report for both days is empty with
`include_partial=False` and report the correct amount of hours with
`include_partial=False`
"""
content = json.dumps([[
3600 * 46,
3600 * 49,
"programming",
"3e76c820909840f89cabaf106ab7d12a",
["cli"],
1548797432
]])
mocker.patch('%s.open' % builtins, mocker.mock_open(read_data=content))
date = arrow.get(date_as_unixtime)
report = watson.report(
from_=date, to=date, include_partial_frames=include_partial,
)
assert report["time"] == pytest.approx(sum_, abs=1e-3)


# renaming project updates frame last_updated time
def test_rename_project_with_time(watson):
"""
Expand Down
Loading

0 comments on commit 3745115

Please sign in to comment.