Пример #1
0
 def test_time(self):
     c = Calendar()
     c = c.add(Day("came 9 left 15", today))
     data = c.dump()
     c2 = Calendar.load(data)
     assert c2.days[today].came == time(9)
     assert c2.days[today].left == time(15)
Пример #2
0
 def test_serialize(self):
     c = Calendar(target_hours_per_day=timedelta(hours=8.00))
     c = c.add(Day("came 9 left 18", today))
     data = c.dump()
     c2 = Calendar.load(data)
     s = ConsoleDayShower(c2).show_days(today, 1)
     assert re.search("Flex *01:00", s)
Пример #3
0
 def test_only_came(self):
     c = Calendar()
     c = c.add(Day("came 9", today))
     assert "09:00" in ConsoleDayShower(c).show_days(today, 1)
     c, date_ = c.undo()
     assert "09:00" not in ConsoleDayShower(c).show_days(today, 1)
     assert date_ == today
Пример #4
0
 def test_basic(self):
     c = Calendar()
     c = c.add(Day("came 9 left 15 lunch 30m", today))
     c, _ = c.undo()
     c, date_ = c.redo()
     assert "30" in ConsoleDayShower(c).show_days(today, 1)
     assert date_ == today
Пример #5
0
 def test_basic(self):
     c = Calendar()
     c = c.add(
         Day(date_=today, project_name="EPG Support", project_time="08:00"))
     c = c.add_project("EPG Support")
     s = ConsoleDayShower(c).show_days(today, 1)
     assert "EPG Support" in s
     assert "08:00" in s
Пример #6
0
 def test_added(self):
     c = Calendar()
     wednesday = today + timedelta(days=-today.weekday() + 2)
     c = c.add(Day("came 8 left 18 lunch 45m", wednesday))
     s = ConsoleDayShower(c).show_days(today, 5)
     assert "08:00" in s
     assert "18:00" in s
     assert "0:45" in s
     assert "Came" in s
     assert "Left" in s
     assert "Lunch" in s
Пример #7
0
 def test_basic(self):
     c = Calendar()
     c = c.add(
         Day(
             args="came 9 left 16:45 lunch 0m",
             date_=today,
             project_name="Parental leave",
             project_time="04:00",
         ))
     c = c.add_project("Parental leave", work=False)
     s = ConsoleDayShower(c).show_days(today, 1)
     assert "Parental leave" in s
     assert "04:00" in s
     assert "07:45" in s
def test_monday_on_the_1st():
    view = ConsoleMonthView(date(2018, 11, 5), "january")
    s = view.show(Calendar())
    assert "2017" not in s
    assert "2018-01-01" in s
    assert "2018-01-31" in s
    assert "2018-02-05" not in s
def test_sunday_on_the_1st():
    view = ConsoleMonthView(date(2017, 11, 5), "october")
    s = view.show(Calendar())
    # TODO: issue #64
    # assert not '2017-09-26' in s
    assert "2017-10-02" in s
    assert "2017-10-30" in s
Пример #10
0
 def test_project_not_existing_error(self, mockdate_tuesday):
     with pytest.raises(ProjectNameDoesNotExistError):
         # TODO: when ProjectCommand moves to use argument splitter method
         # or class instead, change to passing a string since the below is
         # error prone.
         pc = ProjectCommand(Calendar(), mockdate_tuesday,
                             ["project", "EPG Support", "9"])
         pc.execute()
Пример #11
0
 def test_empty(self):
     s = ConsoleDayShower(Calendar()).show_days(today, 5)
     assert "2017-09-18" in s
     assert "2017-09-22" in s
     assert "2017-09-17" not in s
     assert "2017-09-23" not in s
     assert "Monday" in s
     assert "Friday" in s
     assert "Saturday" not in s
Пример #12
0
def get_calendar(path):
    try:
        with open(path, "r") as f:
            data = f.read()
            calendar = Calendar.load(data)
            if not isinstance(calendar, Calendar):
                raise UnreadableCamelFileError(
                    f"File found at {path} not readable. Remove it to "
                    f"create a new one."
                )
    except FileNotFoundError:
        if _can_file_be_created_at(path):
            calendar = Calendar()
        else:
            raise DirectoryDoesNotExistError(
                f"The directory for the specified path {path} does not exist. "
                f"Specify a custom path by setting the %TIMEREPORTER_FILE% "
                f"environment variable."
            )
    return calendar
Пример #13
0
 def test_report_time_short_form_ambiguity(self, mockdate_tuesday):
     calendar = Calendar()
     pc = ProjectCommand(calendar, mockdate_tuesday,
                         ["project", "new", "EPG Support"])
     calendar, view = pc.execute()
     pc = ProjectCommand(calendar, mockdate_tuesday,
                         ["project", "new", "EPG Maintenance"])
     calendar, view = pc.execute()
     with pytest.raises(AmbiguousProjectNameError):
         pc = ProjectCommand(calendar, mockdate_tuesday,
                             "project EP 9".split())
         pc.execute()
Пример #14
0
 def test_project(self):
     c = Calendar()
     c = c.add(
         Day(date_=today, project_name="EPG Support", project_time="08:00"))
     c = c.add_project("EPG Support")
     data = c.dump()
     c2 = Calendar.load(data)
     s = ConsoleDayShower(c2).show_days(today, 1)
     assert "EPG Support" in s
     assert "08:00" in s
def test_january_with_start_in_december():
    view = ConsoleMonthView(date(2019, 2, 7), "january")
    s = view.show(Calendar())
    assert "2018-12-31" in s
    assert "2019-02-07" not in s
def test_month_of_previous_year():
    view = ConsoleMonthView(date(2017, 11, 5), "december")
    s = view.show(Calendar())
    assert "2016-12-01" in s
    assert "2016-12-30" in s  # 31 is a Sunday
Пример #17
0
 def test_change_came_and_left(self):
     c = Calendar()
     c = c.add(Day("came 9 left 16 lunch 45m", today))
     c = c.add(Day("came 8 left 15", today))
     assert c.days[today] == Day("came 8 left 15 lunch 45m", today)
Пример #18
0
 def test_add_to_nothing(self):
     c = Calendar()
     c = c.add(Day("", today))
     c = c.add(Day("came 8 left 18 lunch 45m", today))
     assert c.days[today] == Day("came 8 left 18 lunch 45m", today)
Пример #19
0
def test_invalid_option(mockdate_tuesday):
    calendar = Calendar()
    with pytest.raises(UnexpectedOptionError):
        TimeReporterCommand(calendar, mockdate_tuesday,
                            "8 17 --not-existing".split())
Пример #20
0
 def test_project_number_0_not_existing(self, mockdate_tuesday):
     calendar = Calendar()
     pc = ProjectCommand(calendar, mockdate_tuesday, "project 0 8".split())
     with pytest.raises(InvalidProjectNumberError):
         pc.execute()
Пример #21
0
 def test_unexpected_option_reporting_number_error(self, mockdate_tuesday):
     with pytest.raises(UnexpectedOptionError):
         pc = ProjectCommand(Calendar(), mockdate_tuesday,
                             "project 1 2 7".split())
         pc.execute()
Пример #22
0
 def test_unexpected_option_creating_new_error(self, mockdate_tuesday):
     with pytest.raises(UnexpectedOptionError):
         pc = ProjectCommand(Calendar(), mockdate_tuesday,
                             "project new Hello World".split())
         pc.execute()
Пример #23
0
 def test_overwrite_lunch(self):
     c = Calendar()
     c = c.add(Day("lunch 45m", today))
     c = c.add(Day("lunch 35m", today))
     assert c.days[today].lunch == timedelta(minutes=35)
def test_current_month():
    view = ConsoleMonthView(date(2017, 11, 5), "november")
    s = view.show(Calendar())
    assert "2017-11-01" in s
    assert "2017-11-30" in s
Пример #25
0
 def test_add_to_day_inverse_order(self):
     c = Calendar()
     c = c.add(Day("left 15", today))
     c = c.add(Day("came 9", today))
     assert c.days[today].came == time(9)
     assert c.days[today].left == time(15)
Пример #26
0
def project_calendar():
    calendar = Calendar()
    return calendar.add_project("Hello")
Пример #27
0
 def test_return_none_instead_of_date_if_nothing_to_undo(self):
     c = Calendar()
     c, date_ = c.undo()
     assert date_ is None
Пример #28
0
 def test_came_left_lunch(self):
     c = Calendar()
     c = c.add(Day("came 9 left 15 lunch 30m", today))
     assert "30" in ConsoleDayShower(c).show_days(today, 1)
     c, _ = c.undo()
     assert "30" not in ConsoleDayShower(c).show_days(today, 1)
Пример #29
0
 def test_new_project_without_name_raises_error(self, mockdate_tuesday):
     with pytest.raises(NoProjectNameError):
         pc = ProjectCommand(Calendar(), mockdate_tuesday,
                             "project new".split())
         pc.execute()
Пример #30
0
 def test_overwrite_all(self):
     c = Calendar()
     c = c.add(Day("came 9 left 15", today))
     c = c.add(Day("came 8 left 14", today))
     assert c.days[today].came == time(8)
     assert c.days[today].left == time(14)