Changeset 14939 for main/waeup.kofa/trunk/src/waeup/kofa/utils
- Timestamp:
- 18 Jan 2018, 07:34:42 (7 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/utils
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/utils/helpers.py
r13537 r14939 756 756 757 757 def check_csv_charset(iterable): 758 """Check contents of `iterable` regarding valid CSV encoding. 758 """Check contents of `iterable` regarding valid CSV encoding and 759 trailing whitespaces in data. 759 760 760 761 `iterable` is expected to be an iterable on _rows_ (not … … 764 765 765 766 Returns line num of first illegal char or ``None``. Line nums 766 start counting with 1 (not zero). 767 start counting with 1 (not zero). Returns -1 if data contain 768 trailing whitespaces. 767 769 """ 768 770 linenum = 1 … … 771 773 for row in reader: 772 774 linenum += 1 775 for value in row.values(): 776 if value.endswith(' '): 777 return -1 773 778 except UnicodeDecodeError: 774 779 return linenum -
main/waeup.kofa/trunk/src/waeup/kofa/utils/tests/test_helpers.py
r12433 r14939 537 537 self.assertEqual(helpers.check_csv_charset(csv), 2) 538 538 539 540 def test_invalid_data3(self): 541 csv = ( 542 "code,title,title_prefix\n" 543 "FAC1,Faculty 1,faculty\n" 544 "FAC2,Faculty 2 ,institute\n" 545 "FAC3,Fäcülty 3,school\n" 546 ).splitlines() 547 self.assertEqual(helpers.check_csv_charset(csv), -1) 539 548 540 549 class MemInfoTestCase(unittest.TestCase):
Note: See TracChangeset for help on using the changeset viewer.