Skip to content

Commit 88caeda

Browse files
author
Kevin D Smith
committed
Make sure import errors do not cause tests to fail
1 parent 8062e17 commit 88caeda

File tree

2 files changed

+155
-94
lines changed

2 files changed

+155
-94
lines changed

swat/tests/cas/test_basics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def test_summary(self):
208208
self.assertEqual(summ.name, 'Summary')
209209
self.assertEqual(summ.label, myLabel)
210210
self.assertEqual(summ.title, myTitle)
211-
self.assertEqual(len(summ.columns), 15)
211+
self.assertTrue(len(summ.columns) >= 15)
212212

213213
self.assertEqual(summ.columns[0], 'Column')
214214
self.assertEqual(summ.colinfo['Column'].name, 'Column')

swat/tests/cas/test_table.py

Lines changed: 154 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -4405,170 +4405,231 @@ def test_hist(self):
44054405
tbl = self.table
44064406
df = self.get_cars_df()
44074407

4408-
self.assertPlotsEqual(tbl.hist()[0][0], df.hist()[0][0])
4409-
self.assertPlotsEqual(tbl.hist()[0][1], df.hist()[0][1])
4410-
self.assertPlotsEqual(tbl.hist()[0][2], df.hist()[0][2])
4408+
try:
4409+
self.assertPlotsEqual(tbl.hist()[0][0], df.hist()[0][0])
4410+
self.assertPlotsEqual(tbl.hist()[0][1], df.hist()[0][1])
4411+
self.assertPlotsEqual(tbl.hist()[0][2], df.hist()[0][2])
4412+
4413+
self.assertPlotsEqual(tbl.hist()[1][0], df.hist()[1][0])
4414+
self.assertPlotsEqual(tbl.hist()[1][1], df.hist()[1][1])
4415+
self.assertPlotsEqual(tbl.hist()[1][2], df.hist()[1][2])
44114416

4412-
self.assertPlotsEqual(tbl.hist()[1][0], df.hist()[1][0])
4413-
self.assertPlotsEqual(tbl.hist()[1][1], df.hist()[1][1])
4414-
self.assertPlotsEqual(tbl.hist()[1][2], df.hist()[1][2])
4417+
self.assertPlotsEqual(tbl.hist()[2][0], df.hist()[2][0])
4418+
self.assertPlotsEqual(tbl.hist()[2][1], df.hist()[2][1])
4419+
self.assertPlotsEqual(tbl.hist()[2][2], df.hist()[2][2])
44154420

4416-
self.assertPlotsEqual(tbl.hist()[2][0], df.hist()[2][0])
4417-
self.assertPlotsEqual(tbl.hist()[2][1], df.hist()[2][1])
4418-
self.assertPlotsEqual(tbl.hist()[2][2], df.hist()[2][2])
4421+
self.assertPlotsEqual(tbl.hist()[3][0], df.hist()[3][0])
4422+
self.assertPlotsEqual(tbl.hist()[3][1], df.hist()[3][1])
4423+
self.assertPlotsEqual(tbl.hist()[3][2], df.hist()[3][2])
44194424

4420-
self.assertPlotsEqual(tbl.hist()[3][0], df.hist()[3][0])
4421-
self.assertPlotsEqual(tbl.hist()[3][1], df.hist()[3][1])
4422-
self.assertPlotsEqual(tbl.hist()[3][2], df.hist()[3][2])
4425+
except ImportError as msg:
4426+
tm.TestCase.skipTest(self, '%s' % msg)
44234427

44244428
def test_boxplot(self):
44254429
tbl = self.table
44264430
df = self.get_cars_df()
4427-
self.assertPlotsEqual(
4428-
tbl[['MSRP', 'Invoice']].boxplot(return_type='axes'),
4429-
df[['MSRP', 'Invoice']].boxplot(return_type='axes')
4430-
)
4431+
4432+
try:
4433+
self.assertPlotsEqual(
4434+
tbl[['MSRP', 'Invoice']].boxplot(return_type='axes'),
4435+
df[['MSRP', 'Invoice']].boxplot(return_type='axes')
4436+
)
4437+
4438+
except ImportError as msg:
4439+
tm.TestCase.skipTest(self, '%s' % msg)
44314440

44324441
def test_plot(self):
44334442
tbl = self.table
44344443
df = self.get_cars_df()
44354444

4436-
# Basic plot
4437-
self.assertPlotsEqual(
4438-
tbl.sort_values(['MSRP', 'Invoice']).plot('Make', ['MSRP', 'Invoice']),
4439-
df.sort_values(['MSRP', 'Invoice']).plot('Make', ['MSRP', 'Invoice'])
4440-
)
4441-
4442-
# Must reset index here because it uses that as X axis
4443-
self.assertPlotsEqual(
4444-
tbl.sort_values(['MSRP', 'Invoice']).plot(y=['MSRP', 'Invoice']),
4445-
df.sort_values(['MSRP', 'Invoice']).reset_index().plot(y=['MSRP', 'Invoice'])
4446-
)
4447-
4448-
# Test kind= parameter
4449-
self.assertPlotsEqual(
4450-
tbl.sort_values(['MSRP', 'Invoice']).plot('MSRP', 'Invoice', 'scatter'),
4451-
df.sort_values(['MSRP', 'Invoice']).plot('MSRP', 'Invoice', 'scatter')
4452-
)
4453-
4454-
self.assertPlotsEqual(
4455-
tbl.sort_values(['MSRP', 'Invoice']).plot('MSRP', 'Invoice', kind='scatter'),
4456-
df.sort_values(['MSRP', 'Invoice']).plot('MSRP', 'Invoice', kind='scatter')
4457-
)
4458-
4459-
self.assertPlotsEqual(
4460-
tbl.sort_values(['MSRP', 'Invoice']).plot('Make', ['MSRP', 'Invoice'], kind='bar'),
4461-
df.sort_values(['MSRP', 'Invoice']).plot('Make', ['MSRP', 'Invoice'], kind='bar')
4462-
)
4445+
try:
4446+
# Basic plot
4447+
self.assertPlotsEqual(
4448+
tbl.sort_values(['MSRP', 'Invoice']).plot('Make', ['MSRP', 'Invoice']),
4449+
df.sort_values(['MSRP', 'Invoice']).plot('Make', ['MSRP', 'Invoice'])
4450+
)
4451+
4452+
# Must reset index here because it uses that as X axis
4453+
self.assertPlotsEqual(
4454+
tbl.sort_values(['MSRP', 'Invoice']).plot(y=['MSRP', 'Invoice']),
4455+
df.sort_values(['MSRP', 'Invoice']).reset_index().plot(y=['MSRP', 'Invoice'])
4456+
)
4457+
4458+
# Test kind= parameter
4459+
self.assertPlotsEqual(
4460+
tbl.sort_values(['MSRP', 'Invoice']).plot('MSRP', 'Invoice', 'scatter'),
4461+
df.sort_values(['MSRP', 'Invoice']).plot('MSRP', 'Invoice', 'scatter')
4462+
)
4463+
4464+
self.assertPlotsEqual(
4465+
tbl.sort_values(['MSRP', 'Invoice']).plot('MSRP', 'Invoice', kind='scatter'),
4466+
df.sort_values(['MSRP', 'Invoice']).plot('MSRP', 'Invoice', kind='scatter')
4467+
)
4468+
4469+
self.assertPlotsEqual(
4470+
tbl.sort_values(['MSRP', 'Invoice']).plot('Make', ['MSRP', 'Invoice'], kind='bar'),
4471+
df.sort_values(['MSRP', 'Invoice']).plot('Make', ['MSRP', 'Invoice'], kind='bar')
4472+
)
4473+
4474+
except ImportError as msg:
4475+
tm.TestCase.skipTest(self, '%s' % msg)
44634476

44644477
def test_plot_sampling(self):
44654478
tbl = self.table
44664479

4467-
self.assertPlotsEqual(
4468-
tbl.sort_values(['MSRP', 'Invoice'])\
4469-
.plot('MSRP', 'Invoice', sample_pct=0.05, sample_seed=123),
4470-
tbl._fetch(sample_pct=0.05, sample_seed=123)\
4471-
.sort_values(['MSRP', 'Invoice']).plot('MSRP', 'Invoice')
4472-
)
4480+
try:
4481+
self.assertPlotsEqual(
4482+
tbl.sort_values(['MSRP', 'Invoice'])\
4483+
.plot('MSRP', 'Invoice', sample_pct=0.05, sample_seed=123),
4484+
tbl._fetch(sample_pct=0.05, sample_seed=123)\
4485+
.sort_values(['MSRP', 'Invoice']).plot('MSRP', 'Invoice')
4486+
)
4487+
4488+
except ImportError as msg:
4489+
tm.TestCase.skipTest(self, '%s' % msg)
44734490

44744491
def test_plot_area(self):
44754492
tbl = self.table
44764493
df = self.get_cars_df()
44774494

4478-
self.assertPlotsEqual(
4479-
tbl.sort_values(['MSRP', 'Invoice']).plot.area('Make', ['MSRP', 'Invoice']),
4480-
df.sort_values(['MSRP', 'Invoice']).plot.area('Make', ['MSRP', 'Invoice'])
4481-
)
4495+
try:
4496+
self.assertPlotsEqual(
4497+
tbl.sort_values(['MSRP', 'Invoice']).plot.area('Make', ['MSRP', 'Invoice']),
4498+
df.sort_values(['MSRP', 'Invoice']).plot.area('Make', ['MSRP', 'Invoice'])
4499+
)
4500+
4501+
except ImportError as msg:
4502+
tm.TestCase.skipTest(self, '%s' % msg)
44824503

44834504
def test_plot_bar(self):
44844505
tbl = self.table
44854506
df = self.get_cars_df()
44864507

4487-
self.assertPlotsEqual(
4488-
tbl['Cylinders'].sort_values().plot.bar(),
4489-
df['Cylinders'].sort_values().plot.bar()
4490-
)
4508+
try:
4509+
self.assertPlotsEqual(
4510+
tbl['Cylinders'].sort_values().plot.bar(),
4511+
df['Cylinders'].sort_values().plot.bar()
4512+
)
4513+
4514+
except ImportError as msg:
4515+
tm.TestCase.skipTest(self, '%s' % msg)
44914516

44924517
def test_plot_barh(self):
44934518
tbl = self.table
44944519
df = self.get_cars_df()
44954520

4496-
self.assertPlotsEqual(
4497-
tbl['Cylinders'].sort_values().plot.barh(),
4498-
df['Cylinders'].sort_values().plot.barh()
4499-
)
4521+
try:
4522+
self.assertPlotsEqual(
4523+
tbl['Cylinders'].sort_values().plot.barh(),
4524+
df['Cylinders'].sort_values().plot.barh()
4525+
)
4526+
4527+
except ImportError as msg:
4528+
tm.TestCase.skipTest(self, '%s' % msg)
45004529

45014530
def test_plot_box(self):
45024531
tbl = self.table
45034532
df = self.get_cars_df()
45044533

4505-
self.assertPlotsEqual(
4506-
tbl[['MSRP', 'Invoice']].plot.box(),
4507-
df[['MSRP', 'Invoice']].plot.box()
4508-
)
4534+
try:
4535+
self.assertPlotsEqual(
4536+
tbl[['MSRP', 'Invoice']].plot.box(),
4537+
df[['MSRP', 'Invoice']].plot.box()
4538+
)
4539+
4540+
except ImportError as msg:
4541+
tm.TestCase.skipTest(self, '%s' % msg)
45094542

45104543
def test_plot_density(self):
45114544
tbl = self.table
45124545
df = self.get_cars_df()
45134546

4514-
self.assertPlotsEqual(
4515-
tbl[['MSRP', 'Invoice']].plot.density(),
4516-
df[['MSRP', 'Invoice']].plot.density()
4517-
)
4547+
try:
4548+
self.assertPlotsEqual(
4549+
tbl[['MSRP', 'Invoice']].plot.density(),
4550+
df[['MSRP', 'Invoice']].plot.density()
4551+
)
4552+
4553+
except ImportError as msg:
4554+
tm.TestCase.skipTest(self, '%s' % msg)
45184555

45194556
def test_plot_hexbin(self):
45204557
tbl = self.table
45214558
df = self.get_cars_df()
45224559

4523-
self.assertPlotsEqual(
4524-
tbl.plot.hexbin('MSRP', 'Horsepower'),
4525-
df.plot.hexbin('MSRP', 'Horsepower')
4526-
)
4560+
try:
4561+
self.assertPlotsEqual(
4562+
tbl.plot.hexbin('MSRP', 'Horsepower'),
4563+
df.plot.hexbin('MSRP', 'Horsepower')
4564+
)
4565+
4566+
except ImportError as msg:
4567+
tm.TestCase.skipTest(self, '%s' % msg)
45274568

45284569
def test_plot_hist(self):
45294570
tbl = self.table
45304571
df = self.get_cars_df()
45314572

4532-
self.assertPlotsEqual(
4533-
tbl.plot.hist(),
4534-
df.plot.hist(),
4535-
)
4573+
try:
4574+
self.assertPlotsEqual(
4575+
tbl.plot.hist(),
4576+
df.plot.hist(),
4577+
)
4578+
4579+
except ImportError as msg:
4580+
tm.TestCase.skipTest(self, '%s' % msg)
45364581

45374582
def test_plot_kde(self):
45384583
tbl = self.table
45394584
df = self.get_cars_df()
45404585

4541-
self.assertPlotsEqual(
4542-
tbl[['MSRP', 'Invoice']].plot.kde(),
4543-
df[['MSRP', 'Invoice']].plot.kde()
4544-
)
4586+
try:
4587+
self.assertPlotsEqual(
4588+
tbl[['MSRP', 'Invoice']].plot.kde(),
4589+
df[['MSRP', 'Invoice']].plot.kde()
4590+
)
4591+
4592+
except ImportError as msg:
4593+
tm.TestCase.skipTest(self, '%s' % msg)
45454594

45464595
def test_plot_line(self):
45474596
tbl = self.table
45484597
df = self.get_cars_df()
45494598

4550-
self.assertPlotsEqual(
4551-
tbl.sort_values(['MSRP', 'Invoice']).plot.line('MSRP', 'Invoice'),
4552-
df.sort_values(['MSRP', 'Invoice']).plot.line('MSRP', 'Invoice')
4553-
)
4599+
try:
4600+
self.assertPlotsEqual(
4601+
tbl.sort_values(['MSRP', 'Invoice']).plot.line('MSRP', 'Invoice'),
4602+
df.sort_values(['MSRP', 'Invoice']).plot.line('MSRP', 'Invoice')
4603+
)
4604+
4605+
except ImportError as msg:
4606+
tm.TestCase.skipTest(self, '%s' % msg)
45544607

45554608
def test_plot_pie(self):
45564609
tbl = self.table
45574610
df = self.get_cars_df()
45584611

4559-
self.assertPlotsEqual(
4560-
tbl['Cylinders'].sort_values().plot.pie(),
4561-
df['Cylinders'].sort_values().plot.pie()
4562-
)
4612+
try:
4613+
self.assertPlotsEqual(
4614+
tbl['Cylinders'].sort_values().plot.pie(),
4615+
df['Cylinders'].sort_values().plot.pie()
4616+
)
4617+
4618+
except ImportError as msg:
4619+
tm.TestCase.skipTest(self, '%s' % msg)
45634620

45644621
def test_plot_scatter(self):
45654622
tbl = self.table
45664623
df = self.get_cars_df()
45674624

4568-
self.assertPlotsEqual(
4569-
tbl.plot.scatter('MSRP', 'Horsepower'),
4570-
df.plot.scatter('MSRP', 'Horsepower')
4571-
)
4625+
try:
4626+
self.assertPlotsEqual(
4627+
tbl.plot.scatter('MSRP', 'Horsepower'),
4628+
df.plot.scatter('MSRP', 'Horsepower')
4629+
)
4630+
4631+
except ImportError as msg:
4632+
tm.TestCase.skipTest(self, '%s' % msg)
45724633

45734634
def test_eval(self):
45744635
tbl = self.table

0 commit comments

Comments
 (0)