class TestGetColumnNames(unittest.TestCase): """ Tests for get_column_names() method in DeveloperStats class """ def setUp(self): """ Define attribute dev_stats to hold object of type DeveloperStats """ self.dev_stats = DeveloperStats() def test_for_empty_header(self): """ Test case for testing empty csv file header or empty csv file """ file_input = 'getColumnNames1.csv' actual_result = self.dev_stats.get_column_names(file_input) expected_result = [''] self.assertEqual(actual_result, expected_result) def test_for_three_columns(self): """ Test case for a csv file header with 3 columns """ file_input = 'getColumnNames2.csv' actual_result = self.dev_stats.get_column_names(file_input) expected_result = ['Respondent', 'Country', 'JobSatisfaction'] self.assertEqual(actual_result, expected_result) def test_for_all_columns(self): """ Test case for a csv file header columns """ file_input = 'stats.csv' actual_result = self.dev_stats.get_column_names(file_input) expected_result = [ 'Respondent', 'Country', 'JobSatisfaction', 'UndergradMajor', 'ConvertedSalary', 'Exercise', 'Gender', 'RaceEthnicity', 'EducationParents', 'HoursOutside', 'Age', 'LastNewJob', 'LanguageWorkedWith' ] self.assertEqual(actual_result, expected_result)
def setUp(self): """ Define attribute dev_stats to hold object of type DeveloperStats """ self.dev_stats = DeveloperStats()
class TestCountData(unittest.TestCase): """ Tests for count_data() method in DeveloperStats class """ def setUp(self): """ Define attribute dev_stats to hold object of type DeveloperStats """ self.dev_stats = DeveloperStats() def test_for_empty_file(self): """ Test case for testing empty csv """ file_input = self.dev_stats.categorize_data('getColumnNames1.csv') actual_result = self.dev_stats.count_data(file_input) expected_result = { 'low_salary': { 'count': 0, 'min': 0, 'max': 50000, 'data': {} }, 'medium_salary': { 'count': 0, 'min': 50001, 'max': 80000, 'data': {} }, 'high_salary': { 'count': 0, 'min': 80001, 'max': 200000, 'data': {} } } self.assertDictEqual(actual_result, expected_result) def test_for_three_entries(self): """ Test case for three entries in csv file """ file_input = self.dev_stats.categorize_data('categorizeData1.csv') actual_result = self.dev_stats.count_data(file_input) expected_result = { 'low_salary': { 'count': 1, 'min': 0, 'max': 50000, 'data': { 'C#': 1, 'CoffeeScript': 1, 'JavaScript': 1, 'Ruby': 1, 'HTML': 1, 'CSS': 1, 'Bash/Shell': 1, 'Argentina': 1, 'Slightly satisfied': 1, 'A business discipline (ex. accounting, finance,' + ' marketing)': 1, '1 - 2 times per week': 1, 'Secondary school (e.g. American high school,' + ' German Realschule or Gymnasium, etc.)': 1, '1 - 2 hours': 1, 'More than 4 years ago': 1 } }, 'medium_salary': { 'count': 0, 'min': 50001, 'max': 80000, 'data': {} }, 'high_salary': { 'count': 2, 'min': 80001, 'max': 200000, 'data': { 'C': 1, 'C#': 2, 'Java': 1, 'JavaScript': 2, 'Objective-C': 1, 'PHP': 1, 'Swift': 1, 'HTML': 2, 'CSS': 1, 'United Kingdom': 1, 'Moderately satisfied': 1, 'Computer science, computer engineering, or software ' + 'engineering': 1, '3 - 4 times per week': 2, 'Master’s degree (MA, MS, M.Eng., MBA, etc.)': 1, '3 - 4 hours': 1, 'Between 1 and 2 years ago': 1, 'Python': 1, 'TypeScript': 1, 'Bash/Shell': 1, 'Germany': 1, 'Slightly dissatisfied': 1, 'A social science (ex. anthropology, psychology, ' + 'political science)': 1, 'Secondary school (e.g. American high school, German ' + 'Realschule or Gymnasium, etc.)': 1, '1 - 2 hours': 1, 'Between 2 and 4 years ago': 1 } } } self.assertDictEqual(actual_result, expected_result) def test_for_ten_entries(self): """ Test case for three entries in csv file """ file_input = self.dev_stats.categorize_data('categorizeData2.csv') actual_result = self.dev_stats.count_data(file_input) expected_result = { 'low_salary': { 'count': 2, 'min': 0, 'max': 50000, 'data': { 'C#': 1, 'CoffeeScript': 1, 'JavaScript': 2, 'Ruby': 1, 'HTML': 2, 'CSS': 2, 'Bash/Shell': 1, 'Argentina': 1, 'Slightly satisfied': 1, 'A business discipline (ex. accounting, finance, ' + 'marketing)': 1, '1 - 2 times per week': 1, 'Secondary school (e.g. American high school,' + ' German Realschule or Gymnasium, etc.)': 1, '1 - 2 hours': 2, 'More than 4 years ago': 1, 'PHP': 1, 'Python': 1, 'SQL': 1, 'TypeScript': 1, 'Brazil': 1, 'Moderately dissatisfied': 1, 'Computer science, computer engineering, or software ' + 'engineering': 1, '3 - 4 times per week': 1, 'Primary/elementary school': 1, 'Less than a year ago': 1 } }, 'medium_salary': { 'count': 2, 'min': 50001, 'max': 80000, 'data': { 'JavaScript': 2, 'PHP': 1, 'Japan': 1, 'Slightly dissatisfied': 1, 'Information systems, information technology, or system ' + 'administration': 1, '3 - 4 times per week': 1, 'They never completed any formal education': 1, '30 - 59 minutes': 1, 'Between 2 and 4 years ago': 1, 'Groovy': 1, 'Java': 1, 'SQL': 1, 'HTML': 1, 'CSS': 1, 'Bash/Shell': 1, 'Germany': 1, 'Moderately dissatisfied': 1, 'Computer science, computer engineering, or software ' + 'engineering': 1, "I don't typically exercise": 1, 'Secondary school (e.g. American high school,' + ' German Realschule or Gymnasium, etc.)': 1, '1 - 2 hours': 1, 'Less than a year ago': 1 } }, 'high_salary': { 'count': 5, 'min': 80001, 'max': 200000, 'data': { 'C': 1, 'C#': 3, 'Java': 2, 'JavaScript': 4, 'Objective-C': 1, 'PHP': 1, 'Swift': 1, 'HTML': 3, 'CSS': 2, 'United Kingdom': 2, 'Moderately satisfied': 2, 'Computer science, computer engineering, or software ' + 'engineering': 2, '3 - 4 times per week': 2, 'Master’s degree (MA, MS, M.Eng., MBA, etc.)': 3, '3 - 4 hours': 1, 'Between 1 and 2 years ago': 2, 'Python': 3, 'TypeScript': 1, 'Bash/Shell': 1, 'Germany': 1, 'Slightly dissatisfied': 1, 'A social science (ex. anthropology, psychology, ' + 'political science)': 2, 'Secondary school (e.g. American high school,' + ' German Realschule or Gymnasium, etc.)': 1, '1 - 2 hours': 1, 'Between 2 and 4 years ago': 1, 'United States': 1, 'Moderately dissatisfied': 1, '1 - 2 times per week': 2, 'Bachelor’s degree (BA, BS, B.Eng., etc.)': 1, 'Less than 30 minutes': 1, 'Go': 1, 'Ruby': 1, 'Extremely satisfied': 1, 'A humanities discipline (ex. literature, history, ' + 'philosophy)': 1, "I don't typically exercise": 1, '30 - 59 minutes': 2, 'Less than a year ago': 2, 'SQL': 1, 'Netherlands': 1 } } } self.assertDictEqual(actual_result, expected_result)
class TestTopFive(unittest.TestCase): """ Tests for top_five() method in DeveloperStats class """ def setUp(self): """ Define attribute dev_stats to hold object of type DeveloperStats """ self.dev_stats = DeveloperStats() def test_for_empty_file(self): """ Test case for testing empty csv file header or empty csv file """ file_input = 'getColumnNames1.csv' actual_result = self.dev_stats.top_five( self.dev_stats.count_data( self.dev_stats.categorize_data(file_input))) expected_result = { 'low_salary': { 'count': 0, 'min': 0, 'max': 50000, 'data': {} }, 'medium_salary': { 'count': 0, 'min': 50001, 'max': 80000, 'data': {} }, 'high_salary': { 'count': 0, 'min': 80001, 'max': 200000, 'data': {} } } self.assertDictEqual(actual_result, expected_result) def test_for_nine_entries(self): """ Test case for a csv file with 9 entries """ file_input = 'categorizeData2.csv' actual_result = self.dev_stats.top_five( self.dev_stats.count_data( self.dev_stats.categorize_data(file_input))) expected_result = { 'low_salary': { 'count': 2, 'min': 0, 'max': 50000, 'data': { 'TypeScript': 1, '1 - 2 hours': 2, 'JavaScript': 2, 'HTML': 2, 'CSS': 2 } }, 'medium_salary': { 'count': 2, 'min': 50001, 'max': 80000, 'data': { 'SQL': 1, 'HTML': 1, 'CSS': 1, 'Bash/Shell': 1, 'JavaScript': 2 } }, 'high_salary': { 'count': 5, 'min': 80001, 'max': 200000, 'data': { 'Master’s degree (MA, MS, M.Eng., MBA, etc.)': 3, 'C#': 3, 'HTML': 3, 'Python': 3, 'JavaScript': 4 } } } self.assertEqual(actual_result, expected_result) def test_for_all_entries(self): """ Test case for csv with all the stats """ file_input = 'stats.csv' actual_result = self.dev_stats.top_five( self.dev_stats.count_data( self.dev_stats.categorize_data(file_input))) expected_result = { 'low_salary': { 'count': 826, 'min': 0, 'max': 50000, 'data': { 'SQL': 463, 'Computer science, computer' + ' engineering, or software engineering': 539, 'CSS': 558, 'HTML': 584, 'JavaScript': 600 } }, 'medium_salary': { 'count': 507, 'min': 50001, 'max': 80000, 'data': { 'SQL': 297, 'Computer science, computer engineering,' + ' or software engineering': 312, 'CSS': 331, 'HTML': 347, 'JavaScript': 364 } }, 'high_salary': { 'count': 667, 'min': 80001, 'max': 200000, 'data': { 'United States': 406, 'Computer science, computer' + ' engineering, or software engineering': 409, 'CSS': 413, 'HTML': 448, 'JavaScript': 504 } } } self.assertEqual(actual_result, expected_result)
class TestCategorizeData(unittest.TestCase): """ Tests for categorize_data() method in DeveloperStats class """ def setUp(self): """ Define attribute dev_stats to hold object of type DeveloperStats """ self.dev_stats = DeveloperStats() def test_for_empty_file(self): """ Test case for testing empty csv """ file_file_input = 'getColumnNames1.csv' actual_result = self.dev_stats.categorize_data(file_file_input) expected_result = { 'low_salary': { 'min': 0, 'max': 50000, 'data': [] }, 'medium_salary': { 'min': 50001, 'max': 80000, 'data': [] }, 'high_salary': { 'min': 80001, 'max': 200000, 'data': [] } } self.assertDictEqual(actual_result, expected_result) def test_for_three_entries(self): """ Test case for three entries in csv file """ file_input = 'categorizeData1.csv' actual_result = self.dev_stats.categorize_data(file_input) expected_result = { 'low_salary': { 'min': 0, 'max': 50000, 'data': [[ '95836', 'Argentina', 'Slightly satisfied', 'A business discipline (ex. accounting, finance,' + ' marketing)', '45600.0', '1 - 2 times per week', 'Male', 'Hispanic or Latino/Latina', 'Secondary school (e.g. American high school,' + ' German Realschule or Gymnasium, etc.)', '1 - 2 hours', '35 - 44 years old', 'More than 4 years ago', 'C#;CoffeeScript;JavaScript;Ruby;HTML;CSS;Bash/Shell' ]] }, 'medium_salary': { 'min': 50001, 'max': 80000, 'data': [] }, 'high_salary': { 'min': 80001, 'max': 200000, 'data': [[ '51900', 'United Kingdom', 'Moderately satisfied', 'Computer science, computer engineering, or software' + ' engineering', '94455.0', '3 - 4 times per week', 'Male', 'White or of European descent', 'Master’s degree (MA, MS, M.Eng., MBA, etc.)', '3 - 4 hours', '35 - 44 years old', 'Between 1 and 2 years ago', 'C;C#;Java;JavaScript;Objective-C;PHP;Swift;HTML;CSS' ], [ '51710', 'Germany', 'Slightly dissatisfied', 'A social science (ex. anthropology, psychology,' + ' political science)', '807756.0', '3 - 4 times per week', 'Male', 'White or of European descent', 'Secondary school (e.g. American high school,' + ' German Realschule or Gymnasium, etc.)', '1 - 2 hours', '25 - 34 years old', 'Between 2 and 4 years ago', 'C#;JavaScript;Python;TypeScript;HTML;Bash/Shell' ]] } } self.assertDictEqual(actual_result, expected_result) def test_for_ten_entries(self): """ Test case for three entries in csv file """ file_input = 'categorizeData2.csv' actual_result = self.dev_stats.categorize_data(file_input) expected_result = { 'low_salary': { 'min': 0, 'max': 50000, 'data': [[ '95836', 'Argentina', 'Slightly satisfied', 'A business discipline (ex. accounting, finance,' + ' marketing)', '45600.0', '1 - 2 times per week', 'Male', 'Hispanic or Latino/Latina', 'Secondary school (e.g. American high school,' + ' German Realschule or Gymnasium, etc.)', '1 - 2 hours', '35 - 44 years old', 'More than 4 years ago', 'C#;CoffeeScript;JavaScript;Ruby;HTML;CSS;Bash/Shell' ], [ '36729', 'Brazil', 'Moderately dissatisfied', 'Computer science, computer engineering, or software' + ' engineering', '16848.0', '3 - 4 times per week', 'Male', 'Hispanic or Latino/Latina', 'Primary/elementary school', '1 - 2 hours', '25 - 34 years old', 'Less than a year ago', 'JavaScript;PHP;Python;SQL;TypeScript;HTML;CSS' ]] }, 'medium_salary': { 'min': 50001, 'max': 80000, 'data': [[ '31721', 'Japan', 'Slightly dissatisfied', 'Information systems, information technology, or' + ' system administration', '77433.0', '3 - 4 times per week', 'Male', 'East Asian', 'They never completed any formal education', '30 - 59 minutes', '35 - 44 years old', 'Between 2 and 4 years ago', 'JavaScript;PHP' ], [ '38620', 'Germany', 'Moderately dissatisfied', 'Computer science, computer engineering, or software' + ' engineering', '73433.0', "I don't typically exercise", 'Female', 'White or of European descent', 'Secondary school (e.g. American high school,' + ' German Realschule or Gymnasium, etc.)', '1 - 2 hours', '35 - 44 years old', 'Less than a year ago', 'Groovy;Java;JavaScript;SQL;HTML;CSS;Bash/Shell' ]] }, 'high_salary': { 'min': 80001, 'max': 200000, 'data': [ [ '51900', 'United Kingdom', 'Moderately satisfied', 'Computer science, computer engineering, or software' + ' engineering', '94455.0', '3 - 4 times per week', 'Male', 'White or of European descent', 'Master’s degree (MA, MS, M.Eng., MBA, etc.)', '3 - 4 hours', '35 - 44 years old', 'Between 1 and 2 years ago', 'C;C#;Java;JavaScript;Objective-C;PHP;Swift;HTML;CSS' ], [ '51710', 'Germany', 'Slightly dissatisfied', 'A social science (ex. anthropology, psychology,' + ' political science)', '807756.0', '3 - 4 times per week', 'Male', 'White or of European descent', 'Secondary school (e.g. American high school,' + ' German Realschule or Gymnasium, etc.)', '1 - 2 hours', '25 - 34 years old', 'Between 2 and 4 years ago', 'C#;JavaScript;Python;TypeScript;HTML;Bash/Shell' ], [ '44125', 'United States', 'Moderately dissatisfied', 'A social science (ex. anthropology, psychology,' + ' political science)', '175000.0', '1 - 2 times per week', 'Male', 'White or of European descent', 'Bachelor’s degree (BA, BS, B.Eng., etc.)', 'Less than 30 minutes', '45 - 54 years old', 'Between 1 and 2 years ago', 'JavaScript;Python' ], [ '35167', 'United Kingdom', 'Extremely satisfied', 'A humanities discipline (ex. literature, history,' + ' philosophy)', '90288.0', "I don't typically exercise", 'Male', 'White or of European descent', 'Master’s degree (MA, MS, M.Eng., MBA, etc.)', '30 - 59 minutes', '25 - 34 years old', 'Less than a year ago', 'C#;Go;JavaScript;Ruby;HTML;CSS' ], [ '54695', 'Netherlands', 'Moderately satisfied', 'Computer science, computer engineering, or software' + ' engineering', '82000.0', '1 - 2 times per week', 'Male', 'White or of European descent', 'Master’s degree (MA, MS, M.Eng., MBA, etc.)', '30 - 59 minutes', '25 - 34 years old', 'Less than a year ago', 'Java;Python;SQL' ] ] } } self.assertDictEqual(actual_result, expected_result)