11#!/usr/bin/env python3
2- """Test Timetracker use cases"""
2+ """Test Timetracker use cases.
3+
4+ NOTE: Package `lxml` did not load easily in cygwin, hanging in:
5+ `Building wheel for lxml (pyproject.toml) ...`
6+
7+ Therefore, `docx` (`pip install python-docx`), is optional.
8+ I successfully installed it in cygwin by:
9+ $ git clone git@github.com:lxml/lxml.git
10+ $ cd lxml
11+ $ python setup.py build
12+ $ python setup.py install
13+
14+ """
315
4- #from os import environ
5- #from datetime import timedelta
6- #from timeit import default_timer
7- #from timetracker.consts import DIRTRK
8- #from timetracker.cli import Cli
916from datetime import datetime
1017from datetime import timedelta
11- from timetracker .docx import WordDoc
18+
19+ from timetracker .docx import write_doc
20+ from timetracker .docx import write_invoice
21+ from timetracker .cmd .invoice import _get_billable_timeslots
22+
1223from timetracker .csvfile import CsvFile
1324from timetracker .epoch .text import get_data_formatted
1425from tests .pkgtttest .cmpstr import get_filename
1526
16- # pylint: disable=fixme
1727
28+ def test_docx_report ():
29+ """Test Timetracker report writing"""
30+ print ('\n TEST REPORT WRITING...' )
31+ filename = get_filename ('docxtest_report.docx' )
32+ ##doc = WordDoc(get_data_formatted(_get_datadt()))
33+ ##doc.write_doc(filename)
34+ time_formatted = get_data_formatted (_get_datadt ())
35+ exp = _get_exp_worddoc ()
36+ assert (act := write_doc (filename , time_formatted )) == exp , f'WordDoc: EXP({ exp } ) != ACT({ act } )'
1837
19- def test_docx ():
38+ def test_docx_invoice ():
2039 """Test Timetracker use cases"""
21- filename = get_filename ('docxtest.docx' )
22- doc = WordDoc (get_data_formatted (_get_datadt ()))
23- doc .write_doc (filename )
24- # pylint: disable=line-too-long
25- # make clobber
26-
27- # trk
28- # Run `trk init` to initialize time-tracking for the project in
29-
30- # trk
31- # Run `trk init` to initialize time-tracking for the project in
40+ print ('\n TEST INVOICE WRITING...' )
41+ filename = get_filename ('docxtest_invoice.docx' )
42+ ##doc = WordDoc(get_data_formatted(_get_datadt()))
43+ ##doc.write_doc(filename)
44+ ##time_formatted = get_data_formatted(_get_datadt())
45+ nttimeslots = _get_datadt ()
46+ exp = _get_exp_worddoc ()
47+ billable = _get_billable_timeslots (nttimeslots , hourly_rate = 350 )
48+ assert (act := write_invoice (filename , billable )) == exp , f'WordDoc: EXP({ exp } ) != ACT({ act } )'
3249
33- # trk init
34- # Initialized timetracker directory:
35-
36- # trk init
37- # Trk repository already initialized:
38-
39- # trk start
40- # Timetracker started Wed 03:21 PM: 2025-02-05 15:21:36.452917 for project 'timetracker' ID=username
41-
42- # trk start
43- # Do `trk stop -m "task description"` to stop tracking this time unit
44-
45- # trk stop
46- # usage: timetracker stop [-h] -m MESSAGE [--activity ACTIVITY] [-t [TAGS ...]]
47- # timetracker stop: error: the following arguments are required: -m/--message
48-
49- # trk stop -m 'test stopped'
50- # Timer stopped; Elapsed H:M:S=0:00:19.531226 appended to timetracker_timetracker_username.csv
5150
5251def _get_datadt ():
5352 # pylint: disable=line-too-long
@@ -74,5 +73,16 @@ def _get_datadt():
7473 ]
7574
7675
76+ def _get_exp_worddoc ():
77+ try :
78+ # pylint: disable=import-outside-toplevel
79+ # pylint: disable=unused-import
80+ import docx
81+ return True
82+ except ModuleNotFoundError :
83+ return False
84+
85+
7786if __name__ == '__main__' :
78- test_docx ()
87+ test_docx_report ()
88+ test_docx_invoice ()
0 commit comments