Ejemplo n.º 1
0
 def test_no_match_with_default(self):
     choice = Choice([('redhat 7.0', 'fred'), ('SuSe 2012', 'star'),
                      'match'])
     match = choice.choose(self.what_to_match)
     self.assertEqual(match, 'match')
Ejemplo n.º 2
0
 def test_match_single_string(self):
     choice = Choice('fred')
     match = choice.choose(self.what_to_match)
     self.assertEqual(match, 'fred')
Ejemplo n.º 3
0
 def test_no_match(self):
     choice = Choice([('redhat 7.0','fred'), ('SuSe 2012','star')])
     with self.assertRaises(ValueError) as cm:
         match = choice.choose(self.what_to_match)
     self.assertEqual(str(cm.exception), 'Nothing matched')
Ejemplo n.º 4
0
 def test_match_single_string_in_array(self):
     choice = Choice(['fred'])
     match = choice.choose(self.what_to_match)
     self.assertEqual(match, 'fred')
Ejemplo n.º 5
0
 def test_None_alone_in_sequence_is_allowed(self):
     choice = Choice([None])
     match = choice.choose(self.what_to_match)
     self.assertEqual(match, None)
Ejemplo n.º 6
0
 def test_match_second_in_wildcarding(self):
     choice = Choice([('ubuntu 12.11','fred'), ('ubuntu 12.*','star')])
     match = choice.choose(self.what_to_match)
     self.assertEqual(match, 'star')
Ejemplo n.º 7
0
 def test_match_default_in_sequence_with_default(self):
     choice = Choice([('no match', 'first'), 'fred'])
     match = choice.choose(self.what_to_match)
     self.assertEqual(match, 'fred')
Ejemplo n.º 8
0
 def test_match_second_item_in_sequence_with_default(self):
     choice = Choice([('ubuntu 12.11','first'), ('ubuntu 12.10', 'second')])
     match = choice.choose(self.what_to_match)
     self.assertEqual(match, 'second')
Ejemplo n.º 9
0
 def test_None_alone_in_sequence_is_allowed(self):
     choice = Choice([None])
     match = choice.choose(self.what_to_match)
     self.assertEqual(match, None)
Ejemplo n.º 10
0
 def test_choice_cannot_be_None(self):
     with self.assertRaises(GiveUp) as cm:
         choice = Choice(None)
Ejemplo n.º 11
0
 def test_None_can_be_default(self):
     choice = Choice([('no match', 'first'), None])
     match = choice.choose(self.what_to_match)
     self.assertEqual(match, None)
Ejemplo n.º 12
0
 def test_match_second_item_in_sequence_with_default(self):
     choice = Choice([('ubuntu 12.11', 'first'),
                      ('ubuntu 12.10', 'second')])
     match = choice.choose(self.what_to_match)
     self.assertEqual(match, 'second')
Ejemplo n.º 13
0
 def test_match_first_item_in_sequence(self):
     choice = Choice([('ubuntu 12.10', 'first')])
     match = choice.choose(self.what_to_match)
     self.assertEqual(match, 'first')
Ejemplo n.º 14
0
 def test_match_single_string_in_array(self):
     choice = Choice(['fred'])
     match = choice.choose(self.what_to_match)
     self.assertEqual(match, 'fred')
Ejemplo n.º 15
0
 def test_match_second_in_wildcarding(self):
     choice = Choice([('ubuntu 12.11', 'fred'), ('ubuntu 12.*', 'star')])
     match = choice.choose(self.what_to_match)
     self.assertEqual(match, 'star')
Ejemplo n.º 16
0
 def test_match_first_item_in_sequence(self):
     choice = Choice([('ubuntu 12.10','first')])
     match = choice.choose(self.what_to_match)
     self.assertEqual(match, 'first')
Ejemplo n.º 17
0
 def test_match_second_in_more_wildcarding(self):
     choice = Choice([('ubuntu 12.2?', 'fred'), ('ubuntu 12.1?', 'query')])
     match = choice.choose(self.what_to_match)
     self.assertEqual(match, 'query')
Ejemplo n.º 18
0
 def test_None_can_be_default(self):
     choice = Choice([('no match','first'), None])
     match = choice.choose(self.what_to_match)
     self.assertEqual(match, None)
Ejemplo n.º 19
0
 def test_two_strings(self):
     with self.assertRaises(GiveUp) as cm:
         choice = Choice(['fred', 'fred'])
Ejemplo n.º 20
0
 def test_match_default_in_sequence_with_default(self):
     choice = Choice([('no match','first'), 'fred'])
     match = choice.choose(self.what_to_match)
     self.assertEqual(match, 'fred')
Ejemplo n.º 21
0
 def test_middle_string(self):
     with self.assertRaises(GiveUp) as cm:
         choice = Choice([('ubuntu 12.10', 'fred'), 'fred',
                          ('ubuntu 12.*', 'star')])
Ejemplo n.º 22
0
 def test_match_second_in_more_wildcarding(self):
     choice = Choice([('ubuntu 12.2?','fred'), ('ubuntu 12.1?','query')])
     match = choice.choose(self.what_to_match)
     self.assertEqual(match, 'query')
Ejemplo n.º 23
0
 def test_no_match(self):
     choice = Choice([('redhat 7.0', 'fred'), ('SuSe 2012', 'star')])
     with self.assertRaises(ValueError) as cm:
         match = choice.choose(self.what_to_match)
     self.assertEqual(str(cm.exception), 'Nothing matched')
Ejemplo n.º 24
0
 def test_no_match_with_default(self):
     choice = Choice([('redhat 7.0','fred'), ('SuSe 2012','star'), 'match'])
     match = choice.choose(self.what_to_match)
     self.assertEqual(match, 'match')
Ejemplo n.º 25
0
 def test_match_single_string(self):
     choice = Choice('fred')
     match = choice.choose(self.what_to_match)
     self.assertEqual(match, 'fred')