Skip to content

Commit 293e518

Browse files
committed
update create_ohlc
- combine create_ohlc_increase and create_ohlc_decrease into create_ohlc - rename variables to open, high, low, close - 2 pep 8 fixes - check messages with assertRaisesRegexp
1 parent db377d6 commit 293e518

File tree

2 files changed

+228
-79
lines changed

2 files changed

+228
-79
lines changed

plotly/tests/test_core/test_tools/test_trace_factory.py

Lines changed: 77 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -104,65 +104,101 @@ def test_more_kwargs(self):
104104

105105
class TestOHLC(TestCase):
106106

107-
def test_unequal_o_h_l_c_length(self):
107+
def test_unequal_ohlc_length(self):
108108

109-
# check: PlotlyError if op, hi, lo, cl are not the same length for
110-
# TraceFactory.ohlc_increase and TraceFactory.ohlc_decrease
109+
# check: PlotlyError if open, high, low, close are not the same length
110+
# for TraceFactory.ohlc_increase and TraceFactory.ohlc_decrease
111111

112-
kwargs = {'op': [1], 'hi': [1, 3], 'lo': [1, 2], 'cl': [1, 2]}
112+
kwargs = {'open': [1], 'high': [1, 3], 'low': [1, 2], 'close': [1, 2]}
113113
self.assertRaises(PlotlyError, tls.TraceFactory.create_ohlc_increase,
114114
**kwargs)
115115

116-
kwargs = {'op': [1, 2], 'hi': [1, 2, 3], 'lo': [1, 2], 'cl': [1, 2]}
116+
kwargs = {'open': [1, 2], 'high': [1, 2, 3], 'low': [1, 2],
117+
'close': [1, 2]}
117118
self.assertRaises(PlotlyError, tls.TraceFactory.create_ohlc_increase,
118119
**kwargs)
119120

120-
kwargs = {'op': [1], 'hi': [1, 3], 'lo': [1, 2], 'cl': [2]}
121+
kwargs = {'open': [1], 'high': [1, 3], 'low': [1, 2], 'close': [2]}
121122
self.assertRaises(PlotlyError, tls.TraceFactory.create_ohlc_decrease,
122123
**kwargs)
123124

124-
kwargs = {'op': [1, 2], 'hi': [1, 2], 'lo': [1, 2, .5], 'cl': [1, 2]}
125+
kwargs = {'open': [1, 2], 'high': [1, 2],
126+
'low': [1, 2, .5], 'close': [1, 2]}
125127
self.assertRaises(PlotlyError, tls.TraceFactory.create_ohlc_decrease,
126128
**kwargs)
127129

128-
def test_hi_highest_value(self):
130+
def test_high_highest_value(self):
129131

130-
# check: PlotlyError if the "hi" value is less than the corresponding
131-
# op, lo, or cl value because if the "high" value is not the highest
132-
# (or equal) then the data may have been entered incorrectly.
132+
# check: PlotlyError if the "high" value is less than the corresponding
133+
# open, low, or close value because if the "high" value is not the
134+
# highest (or equal) then the data may have been entered incorrectly.
133135

134136
# create_ohlc_increase
135-
kwargs = {'op': [2, 3], 'hi': [4, 2], 'lo': [1, 1], 'cl': [1, 2]}
136-
self.assertRaises(PlotlyError, tls.TraceFactory.create_ohlc_increase,
137-
**kwargs)
137+
kwargs = {'open': [2, 3], 'high': [4, 2],
138+
'low': [1, 1], 'close': [1, 2]}
139+
self.assertRaisesRegexp(PlotlyError, "Oops! Looks like some of "
140+
"your high values are less "
141+
"the corresponding open, "
142+
"low, or close values. "
143+
"Double check that your data "
144+
"is entered in O-H-L-C order",
145+
tls.TraceFactory.create_ohlc_increase,
146+
**kwargs)
138147

139148
# create_ohlc_decrease
140-
kwargs = {'op': [2, 3], 'hi': [4, 3], 'lo': [1, 1], 'cl': [1, 6]}
141-
self.assertRaises(PlotlyError, tls.TraceFactory.create_ohlc_decrease,
142-
**kwargs)
143-
144-
def test_lo_lowest_value(self):
145-
146-
# check: PlotlyError if the "lo" value is greater than the
147-
# corresponding op, hi, or cl value because if the "lo" value is not
148-
# the lowest (or equal) then the data may have been entered incorrectly
149+
kwargs = {'open': [2, 3], 'high': [4, 3],
150+
'low': [1, 1], 'close': [1, 6]}
151+
self.assertRaisesRegexp(PlotlyError,
152+
"Oops! Looks like some of "
153+
"your high values are less "
154+
"the corresponding open, "
155+
"low, or close values. "
156+
"Double check that your data "
157+
"is entered in O-H-L-C order",
158+
tls.TraceFactory.create_ohlc_decrease,
159+
**kwargs)
160+
161+
def test_low_lowest_value(self):
162+
163+
# check: PlotlyError if the "low" value is greater than the
164+
# corresponding open, high, or close value because if the "low" value
165+
# is not the lowest (or equal) then the data may have been entered
166+
# incorrectly
149167

150168
# create_ohlc_increase
151-
kwargs = {'op': [2, 3], 'hi': [4, 6], 'lo': [3, 1], 'cl': [1, 2]}
152-
self.assertRaises(PlotlyError, tls.TraceFactory.create_ohlc_increase,
153-
**kwargs)
169+
kwargs = {'open': [2, 3], 'high': [4, 6],
170+
'low': [3, 1], 'close': [1, 2]}
171+
self.assertRaisesRegexp(PlotlyError,
172+
"Oops! Looks like some of "
173+
"your low values are greater "
174+
"than the corresponding high"
175+
", open, or close values. "
176+
"Double check that your data "
177+
"is entered in O-H-L-C order",
178+
tls.TraceFactory.create_ohlc_increase,
179+
**kwargs)
154180

155181
# create_ohlc_decrease
156-
kwargs = {'op': [2, 3], 'hi': [4, 6], 'lo': [1, 5], 'cl': [1, 6]}
157-
self.assertRaises(PlotlyError, tls.TraceFactory.create_ohlc_decrease,
158-
**kwargs)
182+
kwargs = {'open': [2, 3], 'high': [4, 6],
183+
'low': [1, 5], 'close': [1, 6]}
184+
self.assertRaisesRegexp(PlotlyError,
185+
"Oops! Looks like some of "
186+
"your low values are greater "
187+
"than the corresponding high"
188+
", open, or close values. "
189+
"Double check that your data "
190+
"is entered in O-H-L-C order",
191+
tls.TraceFactory.create_ohlc_decrease,
192+
**kwargs)
159193

160194
def test_one_ohlc_increase(self):
161195

162196
# This should create one "increase" (i.e. close > open) ohlc stick
163197

164-
ohlc_incr = tls.TraceFactory.create_ohlc_increase(op=[33.0], hi=[33.2],
165-
lo=[32.7], cl=[33.1])
198+
ohlc_incr = tls.TraceFactory.create_ohlc_increase(open=[33.0],
199+
high=[33.2],
200+
low=[32.7],
201+
close=[33.1])
166202

167203
expected_ohlc_incr = {
168204
'mode': 'lines',
@@ -179,8 +215,10 @@ def test_ohlc_increase_with_kwargs(self):
179215
# This should create one "increase" (i.e. close > open) ohlc stick
180216
# and change the name to "POSITIVE!!"
181217

182-
ohlc_incr = tls.TraceFactory.create_ohlc_increase(op=[1.5], hi=[30],
183-
lo=[1], cl=[25],
218+
ohlc_incr = tls.TraceFactory.create_ohlc_increase(open=[1.5],
219+
high=[30],
220+
low=[1],
221+
close=[25],
184222
name="POSITIVE!!")
185223

186224
expected_ohlc_incr = {
@@ -198,8 +236,10 @@ def test_one_ohlc_decrease(self):
198236

199237
# This should create one "decrease" (i.e. close < open) ohlc stick
200238

201-
ohlc_decr = tls.TraceFactory.create_ohlc_decrease(op=[33.3], hi=[33.3],
202-
lo=[32.7], cl=[32.9])
239+
ohlc_decr = tls.TraceFactory.create_ohlc_decrease(open=[33.3],
240+
high=[33.3],
241+
low=[32.7],
242+
close=[32.9])
203243

204244
expected_ohlc_decr = {
205245
'mode': 'lines',
@@ -216,8 +256,8 @@ def test_ohlc_decrease_with_kwargs(self):
216256
# This should create one "decrease" (i.e. close < open) ohlc stick
217257
# and change the line width to 4
218258

219-
ohlc_decr = tls.TraceFactory.create_ohlc_decrease(op=[15], hi=[30],
220-
lo=[1], cl=[5],
259+
ohlc_decr = tls.TraceFactory.create_ohlc_decrease(open=[15], high=[30],
260+
low=[1], close=[5],
221261
line=Line(
222262
color='rgb(214, 39, 40)',
223263
width=4))

0 commit comments

Comments
 (0)