Ejemplo n.º 1
0
    def verify_error_message_for_argv(self, argv, expected_error_message):
        with self.assertRaises(SystemExit) as cm:   # capture sys.exit() in the tested class
            with captured_output() as (out, err):
                make_usage_report.main(argv)

        actual_output = out.getvalue()
        self.assertEqual(expected_error_message, actual_output.split("\n", 1)[0])

        self.assertIsNone(cm.exception.code)    # we can verify exception code here
Ejemplo n.º 2
0
    def test_resident_column_is_present(self, mock_aggregate_simulation_data):
        # setup
        output_filename = tempfile.gettempdir() + '/tmp.csv'
        argv = ['make_usage_report.py', '../analysis/sim_data', '-s', self.survey_csv.name, '-g', 'Jonathan Chen', output_filename]

        # test
        make_usage_report.main(argv)

        # verify
        with open(output_filename) as output_file:
            output = csv.DictReader(output_file)
            self.assertTrue('resident' in output.fieldnames)
Ejemplo n.º 3
0
    def test_single_grader(self, mock_aggregate_simulation_data):
        # setup
        output_filename = tempfile.gettempdir() + '/tmp.csv'
        argv = ['make_usage_report.py', '../analysis/sim_data', '-g', 'Jonathan Chen', output_filename]

        # test
        make_usage_report.main(argv)

        # verify
        with open(output_filename) as output_file:
            output = csv.DictReader(output_file)
            self.assertTrue('grade ({})'.format(argv[3]) in output.fieldnames)
            # assert more columns than original + grade column
            self.assertGreater(len(output.fieldnames), len(header) + 1)