<commit_before>import datetime
import os

import pytest

import timeflow
from timeflow import cli

FAKE_TIME = datetime.datetime(2015, 1, 1, 23, 59, 59)


@pytest.fixture
def patch_datetime_now(monkeypatch):

    class mydatetime(datetime.datetime):
        @classmethod
        def now(cls):
            return FAKE_TIME

    monkeypatch.setattr(datetime, 'datetime', mydatetime)


def test_patch_datetime(patch_datetime_now):
    assert datetime.datetime.now() == FAKE_TIME


def test_log(patch_datetime_now, tmpdir, capsys):
    tmp_path = tmpdir.join("test_log.txt").strpath
    timeflow.LOG_FILE = tmp_path

    # run log command
    parser = cli.create_parser()
    args = parser.parse_args(['log', 'message'])
    args.func(args)

    with open(tmp_path, 'r') as f:
        lines = f.readlines()
        assert len(lines) == 1
        assert lines[0] == '2015-01-01 23:59: message\n'


def test_edit(patch_datetime_now, tmpdir, capsys):
    test_dir = os.path.dirname(os.path.realpath(__file__))

    # overwrite log file setting, to define file to be used in tests
    timeflow.LOG_FILE = test_dir + '/fake_log.txt'

    # run edit command
    parser = cli.create_parser()
    args = parser.parse_args(['edit'])
    args.func(args)


def test_stats_now(patch_datetime_now, capsys):
    test_dir = os.path.dirname(os.path.realpath(__file__))

    # overwrite log file setting, to define file to be used in tests
    timeflow.LOG_FILE = test_dir + '/fake_log.txt'

    # run stats command
    parser = cli.create_parser()
    args = parser.parse_args(['stats'])
    args.func(args)

    # extract STDOUT, as stats command prints to it
    out, err = capsys.readouterr()
    result = ("Work: 02h 50min\n"
              "Slack: 01h 10min\n"
              "\n"
              "Today working for: 15h 59min\n")
    assert result == out


def test_stats_yesterday(patch_datetime_now, capsys):
    test_dir = os.path.dirname(os.path.realpath(__file__))

    # overwrite log file setting, to define file to be used in tests
    timeflow.LOG_FILE = test_dir + '/fake_log.txt'

    # run stats command
    parser = cli.create_parser()
    args = parser.parse_args(['stats', '--yesterday'])
    args.func(args)

    # extract STDOUT, as stats command prints to it
    out, err = capsys.readouterr()
    result = ("Work: 02h 50min\n"
              "Slack: 01h 10min\n")
    assert result == out


def test_stats_day(patch_datetime_now, capsys):
    test_dir = os.path.dirname(os.path.realpath(__file__))

    # overwrite log file setting, to define file to be used in tests
    timeflow.LOG_FILE = test_dir + '/fake_log.txt'

    # run stats command
    parser = cli.create_parser()
    args = parser.parse_args(['stats', '--day', '2015-01-01'])
    args.func(args)

    # extract STDOUT, as stats command prints to it
    out, err = capsys.readouterr()
    result = ("Work: 02h 50min\n"
              "Slack: 01h 10min\n")
    assert result == out


def test_stats_last_week(patch_datetime_now, capsys):<commit_msg>Add test for `--this-week` option<commit_after>import datetime
import os

import pytest

import timeflow
from timeflow import cli

FAKE_TIME = datetime.datetime(2015, 1, 1, 23, 59, 59)


@pytest.fixture
def patch_datetime_now(monkeypatch):

    class mydatetime(datetime.datetime):
        @classmethod
        def now(cls):
            return FAKE_TIME

    monkeypatch.setattr(datetime, 'datetime', mydatetime)


def test_patch_datetime(patch_datetime_now):
    assert datetime.datetime.now() == FAKE_TIME


def test_log(patch_datetime_now, tmpdir, capsys):
    tmp_path = tmpdir.join("test_log.txt").strpath
    timeflow.LOG_FILE = tmp_path

    # run log command
    parser = cli.create_parser()
    args = parser.parse_args(['log', 'message'])
    args.func(args)

    with open(tmp_path, 'r') as f:
        lines = f.readlines()
        assert len(lines) == 1
        assert lines[0] == '2015-01-01 23:59: message\n'


def test_edit(patch_datetime_now, tmpdir, capsys):
    test_dir = os.path.dirname(os.path.realpath(__file__))

    # overwrite log file setting, to define file to be used in tests
    timeflow.LOG_FILE = test_dir + '/fake_log.txt'

    # run edit command
    parser = cli.create_parser()
    args = parser.parse_args(['edit'])
    args.func(args)


def test_stats_now(patch_datetime_now, capsys):
    test_dir = os.path.dirname(os.path.realpath(__file__))

    # overwrite log file setting, to define file to be used in tests
    timeflow.LOG_FILE = test_dir + '/fake_log.txt'

    # run stats command
    parser = cli.create_parser()
    args = parser.parse_args(['stats'])
    args.func(args)

    # extract STDOUT, as stats command prints to it
    out, err = capsys.readouterr()
    result = ("Work: 02h 50min\n"
              "Slack: 01h 10min\n"
              "\n"
              "Today working for: 15h 59min\n")
    assert result == out


def test_stats_yesterday(patch_datetime_now, capsys):
    test_dir = os.path.dirname(os.path.realpath(__file__))

    # overwrite log file setting, to define file to be used in tests
    timeflow.LOG_FILE = test_dir + '/fake_log.txt'

    # run stats command
    parser = cli.create_parser()
    args = parser.parse_args(['stats', '--yesterday'])
    args.func(args)

    # extract STDOUT, as stats command prints to it
    out, err = capsys.readouterr()
    result = ("Work: 02h 50min\n"
              "Slack: 01h 10min\n")
    assert result == out


def test_stats_day(patch_datetime_now, capsys):
    test_dir = os.path.dirname(os.path.realpath(__file__))

    # overwrite log file setting, to define file to be used in tests
    timeflow.LOG_FILE = test_dir + '/fake_log.txt'

    # run stats command
    parser = cli.create_parser()
    args = parser.parse_args(['stats', '--day', '2015-01-01'])
    args.func(args)

    # extract STDOUT, as stats command prints to it
    out, err = capsys.readouterr()
    result = ("Work: 02h 50min\n"
              "Slack: 01h 10min\n")
    assert result == out


def test_stats_this_week(patch_datetime_now, capsys):
    test_dir = os.path.dirname(os.path.realpath(__file__))

    # overwrite log file setting, to define file to be used in tests
    timeflow.LOG_FILE = test_dir + '/fake_log.txt'

    # run stats command
    parser = cli.create_parser()
    args = parser.parse_args(['stats', '--this-week'])
    args.func(args)

    # extract STDOUT, as stats command prints to it
    out, err = capsys.readouterr()
    result = ("Work: 08h 50min\n"
              "Slack: 03h 50min\n")
    assert result == out


def test_stats_last_week(patch_datetime_now, capsys):
{'fraction_non_alphanumeric': 0.11331917475728155, 'fraction_numerical': 0.020024271844660196, 'mean_word_length': 3.069753086419753, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3272763', 'n_tokens_mistral': 2338, 'n_tokens_neox': 2162, 'n_words': 567}