def test_last_act_multiple(self, dtm, prnt: MagicMock):
        first = datetime.now().astimezone(tz.tzlocal())
        mid = (first + timedelta(minutes=13))
        next = (mid + timedelta(minutes=7))

        dtm.now = MagicMock(return_value=next)

        db = DatabaseWrapper()
        db.new_activity('foo')
        db.new_activity('bar')
        db.new_activity('bash')

        db.record_time('foo', 'none', first)
        db.record_time('bar', 'none', mid)

        timelog.take_args(self.config, db, argv=['doing', 'bash'])

        prnt.assert_called_with('Finished doing bar for 0:07:00')
Exemple #2
0
def staged_db():
    '''
    Create a DatabaseWrapper initialized with easy-to-use data for testing.
    '''

    wrapper = DatabaseWrapper()
    wrapper.db.executescript(_test_data)
    yield wrapper

    wrapper.db.close()
Exemple #3
0
def real_data_db():
    '''
    Create a DatabaseWrapper initialized with mock real-world data.

    Note: There are about 3000 rows in the timelog table, this may take
    some time to set-up for each unit test.
    '''

    wrapper = DatabaseWrapper()
    wrapper.db.executescript(_real_data)
    yield wrapper

    wrapper.db.close()
def test_last_act_before_most_recent(staged_db: DatabaseWrapper):
    """
    Make sure that if we record a time before another activity already
    in the timelog, that we don't get a negative duration from that
    activity to this new one, instead make sure that it finds the
    previous activity in time.
    """

    time = datetime(2021, 1, 1, 0, 30, 0, tzinfo=tz.UTC)

    last = staged_db.record_time('foo', 'user1', time)

    assert last is not None
    assert last.name == 'activity1'
    assert last.time == datetime(2021, 1, 1, 0, 0, 0, tzinfo=tz.UTC)
    assert last.duration == timedelta(minutes=30)
Exemple #5
0
def timelog_entry_point():
    """
    The entry point used for the `timelog` command. This method is referenced
    in `setup.py` so that when the package is built, the `timelog` script is
    built and it links to this method.
    """
    from .. import master_config

    # Use the master_config file so that when we are finished, any changes
    # to the configuration are saved.
    #
    # Doing this with a global variable is probably all kinds of bad, but
    # idk, it works for now ¯\_(ツ)_/¯
    with master_config:
        # TODO use a context manager for DatabaseWrapper so the db gets closed
        # properly
        take_args(master_config.time_management,
                  DatabaseWrapper(master_config.data_folder.joinpath('dailydata.db')))
    def test_last_act_print_with_tz(self, dtm, prnt: MagicMock):
        last = datetime.now().astimezone(tz.tzlocal())
        next = (last + timedelta(minutes=50)).astimezone(tz.tzlocal())

        dtm.now = MagicMock(return_value=next)

        db = DatabaseWrapper()
        db.new_activity('foo')
        db.new_activity('bar')

        db.record_time('foo', 'none', last)

        timelog.take_args(self.config, db, argv=['doing', 'bar'])

        prnt.assert_called_with('Finished doing foo for 0:50:00')