class ProteinSetSelectorTests(ProteinSetSelectorBaseTests): def setUp(self): self.mols = Read('Data/stringSel.pdb') self.mol = self.mols[0] self.stringSel = ProteinSetSelector() def tearDown(self): """ clean-up """ del(self.mol) def test_select_with_empty_string(self): """ test result with empty string returns all mols """ result, msg = self.stringSel.select(self.mols, "") self.assertEquals(result, self.mols) def test_select_end(self): """ test select with '$' returns last item """ new_mols = Read("Data/1crn.pdb") self.mols +=new_mols result, msg = self.stringSel.select(self.mols, "$") self.assertEquals(result[-1], self.mols[-1]) def test_select_with_valid_index(self): """ test string with valid_index returns set with 1 item """ selString = "0" #selString = "1" result, msg = self.stringSel.select(self.mols, selString) self.assertEquals(len(result), 1) def test_select_with_invalid_index_returns_empty_set(self): """ test string with invalid_index returns empty set """ selString = "2" result, msg = self.stringSel.select(self.mols, selString) self.assertEqual(result.__class__, self.mols.__class__) self.assertEqual(len(result), 0) self.assertEqual(msg[0], selString) def test_select_with_valid_range(self): """ test string with valid_range returns set with 2 items """ new_mols = Read("Data/1crn.pdb") self.mols +=new_mols selString = "0-1" #selString = "1-2" result, msg = self.stringSel.select(self.mols, selString) self.assertEquals(len(result), 2) def test_select_with_invalid_range(self): """ test string with invalid_range returns set with 0 items """ new_mols = Read("Data/1crn.pdb") self.mols +=new_mols selString = "4-6" result, msg = self.stringSel.select(self.mols, selString) self.assertEquals(len(result), 0) def test_select_with_valid_regex(self): """ test string with valid_regex returns set with 1 items <this regex is intended to match 1, 2,or 3 followed by anything> """ new_mols = Read("Data/1crn.pdb") self.mols +=new_mols selString = "[1-3]*" result, msg = self.stringSel.select(self.mols, selString) #print "result=", result self.assertEquals(len(result), 1) def test_select_with_valid_regex_2(self): """ test string with valid_regex returns set with 1 items <this regex is intended to match anything in range s-z followed by anything> """ new_mols = Read("Data/1crn.pdb") self.mols +=new_mols selString = "[s-z]*" result, msg = self.stringSel.select(self.mols, selString) #print "result=", result self.assertEquals(len(result), 1) def test_select_valid_set(self): """ test string with valid set name returns 1 set """ new_mols = Read("Data/1crn.pdb") self.mols +=new_mols these_sets = Sets() key = 'first' these_sets.add(key, self.mols[1:]) selString = key result, msg = self.stringSel.select(self.mols, selString, sets=these_sets) #print "result=", result self.assertEquals(len(result), 1) self.assertEquals(result, self.mols[1:])
def setUp(self): self.mols = Read('Data/stringSel.pdb') self.mol = self.mols[0] self.stringSel = ProteinSetSelector()
def test_constructor(self): """ instantiate an ProteinSetSelector """ stringSel = ProteinSetSelector() self.assertEquals(stringSel.__class__, ProteinSetSelector)