Exemple #1
0
class ExternalFormatTest(unittest.TestCase):
    def callback(self, data):
        return [1,2,3]
    
    def setUp(self):
        from tootwi.formats import ExternalFormat
        self.format = ExternalFormat(self.callback)
    
    def test_creation(self):
        from tootwi.formats import Format
        self.assertIsInstance(self.format, Format)
        self.assertEqual(self.format.extension, None)
    
    def test_decoding_of_none_sample_fails(self):
        from tootwi.errors import FormatValueIsNotStringError
        with self.assertRaises(FormatValueIsNotStringError):
            result = self.format.decode(None)
    
    def test_decoding_of_empty_sample(self):
        result = self.format.decode('')
        self.assertEqual(result, None)
    
    def test_decoding_of_space_sample(self):
        result = self.format.decode(' ')
        self.assertEqual(result, None)
    
    def test_decoding_of_ascii_sample(self):
        result = self.format.decode('our callback ignores all values')
        self.assertEqual(result, [1,2,3])
Exemple #2
0
 def setUp(self):
     from tootwi.formats import ExternalFormat
     self.format = ExternalFormat(self.callback)