Skip to content

Commit

Permalink
fixed bug and added test that no new day is added in certain cases; f…
Browse files Browse the repository at this point in the history
…ixed error on dumping an empty month
  • Loading branch information
Tino Michael committed Aug 1, 2018
1 parent 36b0552 commit c9011fc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
20 changes: 18 additions & 2 deletions tests/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ def test_fix_saldos():
"--end", "17:30",
"--export", ""]

pre_db = {2018: {7: {29: {
db = {2018: {7: {29: {
17: {'start': '9:00', 'end': '17:30', 'pause': 30, 'Arbeitszeit': '8:00',
'Tagessaldo': '5:00'},
'Wochensaldo': '1:00'},
'Monatssaldo': '2:00'},
'Jahressaldo': '3:00'}}

db = main(db=pre_db)
db = main(db=db)

assert db == {2018: {7: {29: {
17: {'start': '9:00', 'end': '17:30', 'pause': 30, 'Arbeitszeit': '8:00',
Expand All @@ -79,3 +79,19 @@ def test_fix_saldos():
'Wochensaldo': '1:00'},
'Monatssaldo': '1:00'},
'Jahressaldo': '1:00'}}


def test_no_new_day():
sys.argv[1:] = [
"--db_path", "/tmp/",
"--date", "2018-07-18",
"--user", "test_no_new_day",
"--export", ""]

db = {2018: {7: {29: {
17: {'start': '9:00', 'end': '17:30', 'pause': 30}}}}}

db = main(db=db)

with raises(KeyError):
day = db[2018][7][29][18]
7 changes: 5 additions & 2 deletions zeiterfassung.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def main(db=None):
if args.multi_day:
this_day = this_day[args.multi_day]
this_day.update(dict((k, {}) for k in this_day))
elif not (args.start is False and args.end is False and args.comment is False):
elif not (args.start is False and args.end is False and args.comment is None):
this_day = update_day(this_day, args, round_up, round_down)

# recursively remove empty dictionary leaves
Expand All @@ -131,7 +131,10 @@ def main(db=None):
calculate_saldos(db, work_time=args.work_time)

print(f"\nerfasste Zeiten für {args.user}:\n", db_file)
print(yaml.dump(db if args.verbose else db[year][month],
print(yaml.dump(db if args.verbose else
{round_down.strftime("%B"): (db[year][month] if
(year in db and month in db[year]) else
"no entries for this month")},
default_flow_style=args.expand))
yaml.dump(db, open(db_file, mode="w"), Dumper=Dumper)

Expand Down

0 comments on commit c9011fc

Please sign in to comment.