def test_unknown_frag_library(self): """ case where unknown fragment library is specified """ with self.assertRaisesRegex(InvalidCrystalsCSV, r"^Unknown fragment library 'Wat'."): parse_crystals_csv(BytesIO(UNKNOWN_FRAG_LIBRARY))
def test_unknown_frag_code(self): """ case where unknown fragment code is specified """ with self.assertRaisesRegex(InvalidCrystalsCSV, r"^No fragment BT01 in 'MyLib' library."): parse_crystals_csv(BytesIO(UNKNOW_FRAG_CODE))
def test_empty_sample_id(self): """ one of the crystals have an empty SampleID specified """ with self.assertRaisesRegex(InvalidCrystalsCSV, r"Empty SampleID specified\."): parse_crystals_csv(BytesIO(EMPTY_SAMPLE_ID))
def test_unexpected_column(self): """ unexpected column in the CSV """ with self.assertRaisesRegex(InvalidCrystalsCSV, r"^Unexpected column: Suprise\."): parse_crystals_csv(BytesIO(UNEXPECTED_COLUMN))
def test_missing_frag_code(self): """ case where fragment library is specified, by there is no fragment code """ with self.assertRaisesRegex( InvalidCrystalsCSV, r"^No fragment code specified for 'Cry2' crystal."): parse_crystals_csv(BytesIO(MISSING_FRAG_CODE))
def test_missing_frag_library(self): """ case where fragment code is present, but no library is specified """ with self.assertRaisesRegex( InvalidCrystalsCSV, r"^No fragment library specified for 'Cry2' crystal."): parse_crystals_csv(BytesIO(MISSING_FRAG_LIBRARY))
def test_ok(self): crystals = parse_crystals_csv(BytesIO(VALID_CSV)) self.assertListEqual( crystals.as_list(), [ { "SampleID": "MID2-x0017", "FragmentLibrary": "FragMAXlib", "FragmentCode": "VT00249", }, { "SampleID": "MID2-x0018", "FragmentLibrary": "FragMAXlib", "FragmentCode": "VT00249", }, { "SampleID": "MID2-x0019", "FragmentLibrary": None, "FragmentCode": None, }, ], )
def test_missing_required_cols(self): """ required columns are missing """ with self.assertRaisesRegex(InvalidCrystalsCSV, "^Missing columns:.*"): parse_crystals_csv(BytesIO(MISSING_REQ_COLUMS))
def test_csv_parse_error(self): """ unparsable CSV case """ with self.assertRaises(InvalidCrystalsCSV): parse_crystals_csv(BytesIO(b'"'))
def clean_crystals_csv_file(self): csv_file = self.cleaned_data["crystals_csv_file"] try: return parse_crystals_csv(csv_file) except InvalidCrystalsCSV as e: raise ValidationError(str(e))