Пример #1
0
 def test_import_grades_new_format_utf8_bom(self):
     inName = 'marking/testfiles/newformat_utf8_bom.csv'
     data_to_return = {}
     with open(inName, 'r') as inp:
         err = _compose_imported_grades(inp, self.students, data_to_return, self.a1)
     self.assertIn('File contains bad UTF-8 data: make sure it has been saved as UTF-8 text.', err)
     self.assertEqual(len(data_to_return), 0)
Пример #2
0
 def test_import_grades_new_format_missing_uid_col(self):
     '''
         Judgement call on the design:  If the import file lacks a field
         named 'Userid', we treat it as an old-format file and get an 
         error on the first line.  This unfortunate outcome is required
         if we are to avoid misinterpreting a short assignment name that
         matches a student id and thereby misinterpreting an old-style
         file as though it were a defective (i.e., no 'Userid' column)
         new-style file.
     '''
     inName = 'marking/testfiles/newformat_missing_uid_col.csv'
     data_to_return = {}
     with open(inName, 'r') as inp:
         err = _compose_imported_grades(inp, self.students, data_to_return,
                                        self.a1)
     self.assertIn(
         'Error found in the file (row 1): Unmatched student number or user-id (Junk1).',
         err)
     self.assertIn(
         'Error found in the file (row 2): Unmatched student number or user-id (w1).',
         err)
     self.assertIn(
         'Error found in the file (row 3): Unmatched student number or user-id (w2).',
         err)
     self.assertEqual(len(data_to_return), 0)
Пример #3
0
 def test_import_grades_new_format_utf8_bom(self):
     inName = 'marking/testfiles/newformat_utf8_bom.csv'
     data_to_return = {}
     with open(inName, 'r') as inp:
         err = _compose_imported_grades(inp, self.students, data_to_return, self.a1)
     self.assertEqual(err,
         'File cannot be encoded as UTF-8 data: make sure it contains legal Unicode characters.')
     self.assertEqual(len(data_to_return), 0)
Пример #4
0
 def test_import_grades_new_format_bad_utf8(self):
     inName = 'marking/testfiles/newformat_bad_utf8.csv'
     data_to_return = {}
     with open(inName, 'r') as inp:
         err = _compose_imported_grades(inp, self.students, data_to_return, self.a1)
     self.assertEqual(err,
         'File cannot be decoded as UTF-8 data: make sure it has been saved as UTF-8 text.')
     self.assertEqual(len(data_to_return), 0)
Пример #5
0
 def test_import_grades_new_format_dup_act_col(self):
     inName = 'marking/testfiles/newformat_dup_act_col.csv'
     data_to_return = {}
     with open(inName, 'r') as inp:
         err = _compose_imported_grades(inp, self.students, data_to_return, self.a1)
     self.assertEqual(err, 'Error in file header line:  Two columns '
         'labelled {0}.'.format(self.a1.short_name))
     self.assertEqual(len(data_to_return), 0)
Пример #6
0
 def test_import_grades_new_format_missing_act_col(self):
     inName = 'marking/testfiles/newformat_missing_act_col.csv'
     data_to_return = {}
     with open(inName, 'r') as inp:
          err = _compose_imported_grades(inp, self.students, data_to_return, self.a1)
     self.assertIn('Error in file header line:  No '
         'column labelled for activity {0}.'.format(self.a1.short_name), err)
     self.assertEqual(len(data_to_return), 0)
Пример #7
0
 def test_import_grades_old_format_l(self):
     inName = 'marking/testfiles/oldformat_noprob_let.csv'
     self.get_test_file(inName)
     data_to_return = {}
     with open(inName, 'r') as inp:
         err = _compose_imported_grades(inp, self.students, data_to_return, self.a1)
     self.assertEqual(err, None)
     self.assertEqual(len(data_to_return), len(self.values))
     self.compare_grade_lists(data_to_return)
Пример #8
0
 def test_import_grades_short_row(self):
     inName = 'marking/testfiles/newformat_shortrow_userid.csv'
     self.get_test_file(inName)
     del self.values[0] # Delete header row
     data_to_return = {}
     with open(inName, 'r') as inp:
          err = _compose_imported_grades(inp, self.students, data_to_return, self.a1)
     self.assertEqual(err, None)
     self.assertEqual(len(data_to_return), len(self.values)-1)
Пример #9
0
    def test_import_grades_old_format_unknown_emplid(self):
        inName = 'marking/testfiles/oldformat_unk_emplid.csv'
        self.get_test_file(inName)
        bad_emplid = [e for e,_ in self.values if int(e) not in self.emplids] [0]
        data_to_return = {}
        with open(inName, 'r') as inp:
	    err = _compose_imported_grades(inp, self.students, data_to_return, self.a1)
        self.assertEqual(err, 'Error found in the file (row 1): Unmatched student number '
            'or user-id ({0}).'. format(bad_emplid))
        self.assertEqual(len(data_to_return), 0)
Пример #10
0
 def test_import_grades_new_format_l(self):
     inName = 'marking/testfiles/newformat_noprob_userid_let.csv'
     self.get_test_file(inName)
     del self.values[0] # Delete header row
     data_to_return = {}
     with open(inName, 'r') as inp:
         err = _compose_imported_grades(inp, self.students, data_to_return, self.a1)
     self.assertEqual(err, [])
     self.assertEqual(len(data_to_return), len(self.values))
     self.compare_grade_lists(data_to_return)
Пример #11
0
 def test_import_grades_new_format_junk_cols(self):
     inName = 'marking/testfiles/newformat_noprob_junk_cols.csv'
     self.get_test_file(inName)
     del self.values[0] # Delete header row
     for i, row in enumerate(self.values):
         self.values[i] = [self.values[i][3], self.values[i][1]]
     data_to_return = {}
     with open(inName, 'r') as inp:
          err = _compose_imported_grades(inp, self.students, data_to_return, self.a1)
     self.assertEqual(err, None)
     self.assertEqual(len(data_to_return), len(self.values))
     self.compare_grade_lists(data_to_return)
Пример #12
0
 def test_import_grades_new_format_missing_values(self):
     ''' OK for students to have no grade assigned. '''
     inName = 'marking/testfiles/newformat_missing_student_grade.csv'
     self.get_test_file(inName)
     del self.values[0] # Delete header row
     for i, row in enumerate(self.values):
         self.values[i] = [self.values[i][6], self.values[i][1]]
     data_to_return = {}
     with open(inName, 'r') as inp:
         err = _compose_imported_grades(inp, self.students, data_to_return, self.a1)
     self.assertEqual(err, None)
     self.assertEqual(len(data_to_return), len(self.values))
     self.compare_grade_lists(data_to_return)
Пример #13
0
 def test_import_grades_new_format_missing_uid_col(self):
     '''
         Judgement call on the design:  If the import file lacks a field
         named 'Userid', we treat it as an old-format file and get an 
         error on the first line.  This unfortunate outcome is required
         if we are to avoid misinterpreting a short assignment name that
         matches a student id and thereby misinterpreting an old-style
         file as though it were a defective (i.e., no 'Userid' column)
         new-style file.
     '''
     inName = 'marking/testfiles/newformat_missing_uid_col.csv'
     data_to_return = {}
     with open(inName, 'r') as inp:
          err = _compose_imported_grades(inp, self.students, data_to_return, self.a1)
     self.assertEqual(err, 'Error found in the file (row 1): Unmatched student number or user-id (Junk1).')
     self.assertEqual(len(data_to_return), 0)