Skip to content

Commit

Permalink
Fix multiple inclusions of the current frame in aggregate commands
Browse files Browse the repository at this point in the history
- Inclusion of the current frame in report() does not persistently add
it to the Frames container.
- Added test

Fix #293
  • Loading branch information
jmkerr authored and jmaupetit committed Sep 13, 2019
1 parent b58115f commit 581a107
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Stylize prompt to create new project or tag (#310).
- Aggregate calculates wrong time if used with `--current` (#293)

## [1.8.0] - 2019-08-26

Expand Down
27 changes: 27 additions & 0 deletions tests/test_watson.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,33 @@ def test_report(watson):
watson.report(arrow.now(), arrow.now(), tags=["A"], ignore_tags=["A"])


def test_report_current(config_dir):
watson = Watson(
current={'project': 'foo', 'start': arrow.now().shift(hours=-1)},
config_dir=config_dir
)

_ = watson.report(
arrow.now(), arrow.now(), current=True, projects=['foo']
)
report = watson.report(
arrow.now(), arrow.now(), current=True, projects=['foo']
)
assert len(report['projects']) == 1
assert report['projects'][0]['name'] == 'foo'
assert report['projects'][0]['time'] == pytest.approx(3600, rel=1e-2)

report = watson.report(
arrow.now(), arrow.now(), current=False, projects=['foo']
)
assert len(report['projects']) == 0

report = watson.report(
arrow.now(), arrow.now(), projects=['foo']
)
assert len(report['projects']) == 0


# renaming project updates frame last_updated time
def test_rename_project_with_time(mock, watson):
"""
Expand Down
17 changes: 10 additions & 7 deletions watson/watson.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,13 +467,13 @@ def report(self, from_, to, current=None, projects=None, tags=None,
if from_ > to:
raise WatsonError("'from' must be anterior to 'to'")

if self.current:
if current or (current is None and
self.config.getboolean(
'options', 'report_current')):
cur = self.current
self.frames.add(cur['project'], cur['start'], arrow.utcnow(),
cur['tags'], id="current")
if current is None:
current = self.config.getboolean('options', 'report_current')

if self.current and current:
cur = self.current
self.frames.add(cur['project'], cur['start'], arrow.utcnow(),
cur['tags'], id="current")

span = self.frames.span(from_, to)

Expand All @@ -487,6 +487,9 @@ def report(self, from_, to, current=None, projects=None, tags=None,
operator.attrgetter('project')
)

if self.current and current:
del self.frames['current']

total = datetime.timedelta()

report = {
Expand Down

0 comments on commit 581a107

Please sign in to comment.