diff --git a/tests/test_basics.py b/tests/test_basics.py index e64e39b..18274d9 100644 --- a/tests/test_basics.py +++ b/tests/test_basics.py @@ -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', @@ -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] diff --git a/zeiterfassung.py b/zeiterfassung.py index aed4039..e192478 100755 --- a/zeiterfassung.py +++ b/zeiterfassung.py @@ -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 @@ -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)