예제 #1
0
    def test_parse_user_year_month(self):
        file_parser = Parser()
        user_string = """Name: Wayne Doe
Employment: 100 %
Payed vacation: 30
Vacation month: 04
Employed date: 2014-01-01"""

        file_name_1 = save_user_file(user_string, self.temp_dir.name)
        user_1 = file_parser.parse_user_file(file_name_1)

        nt.assert_true(file_parser.user is user_1)

        year_string = ("2014-01-01: \"New years day\"\n"
                       "2014-01-06: \"Epiphany\"")

        file_name_2 = save_year_file(year_string, "2014", self.temp_dir.name)
        year_1 = file_parser.parse_year_file(file_name_2)
        nt.assert_true(file_parser.user.years[0] is year_1)

        month_string = """2. 8:00 1:00 17:00
3. 8:50 0:45 18:00
7. 9:30 1:00 16:55
"""
        file_name_3 = save_month_file(
            month_string, "2014-01.txt", self.temp_dir.name)

        month_1 = file_parser.parse_month_file(file_name_3)
        nt.assert_true(file_parser.user.years[0].months[0] is month_1)
예제 #2
0
    def test_sick_days(self):
        file_parser = Parser()
        file_content_1 = """1. 8:00 1:00 17:00
2. 8:00 1:00 17:00"""

        file_name = save_month_file(
            file_content_1, "2014-09.txt", self.temp_dir.name)

        month_1 = file_parser.parse_month_file(file_name)
        nt.assert_equal(month_1.sick_days(), 0)

        file_content_2 = """1. S"""
        file_name = save_month_file(
            file_content_2, "2014-09.txt", self.temp_dir.name)

        month_2 = file_parser.parse_month_file(file_name)
        nt.assert_equal(month_2.sick_days(), 1)
        file_content_3 = """1. 8:00 1:00 17:00
2. S
3. 8:00 1:00 17:00
4. S
5. 8:00 1:00 17:00
8. S"""

        file_name = save_month_file(
            file_content_3, "2014-09.txt", self.temp_dir.name)

        month_3 = file_parser.parse_month_file(file_name)
        nt.assert_equal(month_3.sick_days(), 3)
예제 #3
0
 def test_parse_year_configuration(self):
     file_parser = Parser()
     year_string = "2015-01-01: \"New years day\""
     file_name = save_year_file(year_string, "2015", self.temp_dir.name)
     year_1 = file_parser.parse_year_file(file_name)
     nt.assert_equal(year_1.holidays["2015-01"]["2015-01-01"],
                     "New years day")
예제 #4
0
    def test_vacation(self):
        file_parser = Parser()
        file_content_1 = """1. 8:00 1:00 17:00
2. 8:00 1:00 17:00"""

        file_name = save_month_file(file_content_1, "2014-09.txt",
                                    self.temp_dir.name)

        month_1 = file_parser.parse_month_file(file_name)
        nt.assert_equal(month_1.used_vacation(), 0)

        file_content_2 = """1. V"""
        file_name = save_month_file(file_content_2, "2014-09.txt",
                                    self.temp_dir.name)

        month_2 = file_parser.parse_month_file(file_name)
        nt.assert_equal(month_2.used_vacation(), 1)

        file_content_3 = """1. 8:00 1:00 17:00
2. V
3. V
4. 8:00 1:00 17:00
5. 8:00 1:00 17:00
8. V"""

        file_name = save_month_file(file_content_3, "2014-09.txt",
                                    self.temp_dir.name)

        month_3 = file_parser.parse_month_file(file_name)
        nt.assert_equal(month_3.used_vacation(), 3)
예제 #5
0
    def test_parse_user_year_month(self):
        file_parser = Parser()
        user_string = """Name: Wayne Doe
Employment: 100 %
Payed vacation: 30
Vacation month: 04
Employed date: 2014-01-01"""

        file_name_1 = save_user_file(user_string, self.temp_dir.name)
        user_1 = file_parser.parse_user_file(file_name_1)

        nt.assert_true(file_parser.user is user_1)

        year_string = ("2014-01-01: \"New years day\"\n"
                       "2014-01-06: \"Epiphany\"")

        file_name_2 = save_year_file(year_string, "2014", self.temp_dir.name)
        year_1 = file_parser.parse_year_file(file_name_2)
        nt.assert_true(file_parser.user.years[0] is year_1)

        month_string = """2. 8:00 1:00 17:00
3. 8:50 0:45 18:00
7. 9:30 1:00 16:55
"""
        file_name_3 = save_month_file(month_string, "2014-01.txt",
                                      self.temp_dir.name)

        month_1 = file_parser.parse_month_file(file_name_3)
        nt.assert_true(file_parser.user.years[0].months[0] is month_1)
예제 #6
0
    def test_sick_days(self):
        file_parser = Parser()
        file_content_1 = """1. 8:00 1:00 17:00
2. 8:00 1:00 17:00"""

        file_name = save_month_file(file_content_1, "2014-09.txt",
                                    self.temp_dir.name)

        month_1 = file_parser.parse_month_file(file_name)
        nt.assert_equal(month_1.sick_days(), 0)

        file_content_2 = """1. S"""
        file_name = save_month_file(file_content_2, "2014-09.txt",
                                    self.temp_dir.name)

        month_2 = file_parser.parse_month_file(file_name)
        nt.assert_equal(month_2.sick_days(), 1)
        file_content_3 = """1. 8:00 1:00 17:00
2. S
3. 8:00 1:00 17:00
4. S
5. 8:00 1:00 17:00
8. S"""

        file_name = save_month_file(file_content_3, "2014-09.txt",
                                    self.temp_dir.name)

        month_3 = file_parser.parse_month_file(file_name)
        nt.assert_equal(month_3.sick_days(), 3)
예제 #7
0
    def test_parse_archive_multiple_months(self):
        file_parser = Parser()

        archive_string = "2014-11\n3. 8:00 1:00 17:05"
        for n in (4, 5, 6, 7,
                  10, 11, 12, 13, 14,
                  17, 18, 19, 20, 21,
                  24, 25, 26, 27, 28):
            archive_string += "\n{}. 8:00 1:00 17:00".format(n)

        archive_string += "\n\n2014-12\n1. 8:00 1:00 17:05"
        for n in (2, 3, 4, 5,
                  8, 9, 10, 11, 12,
                  15, 16, 17, 18, 19,
                  22, 23, 24, 25, 26,
                  29, 30, 31):
            archive_string += "\n{}. 8:00 1:00 17:00".format(n)

        archive_string += "\n\n2015-01\n1. 8:00 1:00 17:05"
        for n in (2,
                  5, 6, 7, 8, 9,
                  12, 13, 14, 15, 16,
                  19, 20, 21, 22, 23,
                  26, 27, 28, 29, 30):
            archive_string += "\n{}. 8:00 1:00 17:00".format(n)

        file_name = save_archive_file(archive_string, self.temp_dir.name)
        archive_1 = file_parser.parse_archive_file(file_name)
        nt.assert_true(len(archive_1.months), 3)
        nt.assert_true(archive_1.calculate_flextime,
                       datetime.timedelta(minutes=15))

        nt.assert_true(archive_1.next_month, "2015-02")
예제 #8
0
 def test_parse_year_configuration(self):
     file_parser = Parser()
     year_string = "2015-01-01: \"New years day\""
     file_name = save_year_file(year_string, "2015", self.temp_dir.name)
     year_1 = file_parser.parse_year_file(file_name)
     nt.assert_equal(year_1.holidays["2015-01"]["2015-01-01"],
                     "New years day")
예제 #9
0
    def test_parse_archive_multiple_months(self):
        file_parser = Parser()

        archive_string = "2014-11\n3. 8:00 1:00 17:05"
        for n in (4, 5, 6, 7, 10, 11, 12, 13, 14, 17, 18, 19, 20, 21, 24, 25,
                  26, 27, 28):
            archive_string += "\n{}. 8:00 1:00 17:00".format(n)

        archive_string += "\n\n2014-12\n1. 8:00 1:00 17:05"
        for n in (2, 3, 4, 5, 8, 9, 10, 11, 12, 15, 16, 17, 18, 19, 22, 23, 24,
                  25, 26, 29, 30, 31):
            archive_string += "\n{}. 8:00 1:00 17:00".format(n)

        archive_string += "\n\n2015-01\n1. 8:00 1:00 17:05"
        for n in (2, 5, 6, 7, 8, 9, 12, 13, 14, 15, 16, 19, 20, 21, 22, 23, 26,
                  27, 28, 29, 30):
            archive_string += "\n{}. 8:00 1:00 17:00".format(n)

        file_name = save_archive_file(archive_string, self.temp_dir.name)
        archive_1 = file_parser.parse_archive_file(file_name)
        nt.assert_true(len(archive_1.months), 3)
        nt.assert_true(archive_1.calculate_flextime,
                       datetime.timedelta(minutes=15))

        nt.assert_true(archive_1.next_month, "2015-02")
예제 #10
0
    def test_vacation(self):
        file_parser = Parser()
        file_content_1 = """1. 8:00 1:00 17:00
2. 8:00 1:00 17:00"""

        file_name = save_month_file(
            file_content_1, "2014-09.txt", self.temp_dir.name)

        month_1 = file_parser.parse_month_file(file_name)
        nt.assert_equal(month_1.used_vacation(), 0)

        file_content_2 = """1. V"""
        file_name = save_month_file(
            file_content_2, "2014-09.txt", self.temp_dir.name)

        month_2 = file_parser.parse_month_file(file_name)
        nt.assert_equal(month_2.used_vacation(), 1)

        file_content_3 = """1. 8:00 1:00 17:00
2. V
3. V
4. 8:00 1:00 17:00
5. 8:00 1:00 17:00
8. V"""

        file_name = save_month_file(
            file_content_3, "2014-09.txt", self.temp_dir.name)

        month_3 = file_parser.parse_month_file(file_name)
        nt.assert_equal(month_3.used_vacation(), 3)
예제 #11
0
    def test_read_user_file_extra_vacation(self):
        file_parser = Parser()
        user_string = """Name: Michael Palin
Employment: 100 %
Payed vacation: 30
Extra vacation: 30
Vacation month: 04
Employed date: 2014-06-01"""

        file_name_1 = save_user_file(user_string, self.temp_dir.name)
        user_1 = file_parser.parse_user_file(file_name_1)
        nt.assert_equal(user_1.vacation_left(), 30)
예제 #12
0
    def test_parse_comments(self):
        file_parser = Parser()
        file_content_1 = """1. 8:00 1:00 17:00
2. 8:00 1:00 14:00 "Went home early because of really good weather"
3. 8:00"""

        file_name = save_month_file(file_content_1, "2014-09.txt",
                                    self.temp_dir.name)

        month_1 = file_parser.parse_month_file(file_name)
        nt.assert_equal(month_1.days[1].get_info(),
                        "Went home early because of really good weather.")
예제 #13
0
    def test_parse_comments(self):
        file_parser = Parser()
        file_content_1 = """1. 8:00 1:00 17:00
2. 8:00 1:00 14:00 "Went home early because of really good weather"
3. 8:00"""

        file_name = save_month_file(
            file_content_1, "2014-09.txt", self.temp_dir.name)

        month_1 = file_parser.parse_month_file(file_name)
        nt.assert_equal(month_1.days[1].get_info(),
                        "Went home early because of really good weather.")
예제 #14
0
    def test_read_user_file_extra_vacation(self):
        file_parser = Parser()
        user_string = """Name: Michael Palin
Employment: 100 %
Payed vacation: 30
Extra vacation: 30
Vacation month: 04
Employed date: 2014-06-01"""

        file_name_1 = save_user_file(user_string, self.temp_dir.name)
        user_1 = file_parser.parse_user_file(file_name_1)
        nt.assert_equal(user_1.vacation_left(), 30)
예제 #15
0
    def test_parse_comments_single_quote(self):
        file_parser = Parser()
        file_content_1 = """1. 8:00 1:00 17:00
2. 8:00 1:00 14:00 'Went home early because of really good weather'
3. 8:00 0:45 15:00 'Still good weather...'"""

        file_name = save_month_file(file_content_1, "2014-09.txt",
                                    self.temp_dir.name)

        month_1 = file_parser.parse_month_file(file_name)
        nt.assert_equal(month_1.days[1].get_info(),
                        "Went home early because of really good weather.")
        nt.assert_equal(month_1.days[2].get_info(), "Still good weather...")
예제 #16
0
    def test_parse_comments_single_quote(self):
        file_parser = Parser()
        file_content_1 = """1. 8:00 1:00 17:00
2. 8:00 1:00 14:00 'Went home early because of really good weather'
3. 8:00 0:45 15:00 'Still good weather...'"""
        
        file_name = save_month_file(
            file_content_1, "2014-09.txt", self.temp_dir.name)

        month_1 = file_parser.parse_month_file(file_name)
        nt.assert_equal(month_1.days[1].get_info(),
                        "Went home early because of really good weather.")
        nt.assert_equal(month_1.days[2].get_info(),
                        "Still good weather...")
예제 #17
0
    def test_one_partial_date(self):
        file_parser = Parser()
        file_name = save_month_file("1. 8:00\n", "2014-09.txt",
                                    self.temp_dir.name)

        month_1 = file_parser.parse_month_file(file_name)
        nt.assert_equal(len(month_1.days), 1)
        day_1 = month_1.days[-1]
        nt.assert_equal(day_1.date, datetime.date(2014, 9, 1))
        nt.assert_equal(day_1.start_time, datetime.datetime(2014, 9, 1,
                                                            hour=8))

        nt.assert_true(day_1.lunch_duration is None)
        nt.assert_true(day_1.end_time is None)
        nt.assert_false(day_1.complete())
예제 #18
0
    def test_one_partial_date(self):
        file_parser = Parser()
        file_name = save_month_file(
            "1. 8:00\n", "2014-09.txt", self.temp_dir.name)

        month_1 = file_parser.parse_month_file(file_name)
        nt.assert_equal(len(month_1.days), 1)
        day_1 = month_1.days[-1]
        nt.assert_equal(day_1.date, datetime.date(2014, 9, 1))
        nt.assert_equal(day_1.start_time,
                        datetime.datetime(2014, 9, 1, hour=8))

        nt.assert_true(day_1.lunch_duration is None)
        nt.assert_true(day_1.end_time is None)
        nt.assert_false(day_1.complete())
예제 #19
0
    def test_parse_archive_one_month(self):
        file_parser = Parser()
        month_string = "2014-09\n1. 8:00 1:00 17:05"
        for n in (2, 3, 4, 5, 8, 9, 10, 11, 12, 15, 16, 17, 18, 19, 22, 23, 24,
                  25, 26, 29, 30):
            month_string += "\n{}. 8:00 1:00 17:00".format(n)
        file_name = save_archive_file(month_string, self.temp_dir.name)
        archive_1 = file_parser.parse_archive_file(file_name)
        nt.assert_true(len(archive_1.months), 1)
        nt.assert_true(archive_1.months[0].year, 2014)
        nt.assert_true(archive_1.months[0].month, 9)
        nt.assert_true(archive_1.calculate_flextime,
                       datetime.timedelta(minutes=5))

        nt.assert_true(archive_1.next_month, "2014-10")
예제 #20
0
    def test_parse_bad_time(self):
        file_parser = Parser()
        file_name = save_month_file("1. 8.00", "2014-09.txt",
                                    self.temp_dir.name)

        nt.assert_raises_regexp(
            errors.ParseError,
            "Could not parse start time for date 2014-09-01: \"8.00\"",
            file_parser.parse_month_file, file_name)

        file_name = save_month_file("1. 8", "2014-10.txt", self.temp_dir.name)

        nt.assert_raises_regexp(
            errors.ParseError,
            "Could not parse start time for date 2014-10-01. Time must be "
            "given in hours and minutes, got \"8\".",
            file_parser.parse_month_file, file_name)

        file_name = save_month_file("1. 9", "2014-09.txt", self.temp_dir.name)

        nt.assert_raises_regexp(
            errors.ParseError,
            "Could not parse start time for date 2014-09-01. Time must be "
            "given in hours and minutes, got \"9\".",
            file_parser.parse_month_file, file_name)
예제 #21
0
    def test_read_messy_user(self):
        file_parser = Parser()
        user_string = """ name :  Sid Vicious
 employment :  20%  
 payed  Vacation :  0  
 vacation  Month :  3
\temployed\tdate\t:\t2013-04-01\t"""

        file_name_1 = save_user_file(user_string, self.temp_dir.name)
        user_1 = file_parser.parse_user_file(file_name_1)
        nt.assert_equal(user_1.name, "Sid Vicious")
        nt.assert_equal(user_1.employment, 20)
        nt.assert_equal(user_1.payed_vacation, 0)
        nt.assert_equal(user_1.vacation_month, 3)
        nt.assert_equal(user_1.employed_date,
                        datetime.datetime(year=2013, month=4, day=1).date())
예제 #22
0
    def test_read_messy_user(self):
        file_parser = Parser()
        user_string = """ name :  Sid Vicious
 employment :  20%  
 payed  Vacation :  0  
 vacation  Month :  3
\temployed\tdate\t:\t2013-04-01\t"""

        file_name_1 = save_user_file(user_string, self.temp_dir.name)
        user_1 = file_parser.parse_user_file(file_name_1)
        nt.assert_equal(user_1.name, "Sid Vicious")
        nt.assert_equal(user_1.employment, 20)
        nt.assert_equal(user_1.payed_vacation, 0)
        nt.assert_equal(user_1.vacation_month, 3)
        nt.assert_equal(user_1.employed_date,
                        datetime.datetime(year=2013, month=4, day=1).date())
예제 #23
0
    def test_read_user_file(self):
        file_parser = Parser()
        user_string = """Name: Jane Doe
Employment: 100 %
Payed vacation: 30
Vacation month: 04
Employed date: 2014-09-01"""

        file_name_1 = save_user_file(user_string, self.temp_dir.name)
        user_1 = file_parser.parse_user_file(file_name_1)
        nt.assert_equal(user_1.name, "Jane Doe")
        nt.assert_equal(user_1.employment, 100)
        nt.assert_equal(user_1.payed_vacation, 30)
        nt.assert_equal(user_1.vacation_month, 4)
        nt.assert_equal(user_1.employed_date,
                        datetime.datetime(year=2014, month=9, day=1).date())
예제 #24
0
    def test_read_user_file(self):
        file_parser = Parser()
        user_string = """Name: Jane Doe
Employment: 100 %
Payed vacation: 30
Vacation month: 04
Employed date: 2014-09-01"""

        file_name_1 = save_user_file(user_string, self.temp_dir.name)
        user_1 = file_parser.parse_user_file(file_name_1)
        nt.assert_equal(user_1.name, "Jane Doe")
        nt.assert_equal(user_1.employment, 100)
        nt.assert_equal(user_1.payed_vacation, 30)
        nt.assert_equal(user_1.vacation_month, 4)
        nt.assert_equal(user_1.employed_date,
                        datetime.datetime(year=2014, month=9, day=1).date())
예제 #25
0
    def test_read_user_file_another_user(self):
        file_parser = Parser()
        user_string = """Name: John Doe
Employment: 75 %
Payed vacation: 25
Vacation month: 1
Employed date: 2012-01-01"""

        file_name_1 = save_user_file(user_string, self.temp_dir.name)
        user_1 = file_parser.parse_user_file(file_name_1)
        nt.assert_equal(user_1.name, "John Doe")
        nt.assert_equal(user_1.employment, 75)
        nt.assert_equal(user_1.payed_vacation, 25)
        nt.assert_equal(user_1.vacation_month, 1)
        nt.assert_equal(user_1.employed_date,
                        datetime.datetime(year=2012, month=1, day=1).date())
예제 #26
0
    def test_read_user_file_another_user(self):
        file_parser = Parser()
        user_string = """Name: John Doe
Employment: 75 %
Payed vacation: 25
Vacation month: 1
Employed date: 2012-01-01"""

        file_name_1 = save_user_file(user_string, self.temp_dir.name)
        user_1 = file_parser.parse_user_file(file_name_1)
        nt.assert_equal(user_1.name, "John Doe")
        nt.assert_equal(user_1.employment, 75)
        nt.assert_equal(user_1.payed_vacation, 25)
        nt.assert_equal(user_1.vacation_month, 1)
        nt.assert_equal(user_1.employed_date,
                        datetime.datetime(year=2012, month=1, day=1).date())
예제 #27
0
    def test_no_lunch(self):
        file_parser = Parser()
        file_name = save_month_file("1. 8:00 0 12:00\n", "2014-10.txt",
                                    self.temp_dir.name)

        month_1 = file_parser.parse_month_file(file_name)
        nt.assert_equal(month_1.days[0].lunch_duration, datetime.timedelta())
        nt.assert_equal(month_1.days[0].worked_hours(),
                        datetime.timedelta(hours=4))

        file_name = save_month_file("1. 9:00 0:00 11:45\n", "2014-09.txt",
                                    self.temp_dir.name)

        month_2 = file_parser.parse_month_file(file_name)
        nt.assert_equal(month_2.days[0].lunch_duration, datetime.timedelta())
        nt.assert_equal(month_2.days[0].worked_hours(),
                        datetime.timedelta(hours=2, minutes=45))
예제 #28
0
    def test_no_lunch(self):
        file_parser = Parser()
        file_name = save_month_file(
            "1. 8:00 0 12:00\n", "2014-10.txt", self.temp_dir.name)

        month_1 = file_parser.parse_month_file(file_name)
        nt.assert_equal(month_1.days[0].lunch_duration, datetime.timedelta())
        nt.assert_equal(month_1.days[0].worked_hours(),
                        datetime.timedelta(hours=4))

        file_name = save_month_file(
            "1. 9:00 0:00 11:45\n", "2014-09.txt", self.temp_dir.name)

        month_2 = file_parser.parse_month_file(file_name)
        nt.assert_equal(month_2.days[0].lunch_duration, datetime.timedelta())
        nt.assert_equal(month_2.days[0].worked_hours(),
                        datetime.timedelta(hours=2, minutes=45))
예제 #29
0
    def test_parse_archive_one_month(self):
        file_parser = Parser()
        month_string = "2014-09\n1. 8:00 1:00 17:05"
        for n in (2, 3, 4, 5,
                  8, 9, 10, 11, 12,
                  15, 16, 17, 18, 19,
                  22, 23, 24, 25, 26,
                  29, 30):
            month_string += "\n{}. 8:00 1:00 17:00".format(n)
        file_name = save_archive_file(month_string, self.temp_dir.name)
        archive_1 = file_parser.parse_archive_file(file_name)
        nt.assert_true(len(archive_1.months), 1)
        nt.assert_true(archive_1.months[0].year, 2014)
        nt.assert_true(archive_1.months[0].month, 9)
        nt.assert_true(archive_1.calculate_flextime,
                       datetime.timedelta(minutes=5))

        nt.assert_true(archive_1.next_month, "2014-10")
예제 #30
0
    def test_half_month(self):
        file_parser = Parser()
        file_content = """1. 8:00 1:00 17:00
2. 9:00 0:30 17:45
3. 8:50 0:45 18:00
4. 9:30 1:00 16:55
5. 8:15 1:00 17:10
8. 10:00 0:50 18:05
9. 8:30
"""
        file_name = save_month_file(file_content, "2014-09.txt",
                                    self.temp_dir.name)

        month_1 = file_parser.parse_month_file(file_name)
        nt.assert_equal(len(month_1.days), 7)
        for day in month_1.days[:-1]:
            nt.assert_true(day.complete)
        nt.assert_false(month_1.days[-1].complete())
예제 #31
0
    def test_half_month(self):
        file_parser = Parser()
        file_content = """1. 8:00 1:00 17:00
2. 9:00 0:30 17:45
3. 8:50 0:45 18:00
4. 9:30 1:00 16:55
5. 8:15 1:00 17:10
8. 10:00 0:50 18:05
9. 8:30
"""
        file_name = save_month_file(
            file_content, "2014-09.txt", self.temp_dir.name)

        month_1 = file_parser.parse_month_file(file_name)
        nt.assert_equal(len(month_1.days), 7)
        for day in month_1.days[:-1]:
            nt.assert_true(day.complete)
        nt.assert_false(month_1.days[-1].complete())
예제 #32
0
    def test_one_and_a_half_month(self):
        file_parser = Parser()
        file_content_1 = """1. 8:00 1:00 17:05
2. 8:00 1:00 17:00
3. 8:00 1:00 17:00
4. 8:00 1:00 17:00
5. 8:00 1:00 17:00
8. 8:00 1:00 17:00
9. 8:00 1:00 17:00
10. 8:00 1:00 17:00
11. 8:00 1:00 17:00
12. 8:00 1:00 17:00
15. 8:00 1:00 17:00
16. 8:00 1:00 17:00
17. 8:00 1:00 17:00
18. 8:00 1:00 17:00
19. 8:00 1:00 17:00
22. 8:00 1:00 17:00
23. 8:00 1:00 17:00
24. 8:00 1:00 17:00
25. 8:00 1:00 17:00
26. 8:00 1:00 17:00
29. 8:00 1:00 17:00
30. 8:00 1:00 17:00"""

        file_content_2 = """1. 8:00 1:00 17:00
2. 8:00 1:00 17:00
3. 8:00 1:00 17:00
6. 8:00 1:00 17:00
7. 8:00 1:00 17:00
8. 8:00 1:00 17:00
9. 8:00 1:00 17:00
10. 8:00 1:00 17:00"""

        file_name_1 = save_month_file(file_content_1, "2014-09.txt",
                                      self.temp_dir.name)

        file_name_2 = save_month_file(file_content_2, "2014-10.txt",
                                      self.temp_dir.name)

        month_1 = file_parser.parse_month_file(file_name_1)
        month_2 = file_parser.parse_month_file(file_name_2)
        nt.assert_equal(month_1.month, 9)
        nt.assert_equal(month_2.month, 10)
예제 #33
0
    def test_one_and_a_half_month(self):
        file_parser = Parser()
        file_content_1 = """1. 8:00 1:00 17:05
2. 8:00 1:00 17:00
3. 8:00 1:00 17:00
4. 8:00 1:00 17:00
5. 8:00 1:00 17:00
8. 8:00 1:00 17:00
9. 8:00 1:00 17:00
10. 8:00 1:00 17:00
11. 8:00 1:00 17:00
12. 8:00 1:00 17:00
15. 8:00 1:00 17:00
16. 8:00 1:00 17:00
17. 8:00 1:00 17:00
18. 8:00 1:00 17:00
19. 8:00 1:00 17:00
22. 8:00 1:00 17:00
23. 8:00 1:00 17:00
24. 8:00 1:00 17:00
25. 8:00 1:00 17:00
26. 8:00 1:00 17:00
29. 8:00 1:00 17:00
30. 8:00 1:00 17:00"""

        file_content_2 = """1. 8:00 1:00 17:00
2. 8:00 1:00 17:00
3. 8:00 1:00 17:00
6. 8:00 1:00 17:00
7. 8:00 1:00 17:00
8. 8:00 1:00 17:00
9. 8:00 1:00 17:00
10. 8:00 1:00 17:00"""

        file_name_1 = save_month_file(
            file_content_1, "2014-09.txt", self.temp_dir.name)

        file_name_2 = save_month_file(
            file_content_2, "2014-10.txt", self.temp_dir.name)

        month_1 = file_parser.parse_month_file(file_name_1)
        month_2 = file_parser.parse_month_file(file_name_2)
        nt.assert_equal(month_1.month, 9)
        nt.assert_equal(month_2.month, 10)
예제 #34
0
    def test_deviation(self):
        file_parser = Parser()
        file_name = save_month_file("1. 8:00 1:00 17:00 0:30\n", "2014-10.txt",
                                    self.temp_dir.name)

        month_1 = file_parser.parse_month_file(file_name)
        nt.assert_equal(month_1.days[0].deviation,
                        datetime.timedelta(minutes=30))

        nt.assert_equal(month_1.days[0].worked_hours(),
                        datetime.timedelta(hours=7, minutes=30))

        file_name = save_month_file("1. 9:00 0:45 15:50 1\n", "2014-09.txt",
                                    self.temp_dir.name)

        month_2 = file_parser.parse_month_file(file_name)
        nt.assert_equal(month_2.days[0].deviation, datetime.timedelta(hours=1))
        nt.assert_equal(month_2.days[0].worked_hours(),
                        datetime.timedelta(hours=5, minutes=5))
예제 #35
0
    def test_deviation(self):
        file_parser = Parser()
        file_name = save_month_file(
            "1. 8:00 1:00 17:00 0:30\n", "2014-10.txt", self.temp_dir.name)

        month_1 = file_parser.parse_month_file(file_name)
        nt.assert_equal(month_1.days[0].deviation,
                        datetime.timedelta(minutes=30))

        nt.assert_equal(month_1.days[0].worked_hours(),
                        datetime.timedelta(hours=7, minutes=30))

        file_name = save_month_file(
            "1. 9:00 0:45 15:50 1\n", "2014-09.txt", self.temp_dir.name)

        month_2 = file_parser.parse_month_file(file_name)
        nt.assert_equal(month_2.days[0].deviation, datetime.timedelta(hours=1))
        nt.assert_equal(month_2.days[0].worked_hours(),
                        datetime.timedelta(hours=5, minutes=5))
예제 #36
0
    def test_one_complete_date(self):
        file_parser = Parser()
        file_name = save_month_file("1. 8:00 1:00 17:01\n", "2014-09.txt",
                                    self.temp_dir.name)

        month_1 = file_parser.parse_month_file(file_name)
        nt.assert_equal(len(month_1.days), 1)
        day_1 = month_1.days[-1]
        nt.assert_equal(day_1.date, datetime.date(2014, 9, 1))
        nt.assert_equal(day_1.start_time, datetime.datetime(2014, 9, 1,
                                                            hour=8))

        nt.assert_equal(day_1.lunch_duration, datetime.timedelta(hours=1))

        nt.assert_equal(day_1.end_time,
                        datetime.datetime(2014, 9, 1, hour=17, minute=1))

        nt.assert_true(day_1.complete())
        nt.assert_equal(month_1.calculate_flextime(),
                        datetime.timedelta(minutes=1))
예제 #37
0
    def test_one_complete_date(self):
        file_parser = Parser()
        file_name = save_month_file(
            "1. 8:00 1:00 17:01\n", "2014-09.txt", self.temp_dir.name)

        month_1 = file_parser.parse_month_file(file_name)
        nt.assert_equal(len(month_1.days), 1)
        day_1 = month_1.days[-1]
        nt.assert_equal(day_1.date, datetime.date(2014, 9, 1))
        nt.assert_equal(day_1.start_time,
                        datetime.datetime(2014, 9, 1, hour=8))

        nt.assert_equal(day_1.lunch_duration,
                        datetime.timedelta(hours=1))

        nt.assert_equal(day_1.end_time,
                        datetime.datetime(2014, 9, 1, hour=17, minute=1))

        nt.assert_true(day_1.complete())
        nt.assert_equal(month_1.calculate_flextime(),
                        datetime.timedelta(minutes=1))
예제 #38
0
    def test_parse_year_configuration_with_comments(self):
        file_parser = Parser()
        year_string = ("# January\n"
                       "2014-01-01: \"New years day\"\n"
                       "2014-01-06: \"Epiphany\"\n"
                       "\n"
                       "# April\n"
                       "2014-04-18: \"Good friday\"\n"
                       "2014-04-21: \"Easter monday\"")

        file_name = save_year_file(year_string, "2014", self.temp_dir.name)
        year_1 = file_parser.parse_year_file(file_name)
        nt.assert_equal(year_1.holidays["2014-01"]["2014-01-01"],
                        "New years day")

        nt.assert_equal(year_1.holidays["2014-01"]["2014-01-06"], "Epiphany")

        nt.assert_equal(year_1.holidays["2014-04"]["2014-04-18"],
                        "Good friday")

        nt.assert_equal(year_1.holidays["2014-04"]["2014-04-21"],
                        "Easter monday")
예제 #39
0
    def test_parse_year_configuration_with_comments(self):
        file_parser = Parser()
        year_string = ("# January\n"
                       "2014-01-01: \"New years day\"\n"
                       "2014-01-06: \"Epiphany\"\n"
                       "\n"
                       "# April\n"
                       "2014-04-18: \"Good friday\"\n"
                       "2014-04-21: \"Easter monday\"")

        file_name = save_year_file(year_string, "2014", self.temp_dir.name)
        year_1 = file_parser.parse_year_file(file_name)
        nt.assert_equal(year_1.holidays["2014-01"]["2014-01-01"],
                        "New years day")

        nt.assert_equal(year_1.holidays["2014-01"]["2014-01-06"],
                        "Epiphany")

        nt.assert_equal(year_1.holidays["2014-04"]["2014-04-18"],
                        "Good friday")

        nt.assert_equal(year_1.holidays["2014-04"]["2014-04-21"],
                        "Easter monday")
예제 #40
0
    def test_parse_bad_date(self):
        file_parser = Parser()
        file_content_1 = "1"
        file_name = save_month_file(file_content_1, "2014-09.txt",
                                    self.temp_dir.name)

        nt.assert_raises_regexp(errors.ParseError,
                                "Could not parse date in 2014-09: \"1\"",
                                file_parser.parse_month_file, file_name)

        file_content_2 = "1:"
        file_name = save_month_file(file_content_2, "2014-10.txt",
                                    self.temp_dir.name)

        nt.assert_raises_regexp(errors.ParseError,
                                "Could not parse date in 2014-10: \"1:\"",
                                file_parser.parse_month_file, file_name)
예제 #41
0
    def test_unmatched_quote_types(self):
        file_parser = Parser()
        file_content_1 = """1. 8:00 1:00 17:00
2. 8:00 1:00 14:00 "Went home early because of really good weather'"""

        file_name = save_month_file(file_content_1, "2014-09.txt",
                                    self.temp_dir.name)

        nt.assert_raises_regexp(errors.ParseError,
                                "No endquote in comment for date 2014-09-02.",
                                file_parser.parse_month_file, file_name)

        file_content_2 = "1. 8:00 'Bad comment\""
        file_name = save_month_file(file_content_2, "2014-09.txt",
                                    self.temp_dir.name)

        nt.assert_raises_regexp(errors.ParseError,
                                "No endquote in comment for date 2014-09-01.",
                                file_parser.parse_month_file, file_name)
예제 #42
0
def main():
    locale.setlocale(locale.LC_ALL, "")
    arguments = docopt(__doc__)
    if arguments["--verbose"]:
        print(arguments)
    config_path = os.path.expanduser("~/.chrono")
    config = get_config(config_path)
    reconfigured = False
    if "Data" not in config["Paths"]:
        print("Chrono requires a data folder. Specify data folder with the " "--set-data-folder option.")

        sys.exit(1)
    elif arguments["--set-data-folder"]:
        data_folder = os.path.abspath(os.path.expanduser(arguments["--set-data-folder"]))

        if os.path.isdir(data_folder):
            config["Paths"]["Data"] = data_folder
            reconfigured = True
        else:
            raise ValueError("Couln't find folder '{}'.".format(data_folder))
    else:
        data_folder = os.path.expanduser(config["Paths"]["Data"])
        parser = Parser()
        parser.parse_user_file(os.path.join(data_folder, "user.cfg"))
        year_files = [f[:4] for f in os.listdir(data_folder) if f.endswith(".cfg") and len(os.path.basename(f)) == 8]

        month_files = sorted(glob(os.path.join(data_folder, "[1-2][0-9][0-9][0-9]-[0-1][0-9].txt")))

        for month_file in month_files:
            year = os.path.basename(month_file)[:4]
            if year in year_files:
                parser.parse_year_file(os.path.join(data_folder, "{}.cfg".format(year)))

                year_files.remove(year)
            parser.parse_month_file(month_file)

        # Handling CLI commands
        if arguments["today"] or arguments["day"]:
            if not arguments["<date>"]:
                selected_day = parser.user.today()
            else:
                date = arguments["<date>"].split("-")
                if len(date) == 1:
                    day = int(date[0])
                    selected_day = [d for d in parser.user.current_month().days if d.date.day == day][0]

                elif len(date) == 2:
                    month, day = date
                    month = int(month)
                    day = int(day)
                    selected_month = [m for m in parser.user.current_year().months if m.month == month][0]

                    selected_day = [d for d in selected_month.days if d.date.day == day][0]

                elif len(date) == 3:
                    year, month, day = date
                    year = int(year)
                    month = int(month)
                    day = int(day)
                    selected_year = [y for y in parser.user.years if y.year == year][0]

                    selected_month = [m for m in selected_year.months if m.month == month][0]

                    selected_day = [d for d in selected_month.days if d.date.day == day][0]
                else:
                    raise errors.BadDateError("Date string must have between 1 and 3 elements.")

            print(selected_day)
        elif arguments["week"]:
            selected_week = parser.user.current_week()
            print(selected_week)
            print("Total flextime: {}".format(pretty_timedelta(parser.user.calculate_flextime(), signed=True)))

        elif arguments["month"]:
            if arguments["<date>"]:
                if "-" in arguments["<date>"]:
                    year, month = arguments["<date>"].split("-")
                    year = int(year)
                    month = int(month)
                else:
                    year = parser.user.current_year().year
                    month = int(arguments["<date>"])
                selected_year = [y for y in parser.user.years if y.year == year][0]

                selected_month = [m for m in selected_year.months if m.month == month][0]
            else:
                selected_month = parser.user.years[-1].months[-1]
            print(selected_month)
            print("Total flextime: {}".format(pretty_timedelta(parser.user.calculate_flextime(), signed=True)))

        elif arguments["year"]:
            if arguments["<date>"]:
                selected_year = [year for year in parser.user.years if str(year.year) == arguments["<date>"]][0]
            else:
                selected_year = parser.user.years[-1]
            for month in selected_year.months:
                print(month)
        elif arguments["report"]:
            if arguments["start"]:
                start_time = arguments["<time>"] or datetime.datetime.now().strftime("%H:%M")

                parser.user.add_day(parser.user.next_workday()).report_start_time(start_time)

            elif arguments["end"]:
                end_time = arguments["<time>"] or datetime.datetime.now().strftime("%H:%M")
                parser.user.today().report_end_time(end_time)
            elif arguments["lunch"]:
                parser.user.today().report_lunch_duration(arguments["<time>"])
            elif arguments["deviation"]:
                parser.user.today().report_deviation(arguments["<time>"])
            today = parser.user.today()
            month_file = os.path.join(data_folder, "{}.txt".format(today.date.strftime("%Y-%m")))

            writer.write_line(month_file, today.export())
        elif arguments["user"]:
            print()
            print(parser.user)
            print()
        elif arguments["stats"]:
            if arguments["-w"]:
                selected_period = parser.user.current_week().days
            elif arguments["-m"]:
                selected_period = parser.user.current_month().days
            elif arguments["-y"]:
                selected_period = parser.user.current_year().days
            else:
                selected_period = parser.user.all_days()
            if arguments["start"]:
                print_start_statistics(
                    selected_period,
                    histogram=arguments["--hist"],
                    bin_width=int(arguments["--bin-width"]),
                    height=int(arguments["--height"]),
                )

            if arguments["end"]:
                print_end_statistics(
                    selected_period,
                    histogram=arguments["--hist"],
                    bin_width=int(arguments["--bin-width"]),
                    height=int(arguments["--height"]),
                )

        elif arguments["vacation"]:
            print("Vacation left: {} / {}".format(parser.user.vacation_left(), parser.user.payed_vacation))
        elif arguments["edit"]:
            if "Editor" in config["Paths"]:
                if arguments["<month>"]:
                    month_string = arguments["<month>"]
                else:
                    month_string = parser.user.today().date.strftime("%Y-%m")
                month_file = os.path.join(data_folder, "{}.txt".format(month_string))

                if not os.path.exists(month_file):
                    raise errors.BadDateError("Couldn't find month file '{}'".format(month_file))

                command = [config["Paths"]["Editor"], month_file]
                subprocess.call(command)
            else:
                print("Add an editor to your .chrono configuration file.")

    if reconfigured:
        write_config(config, config_path)
예제 #43
0
def main():
    locale.setlocale(locale.LC_ALL, '')
    arguments = docopt(__doc__)
    if arguments['--verbose']:
        print(arguments)
    config_path = os.path.expanduser("~/.chrono")
    config = get_config(config_path)
    reconfigured = False
    if 'Data' not in config['Paths']:
        print("Chrono requires a data folder. Specify data folder with the "
              "--set-data-folder option.")

        sys.exit(1)
    elif arguments["--set-data-folder"]:
        data_folder = os.path.abspath(
            os.path.expanduser(arguments["--set-data-folder"]))

        if os.path.isdir(data_folder):
            config['Paths']['Data'] = data_folder
            reconfigured = True
        else:
            raise ValueError("Couln't find folder '{}'.".format(data_folder))
    else:
        data_folder = os.path.expanduser(config['Paths']['Data'])
        parser = Parser()
        parser.parse_user_file(os.path.join(data_folder, "user.cfg"))
        year_files = [
            f[:4] for f in os.listdir(data_folder)
            if f.endswith(".cfg") and len(os.path.basename(f)) == 8
        ]

        month_files = sorted(
            glob(
                os.path.join(data_folder,
                             "[1-2][0-9][0-9][0-9]-[0-1][0-9].txt")))

        for month_file in month_files:
            year = os.path.basename(month_file)[:4]
            if year in year_files:
                parser.parse_year_file(
                    os.path.join(data_folder, "{}.cfg".format(year)))

                year_files.remove(year)
            parser.parse_month_file(month_file)

        # Handling CLI commands
        if arguments['today'] or arguments['day']:
            if not arguments['<date>']:
                selected_day = parser.user.today()
            else:
                date = arguments['<date>'].split("-")
                if len(date) == 1:
                    day = int(date[0])
                    selected_day = [
                        d for d in parser.user.current_month().days
                        if d.date.day == day
                    ][0]

                elif len(date) == 2:
                    month, day = date
                    month = int(month)
                    day = int(day)
                    selected_month = [
                        m for m in parser.user.current_year().months
                        if m.month == month
                    ][0]

                    selected_day = [
                        d for d in selected_month.days if d.date.day == day
                    ][0]

                elif len(date) == 3:
                    year, month, day = date
                    year = int(year)
                    month = int(month)
                    day = int(day)
                    selected_year = [
                        y for y in parser.user.years if y.year == year
                    ][0]

                    selected_month = [
                        m for m in selected_year.months if m.month == month
                    ][0]

                    selected_day = [
                        d for d in selected_month.days if d.date.day == day
                    ][0]
                else:
                    raise errors.BadDateError(
                        "Date string must have between 1 and 3 elements.")

            print(selected_day)
        elif arguments['week']:
            selected_week = parser.user.current_week()
            print(selected_week)
            print("Total flextime: {}".format(
                pretty_timedelta(parser.user.calculate_flextime(),
                                 signed=True)))

        elif arguments['month']:
            if arguments['<date>']:
                if "-" in arguments['<date>']:
                    year, month = arguments['<date>'].split("-")
                    year = int(year)
                    month = int(month)
                else:
                    year = parser.user.current_year().year
                    month = int(arguments['<date>'])
                selected_year = [
                    y for y in parser.user.years if y.year == year
                ][0]

                selected_month = [
                    m for m in selected_year.months if m.month == month
                ][0]
            else:
                selected_month = parser.user.years[-1].months[-1]
            print(selected_month)
            print("Total flextime: {}".format(
                pretty_timedelta(parser.user.calculate_flextime(),
                                 signed=True)))

        elif arguments['year']:
            if arguments['<date>']:
                selected_year = [
                    year for year in parser.user.years
                    if str(year.year) == arguments['<date>']
                ][0]
            else:
                selected_year = parser.user.years[-1]
            for month in selected_year.months:
                print(month)
        elif arguments['report']:
            if arguments['start']:
                start_time = (arguments['<time>']
                              or datetime.datetime.now().strftime("%H:%M"))

                parser.user.add_day(
                    parser.user.next_workday()).report_start_time(start_time)

            elif arguments['end']:
                end_time = (arguments['<time>']
                            or datetime.datetime.now().strftime("%H:%M"))
                parser.user.today().report_end_time(end_time)
            elif arguments['lunch']:
                parser.user.today().report_lunch_duration(arguments['<time>'])
            elif arguments["deviation"]:
                parser.user.today().report_deviation(arguments['<time>'])
            today = parser.user.today()
            month_file = os.path.join(
                data_folder, "{}.txt".format(today.date.strftime("%Y-%m")))

            writer.write_line(month_file, today.export())
        elif arguments['user']:
            print()
            print(parser.user)
            print()
        elif arguments['stats']:
            if arguments['-w']:
                selected_period = parser.user.current_week().days
            elif arguments['-m']:
                selected_period = parser.user.current_month().days
            elif arguments['-y']:
                selected_period = parser.user.current_year().days
            else:
                selected_period = parser.user.all_days()
            if arguments['start']:
                print_start_statistics(selected_period,
                                       histogram=arguments['--hist'],
                                       bin_width=int(arguments['--bin-width']),
                                       height=int(arguments['--height']))

            if arguments['end']:
                print_end_statistics(selected_period,
                                     histogram=arguments['--hist'],
                                     bin_width=int(arguments['--bin-width']),
                                     height=int(arguments['--height']))

        elif arguments['vacation']:
            print("Vacation left: {} / {}".format(parser.user.vacation_left(),
                                                  parser.user.payed_vacation))
        elif arguments['edit']:
            if 'Editor' in config['Paths']:
                if arguments['<month>']:
                    month_string = arguments['<month>']
                else:
                    month_string = parser.user.today().date.strftime("%Y-%m")
                month_file = os.path.join(data_folder,
                                          "{}.txt".format(month_string))

                if not os.path.exists(month_file):
                    raise errors.BadDateError(
                        "Couldn't find month file '{}'".format(month_file))

                command = [config['Paths']['Editor'], month_file]
                subprocess.call(command)
            else:
                print("Add an editor to your .chrono configuration file.")

    if reconfigured:
        write_config(config, config_path)