@@ -203,6 +203,15 @@ def test_init_multiple_wildtypes(self):
203
203
r'Multiple wildtypes found: Q, R\.' ):
204
204
MutationSet (mutations = mutations )
205
205
206
+ def test_init_bad_text (self ):
207
+ expected_message = \
208
+ r'MutationSet text expects wild type \(optional\), position, and ' \
209
+ r'zero or more variants\.'
210
+ for bad_text in ('!20A' , '20Ac' , 'r20Q' ):
211
+ with self .subTest (bad_text ):
212
+ with self .assertRaisesRegex (ValueError , expected_message ):
213
+ MutationSet (bad_text )
214
+
206
215
def test_repr (self ):
207
216
expected_repr = "MutationSet('Q1AC')"
208
217
ms = MutationSet ('Q1AC' )
@@ -263,6 +272,19 @@ def test_immutable(self):
263
272
with self .assertRaises (AttributeError ):
264
273
ms .wildtype = 'D'
265
274
275
+ def test_length (self ):
276
+ self .assertEqual (0 , len (MutationSet ('A10' )))
277
+ self .assertEqual (1 , len (MutationSet ('A10I' )))
278
+ self .assertEqual (2 , len (MutationSet ('A10IL' )))
279
+
280
+ def test_in (self ):
281
+ ms = MutationSet ('A10IL' )
282
+
283
+ self .assertIn (Mutation ('A10I' ), ms )
284
+ self .assertIn (Mutation ('A10L' ), ms )
285
+ self .assertIn (Mutation ('10L' ), ms )
286
+ self .assertNotIn (Mutation ('A10S' ), ms )
287
+
266
288
267
289
class TestVariantCalls (unittest .TestCase ):
268
290
def test_init_text (self ):
@@ -300,6 +322,11 @@ def test_init_bad_length(self):
300
322
ValueError , r'Reference length was 4 and sample length was 5\.' ):
301
323
VariantCalls (reference = reference , sample = sample )
302
324
325
+ def test_init_with_duplicate_positions (self ):
326
+ with self .assertRaisesRegex (
327
+ ValueError , r'Multiple mutation sets at position 10\.' ):
328
+ VariantCalls ('H10R A1IN H10C' )
329
+
303
330
def test_init_with_reference (self ):
304
331
expected_reference = 'ASH'
305
332
expected_repr = "VariantCalls('A1IL H3R')"
@@ -362,6 +389,11 @@ def test_in(self):
362
389
self .assertIn (mutation_set1 , calls )
363
390
self .assertNotIn (mutation_set2 , calls )
364
391
392
+ def test_length (self ):
393
+ self .assertEqual (0 , len (VariantCalls ('' )))
394
+ self .assertEqual (1 , len (VariantCalls ('A10IL' )))
395
+ self .assertEqual (2 , len (VariantCalls ('A10IL H3R' )))
396
+
365
397
def test_immutable (self ):
366
398
calls = VariantCalls ('A1IL H3R' )
367
399
0 commit comments