Ejemplo n.º 1
0
 def test_round_trip(self):
     choices = {
         factory.make_name("name"): factory.make_bytes() for _ in range(10)
     }
     argument = arguments.Choice(choices)
     choice = random.choice(list(choices))
     encoded = argument.toString(choice)
     self.assertThat(encoded, IsInstance(bytes))
     decoded = argument.fromString(encoded)
     self.assertThat(decoded, Equals(choice))
Ejemplo n.º 2
0
 def test_error_when_choices_values_are_not_byte_strings(self):
     with ExpectedException(TypeError, "^Not byte strings: 'foo', 12345"):
         arguments.Choice({object(): 12345, object(): "foo"})
Ejemplo n.º 3
0
 def test_error_when_choices_is_not_mapping(self):
     with ExpectedException(TypeError, r"^Not a mapping: \[\]"):
         arguments.Choice([])
Ejemplo n.º 4
0
 def test_error_when_input_is_not_in_choices(self):
     with ExpectedException(KeyError, "^<object .*"):
         arguments.Choice({}).toString(object())