Skip to content

Commit a819660

Browse files
committed
Create test_stack.py
1 parent 000b5a9 commit a819660

File tree

1 file changed

+179
-0
lines changed

1 file changed

+179
-0
lines changed

Exercise01/test_stack.py

+179
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
"""
2+
Simple tests for verifying software requirements.
3+
These tests will check if the following conditions
4+
are met:
5+
6+
* Python is 3.0 or higher.
7+
* TensorFlow is 2.0 or higher.
8+
* Keras is 2.2 or higher.
9+
10+
The program returns helpful error messages if
11+
the conditions above are not met.abs
12+
13+
Proceed to Chapter 02 when all tests pass.
14+
15+
--
16+
Author: Luis Capelo
17+
Date: October 17, 2017
18+
"""
19+
import sys
20+
21+
22+
def __separator(c):
23+
"""
24+
Prints a pretty separator.
25+
26+
Parameters
27+
----------
28+
c: str
29+
Character to use.
30+
"""
31+
print(c * 65)
32+
33+
def test_python():
34+
"""
35+
Tests if Python 3 is installed.
36+
"""
37+
message = None
38+
if sys.version_info[0] == 3:
39+
success = True
40+
log = """
41+
PASS: Python 3.0 (or higher) is installed.
42+
"""
43+
44+
else:
45+
success = False
46+
log = """
47+
FAIL: Python 3.0 (or higher) not detected.
48+
"""
49+
message = """
50+
Please install it before proceeding.
51+
Follow instructions in the official Python
52+
website in order to install it in your platform:
53+
54+
https://www.python.org/downloads/
55+
"""
56+
57+
print(log)
58+
if message:
59+
print(message)
60+
61+
__separator('~')
62+
return success
63+
64+
def test_tensorflow():
65+
"""
66+
Tests if TensorFlow is installed.
67+
"""
68+
message = None
69+
try:
70+
import tensorflow;
71+
72+
if tensorflow.__version__ >= '2.0.0':
73+
success = True
74+
log = """
75+
PASS: TensorFlow 2.0.0 (or higher) is installed.
76+
"""
77+
78+
else:
79+
success = False
80+
log = """
81+
FAIL: TensorFlow 2.0.0 (or higher) not detected.
82+
"""
83+
message = """
84+
Please install it before proceeding.
85+
Follow instructions in the official TensorFlow
86+
website in order to install it in your platform:
87+
88+
https://www.tensorflow.org/install/
89+
"""
90+
91+
except ModuleNotFoundError:
92+
success = False
93+
log = """
94+
FAIL: TensorFlow 2.0.0 (or higher) not detected.
95+
"""
96+
message = """
97+
Please install it before proceeding.
98+
Follow instructions in the official TensorFlow
99+
website in order to install it in your platform:
100+
101+
https://www.tensorflow.org/install/
102+
"""
103+
104+
print(log)
105+
if message:
106+
print(message)
107+
108+
__separator('~')
109+
return success
110+
111+
def test_keras():
112+
"""
113+
Tests if Keras is installed.
114+
"""
115+
message = None
116+
try:
117+
import keras
118+
119+
if sys.version_info[0] == 3:
120+
success = True
121+
log = """
122+
PASS: Keras 2.2 (or higher) is installed.
123+
"""
124+
125+
else:
126+
success = False
127+
log = """
128+
FAIL: Keras 2.2 (or higher) not detected.
129+
"""
130+
message = """
131+
Please install it before proceeding.
132+
Follow instructions in the official Keras
133+
website in order to install it in your platform:
134+
135+
https://keras.io/#installation
136+
"""
137+
138+
except ModuleNotFoundError:
139+
success = False
140+
log = """
141+
FAIL: Keras 2.2 (or higher) not detected.
142+
"""
143+
message = """
144+
Please install it before proceeding.
145+
Follow instructions in the official Keras
146+
website in order to install it in your platform:
147+
148+
https://keras.io/#installation
149+
"""
150+
151+
print(log)
152+
if message:
153+
print(message)
154+
155+
__separator('~')
156+
return success
157+
158+
159+
if __name__ == '__main__':
160+
__separator('=')
161+
test_results = [
162+
test_python(),
163+
test_tensorflow(),
164+
test_keras()]
165+
166+
if False in test_results:
167+
print(
168+
"""
169+
** Please review software requirements before
170+
** proceeding to Chapter 02.
171+
"""
172+
)
173+
else:
174+
print(
175+
"""
176+
** Python, TensorFlow, and Keras are available.
177+
"""
178+
)
179+
__separator('=')

0 commit comments

Comments
 (0)