def test_teams(self): data = read_data() ipl_teams = teams(data) self.assertIsInstance(ipl_teams, list) self.assertTrue('Royal Challengers Bangalore' in ipl_teams) self.assertTrue('Kolkata Knight Riders' in ipl_teams) self.assertTrue(len(ipl_teams) == 2)
def test_BC_runs(self): data= read_data() McCullum_runs = BC_runs(data) self.assertIsInstance(McCullum_runs, int) self.assertTrue(158 == McCullum_runs)
def test_return_instance(self): result = read_data() self.assertIsInstance(result, dict,"The expected instance does not match with the return instance")
def test_deliveries_count(self): data = read_data() nos_of_delivery = deliveries_count(data) self.assertIsInstance(nos_of_delivery, int) self.assertTrue(20 == nos_of_delivery)
def test_extras_runs(self): data = read_data() extras = extras_runs(data) self.assertIsInstance(6, int) self.assertTrue(6 == extras)
def test_first_batsman(self): data = read_data() batsman_name = first_batsman(data) self.assertIsInstance(batsman_name, str) self.assertTrue('SC Ganguly' == batsman_name)
def test_read_data(self): result = read_data() self.assertIsInstance(result, dict)
def test_return_instance(self): result = read_data() self.assertIsInstance( result, dict, "The expected instance does not match with the return instance")
import yaml def read_data(): # import the csv file into variable # You can use this path to access the CSV file: '../data/ipl_match.yaml' # Write your code here fileData = open('./data/ipl_match.yaml', 'r') yamlData = yaml.load(fileData.read()) print(type(yamlData)) data = yamlData print(data) return data read_data() import sys, os sys.path.append(os.path.join(os.path.dirname(os.curdir))) from unittest import TestCase from q01_read_data.build import read_data class TestRead_data(TestCase): def test_return_instance(self): result = read_data() self.assertIsInstance( result, dict, 'The expected instance does not match with the return instance')
def test_bowled_out(self): data = read_data() bowled_out_players = bowled_out(data) self.assertIsInstance(bowled_out_players, list) self.assertSetEqual(set(bowled_out_players), set(['R Dravid', 'V Kohli', 'Z Khan']))