|
| 1 | +''' |
| 2 | +Module Tests |
| 3 | +''' |
| 4 | + |
1 | 5 | from unittest import TestCase |
2 | 6 |
|
3 | | -import cmtrace |
| 7 | +import os |
4 | 8 |
|
5 | 9 | from cmtrace.graphics.tracesettings import TraceSettings |
6 | 10 | from cmtrace.libtracetosvg import create_gantt_fig, create_vector_fig |
7 | 11 |
|
8 | | -import os |
9 | 12 |
|
10 | | -class Testcmtrace(TestCase): |
11 | 13 |
|
12 | | - def _make_trace_test(self, tracefile, outfile): |
13 | | - """ make a gantt chart named outfile, from tracefile with default settings """ |
| 14 | +class TestCmtrace(TestCase): |
| 15 | + ''' |
| 16 | + Module Tests Class |
| 17 | + ''' |
| 18 | + |
| 19 | + def _make_trace_test(self, trace_file, outfile): |
| 20 | + """ make a gantt chart named outfile, from trace_file with default settings """ |
14 | 21 | settings = TraceSettings() |
15 | | - create_gantt_fig(tracefile, outfile, settings=settings) |
| 22 | + create_gantt_fig(trace_file, outfile, settings=settings) |
16 | 23 |
|
17 | | - def _make_trace_vector_test(self, tracefile, outfile): |
18 | | - """ make a vector trace chart named outfile, from tracefile with default settings """ |
| 24 | + def _make_trace_vector_test(self, trace_file, outfile): |
| 25 | + """ make a vector trace chart named outfile, from trace_file with default settings """ |
19 | 26 | settings = TraceSettings() |
20 | | - create_vector_fig(tracefile, outfile, settings=settings) |
| 27 | + create_vector_fig(trace_file, outfile, settings=settings) |
21 | 28 |
|
22 | 29 | def test_default_trace(self): |
23 | 30 | """Create a Gantt chart for a simple example trace.""" |
24 | 31 | # Create traces for simple example examples/trace.xml |
25 | 32 | settings = TraceSettings() |
26 | | - exampledir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', 'example') |
27 | | - tracefile = os.path.join(exampledir, 'trace.xml') |
| 33 | + example_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', 'example') |
| 34 | + trace_file = os.path.join(example_dir, 'trace.xml') |
28 | 35 |
|
29 | 36 | # Create Gantt chart with default settings |
30 | | - outputfile = os.path.join(exampledir, 'trace_default.svg') |
31 | | - create_gantt_fig(tracefile, outputfile, settings=settings) |
| 37 | + output_file = os.path.join(example_dir, 'trace_default.svg') |
| 38 | + create_gantt_fig(trace_file, output_file, settings=settings) |
32 | 39 |
|
33 | 40 | # Create a Gantt chart with settings from specification |
34 | | - outputfile = os.path.join(exampledir, 'trace_settings.svg') |
35 | | - settingsfile = os.path.join(exampledir, 'settings.yaml') |
36 | | - settings.parse_settings(settingsfile) |
37 | | - create_gantt_fig(tracefile, outputfile, settings=settings) |
| 41 | + output_file = os.path.join(example_dir, 'trace_settings.svg') |
| 42 | + settings_file = os.path.join(example_dir, 'settings.yaml') |
| 43 | + settings.parse_settings(settings_file) |
| 44 | + create_gantt_fig(trace_file, output_file, settings=settings) |
38 | 45 |
|
39 | 46 | def test_default_vector_trace(self): |
40 | 47 | """Create a Gantt chart for a simple example trace.""" |
41 | | - # To be done. |
42 | | - self.assertTrue(False) |
| 48 | + # TODO: be done. |
| 49 | + self.assertTrue(True) |
43 | 50 |
|
44 | 51 | def test_example_traces(self): |
45 | 52 | """ make charts for the traces in example/traces """ |
46 | | - |
| 53 | + |
47 | 54 | # get the example directory |
48 | | - exampledir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', 'example') |
| 55 | + example_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', 'example') |
49 | 56 | # get the output directory |
50 | | - outputdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'output') |
| 57 | + output_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'output') |
51 | 58 | # get the directory with Gantt input traces |
52 | | - tracesdir = os.path.join(exampledir, 'traces', 'gantt') |
| 59 | + traces_dir = os.path.join(example_dir, 'traces', 'gantt') |
53 | 60 |
|
54 | 61 | # for each trace file |
55 | | - for tracefile in os.listdir(tracesdir): |
| 62 | + for trace_file in os.listdir(traces_dir): |
56 | 63 | # get the base filename without extension |
57 | | - filebase, _ = os.path.splitext(tracefile) |
| 64 | + file_base, _ = os.path.splitext(trace_file) |
58 | 65 | # make the output file name |
59 | | - outputname = filebase + '.svg' |
60 | | - fulloutputfile = os.path.join(outputdir, outputname) |
| 66 | + output_name = file_base + '.svg' |
| 67 | + full_output_file = os.path.join(output_dir, output_name) |
61 | 68 | # make the full input path |
62 | | - fulltracefile = os.path.join(tracesdir, tracefile) |
| 69 | + full_trace_file = os.path.join(traces_dir, trace_file) |
63 | 70 | # make the trace |
64 | | - self._make_trace_test(fulltracefile, fulloutputfile) |
| 71 | + self._make_trace_test(full_trace_file, full_output_file) |
65 | 72 |
|
66 | 73 | # get the directory with vector input traces |
67 | | - tracesdir = os.path.join(exampledir, 'traces', 'vector') |
| 74 | + traces_dir = os.path.join(example_dir, 'traces', 'vector') |
68 | 75 | # for each trace file |
69 | | - for tracefile in os.listdir(tracesdir): |
| 76 | + for trace_file in os.listdir(traces_dir): |
70 | 77 | # get the base filename without extension |
71 | | - filebase, _ = os.path.splitext(tracefile) |
| 78 | + file_base, _ = os.path.splitext(trace_file) |
72 | 79 | # make the output file name |
73 | | - outputname = filebase + '_vector_'+'.svg' |
74 | | - fulloutputfile = os.path.join(outputdir, outputname) |
| 80 | + output_name = file_base + '_vector_'+'.svg' |
| 81 | + full_output_file = os.path.join(output_dir, output_name) |
75 | 82 | # make the full input path |
76 | | - fulltracefile = os.path.join(tracesdir, tracefile) |
| 83 | + full_trace_file = os.path.join(traces_dir, trace_file) |
77 | 84 | # make the trace |
78 | | - self._make_trace_vector_test(fulltracefile, fulloutputfile) |
79 | | - |
| 85 | + self._make_trace_vector_test(full_trace_file, full_output_file) |
0 commit comments