Skip to content

Commit

Permalink
Resolve Issue #407: Migrate to arrow 1.0.0
Browse files Browse the repository at this point in the history
Update unit test cases:

- tests/test_cli.py: replace arrow.arrow.datetime with arrow.arrow.dt_datetime
- tests/test_watson.py: replace .timestamp with .int_timestamp
  • Loading branch information
veganjay authored and jmaupetit committed Mar 4, 2021
1 parent 9bf344c commit ad780c0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
10 changes: 5 additions & 5 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,14 @@ def test_report_invalid_date(runner, watson, test_dt):

@pytest.mark.parametrize('at_dt', VALID_TIMES_DATA)
def test_stop_valid_time(runner, watson, mocker, at_dt):
mocker.patch('arrow.arrow.datetime', wraps=datetime)
mocker.patch('arrow.arrow.dt_datetime', wraps=datetime)
start_dt = datetime(2019, 4, 10, 14, 0, 0, tzinfo=tzlocal())
arrow.arrow.datetime.now.return_value = start_dt
arrow.arrow.dt_datetime.now.return_value = start_dt
result = runner.invoke(cli.start, ['a-project'], obj=watson)
assert result.exit_code == 0
# Simulate one hour has elapsed, so that 'at_dt' is older than now()
# but newer than the start date.
arrow.arrow.datetime.now.return_value = (start_dt + timedelta(hours=1))
arrow.arrow.dt_datetime.now.return_value = (start_dt + timedelta(hours=1))
result = runner.invoke(cli.stop, ['--at', at_dt], obj=watson)
assert result.exit_code == 0

Expand All @@ -189,8 +189,8 @@ def test_stop_valid_time(runner, watson, mocker, at_dt):
@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)
mocker.patch('arrow.arrow.dt_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))
arrow.arrow.dt_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
40 changes: 20 additions & 20 deletions tests/test_watson.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_current_with_empty_given_state(config_dir, mocker):

def test_last_sync(mocker, watson):
now = arrow.get(4123)
content = json.dumps(now.timestamp)
content = json.dumps(now.int_timestamp)

mocker.patch('builtins.open', mocker.mock_open(read_data=content))
assert watson.last_sync == now
Expand Down Expand Up @@ -482,7 +482,7 @@ def test_save_last_sync(mocker, watson, json_mock):
watson.save()

assert json_mock.call_count == 1
assert json_mock.call_args[0][0] == now.timestamp
assert json_mock.call_args[0][0] == now.int_timestamp


def test_save_empty_last_sync(config_dir, mocker, json_mock):
Expand Down Expand Up @@ -682,14 +682,14 @@ def json(self):

assert watson.frames[0].id == '1c006c6e6cc14c80ab22b51c857c0b06'
assert watson.frames[0].project == 'foo'
assert watson.frames[0].start.timestamp == 4003
assert watson.frames[0].stop.timestamp == 4004
assert watson.frames[0].start.int_timestamp == 4003
assert watson.frames[0].stop.int_timestamp == 4004
assert watson.frames[0].tags == ['A']

assert watson.frames[1].id == 'c44aa8154d774a58bddd1afa95562141'
assert watson.frames[1].project == 'bar'
assert watson.frames[1].start.timestamp == 4004
assert watson.frames[1].stop.timestamp == 4005
assert watson.frames[1].start.int_timestamp == 4004
assert watson.frames[1].stop.int_timestamp == 4005
assert watson.frames[1].tags == []


Expand Down Expand Up @@ -888,18 +888,18 @@ def test_rename_project_with_time(watson):

assert watson.frames[0].id == 'c76d1ad0282c429595cc566d7098c165'
assert watson.frames[0].project == 'baz'
assert watson.frames[0].start.timestamp == 4001
assert watson.frames[0].stop.timestamp == 4002
assert watson.frames[0].start.int_timestamp == 4001
assert watson.frames[0].stop.int_timestamp == 4002
assert watson.frames[0].tags == ['some_tag']
# assert watson.frames[0].updated_at.timestamp == 9000
assert watson.frames[0].updated_at.timestamp > 4005
# assert watson.frames[0].updated_at.int_timestamp == 9000
assert watson.frames[0].updated_at.int_timestamp > 4005

assert watson.frames[1].id == 'eed598ff363d42658a095ae6c3ae1088'
assert watson.frames[1].project == 'bar'
assert watson.frames[1].start.timestamp == 4010
assert watson.frames[1].stop.timestamp == 4015
assert watson.frames[1].start.int_timestamp == 4010
assert watson.frames[1].stop.int_timestamp == 4015
assert watson.frames[1].tags == ['other_tag']
assert watson.frames[1].updated_at.timestamp == 4035
assert watson.frames[1].updated_at.int_timestamp == 4035


def test_rename_tag_with_time(watson):
Expand All @@ -922,18 +922,18 @@ def test_rename_tag_with_time(watson):

assert watson.frames[0].id == 'c76d1ad0282c429595cc566d7098c165'
assert watson.frames[0].project == 'foo'
assert watson.frames[0].start.timestamp == 4001
assert watson.frames[0].stop.timestamp == 4002
assert watson.frames[0].start.int_timestamp == 4001
assert watson.frames[0].stop.int_timestamp == 4002
assert watson.frames[0].tags == ['some_tag']
assert watson.frames[0].updated_at.timestamp == 4005
assert watson.frames[0].updated_at.int_timestamp == 4005

assert watson.frames[1].id == 'eed598ff363d42658a095ae6c3ae1088'
assert watson.frames[1].project == 'bar'
assert watson.frames[1].start.timestamp == 4010
assert watson.frames[1].stop.timestamp == 4015
assert watson.frames[1].start.int_timestamp == 4010
assert watson.frames[1].stop.int_timestamp == 4015
assert watson.frames[1].tags == ['baz']
# assert watson.frames[1].updated_at.timestamp == 9000
assert watson.frames[1].updated_at.timestamp > 4035
# assert watson.frames[1].updated_at.int_timestamp == 9000
assert watson.frames[1].updated_at.int_timestamp > 4035

# add

Expand Down

0 comments on commit ad780c0

Please sign in to comment.