__main__.py 3.62 KB
Newer Older
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
1
2
3
4
5
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# ================= FILE HEADER ========================================
#
Philipp Gast's avatar
Philipp Gast committed
6
#   myplotlib v3.0.1,
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#
#   @file      __main__.py
#   @author    Yori 'AGy' Fournier
#   @licence   CC-BY-SA
#
#   main program of the module to use in command-line mode.
#   for printing usage:
#
#            > python myplotlib -h
#
#   @section Test
#
#   run a few Test to verify integrity of library.
#
#   @section Plot
#
#   interface to the plot scripts
#
#   @section History
#
#   v 0.0.0 - __main__.py file for the myplotlib module
#             no tests and no plots
#
# ======================================================================
#
#
# IMPORT ---------------------------------------------------------------
34
35
from . import INFO, SPCE, DBUG
from . import myTest, testList
Yori Fournier's avatar
Yori Fournier committed
36
from .test import __dict__ as availTests
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
37
38
39
40
41
42
43
44

import sys
import getopt

# LOCAL VARIABLE
run4Plot = False
arg4Plot = ''
run4Test = False
45
debug    = False
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

# GET PASSED OPTIONS --------------------------------------------------- 
usage = '''
{0}Usage:       python mfdPlot [-h]
{1}                            [-t/--test [all/<num of test>]
{1}                            [-p/--plot <Name of the Plot>]
{1}                            [-a/--args <String of the arguments>]
{1}                            [--debug]
'''.format(INFO, SPCE)

# GET OPT
try:
    opts, args = getopt.getopt(
        sys.argv[1:], "htp:", ["test=", "plot=", "args=", "debug"])
    
except getopt.GetoptError:
    print(usage)
    sys.exit(1)

# CASE OPT
for opt, arg in opts:
    if(opt == '-h'):
        print(usage)
        sys.exit(0)
70
    
71
    elif opt in ("-t"):
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
72
        run4Test = True
73
    
74
75
76
77
78
    elif opt in ("--test"):
        run4Test = True
        tests = arg.split(', ')
        testList = []
        for test in tests:
Yori Fournier's avatar
Yori Fournier committed
79
80
            if test in availTests.keys():
                testList.append(availTests[test])
81
82
83
84
85
        
        if len(testList) == 0:
            print(" > sevr-: you need to give valid tests to be tested.")
            exit(1)
    
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
86
87
88
    elif opt in ("-p", "--plot"):
        run4Plot = True
        arg4Plot = str(arg)
89
    
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
90
    elif opt in ("--debug"):
91
        debug = True
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
92
93
94
95
96


# SECTION: TESTS ------------------------------------------------------
if run4Test:

97
98
99
100
    if debug:
        print(DBUG + '{title:{c}^{n}}'.format(title=' Run for Test ', c='=', n=72))
    else:
        print(INFO + '{title:{c}^{n}}'.format(title=' Run for Test ', c='=', n=72))
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
101
        
102
103
    fail = []
    status = True
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
104

105
106
    print(INFO + "TESTS: ")
    for test in testList:
107
        print('\n')
108
        print(INFO + '{title:{c}^{n}}'.format(title=' ' + str(test.__name__) + ' ', c='=', n=72))
109
110
111
112
113
114
115
        testStatus = myTest(test, True, fail, debug)  # function, expected, fail, debug
        if testStatus:
            print(INFO + 72 * '-' + " [PASSED]")
        else:
            print(INFO + 72 * '-' + " [FAILED] !")
        
        status = status and testStatus
116
    
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
117
    # Print final status
118
    print('\n')
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
119
120
121
122
123
124
125
126
127
128
129
130
131
    print(INFO + 'Status of test series: ' + str(status))
    if not status:
        print(SPCE + 'Number of Failed Tests: ' + str(len(fail)))
        print(SPCE + 'List of Failed Tests: ')
        for test in fail:
            print(SPCE + '\t- ' + str(test))

# SECTION: PLOTS ------------------------------------------------------
elif run4Plot:
    
    print(INFO + '{title:{c}^{n}}'.format(title=' Run for Plot ', c='=', n=72))
  
#  try:
132
133
#    data = arg4Plot
#    somePlottingRoutine(data)
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
134
135
136
137
138
139
140
141
142
143
144
#  except:
#    print('\n'+SEVR+"There is something wrong with your arguments.")
#    print(usage)
#    print(INFO+"To start interactively:")
#    print(SPCE+">> from mfdPlot import * \n")

else:

    print(usage)