__main__.py 3.13 KB
Newer Older
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
1
2
3
4
5
6
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# ================= FILE HEADER ========================================
#
#   myplotlib v0.0.0,
#
#   @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 .__init__ import INFO, SPCE, DBUG
from .__init__ import myTest, testList
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
36
37
38
39
40
41
42
43

import sys
import getopt

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

# 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)
69
    
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
70
71
    elif opt in ("-t", "--test"):
        run4Test = True
72
    
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
73
74
75
    elif opt in ("-p", "--plot"):
        run4Plot = True
        arg4Plot = str(arg)
76
    
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
77
    elif opt in ("--debug"):
78
        debug = True
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
79
80
81
82
83


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

84
85
86
87
    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
88
        
89
90
    fail = []
    status = True
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
91

92
93
94
95
96
97
98
99
    print(INFO + "TESTS: ")
    for test in testList:
        print
        print
        print(INFO + '{title:{c}^{n}}'.format(title=' ' + str(test.__name__) + ' ', c='=', n=72))
        status = myTest(test, True, fail, debug)  # function, expected, fail, debug
        if status: print(INFO + 72 * '-' + " [PASSED]")
    
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
    # Print final status
    print
    print
    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:
116
117
#    data = arg4Plot
#    somePlottingRoutine(data)
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
118
119
120
121
122
123
124
125
126
127
128
#  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)