-
Notifications
You must be signed in to change notification settings - Fork 140
Expand file tree
/
Copy pathbinary_length.py
More file actions
31 lines (21 loc) · 861 Bytes
/
binary_length.py
File metadata and controls
31 lines (21 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
from unittest import TestCase
class BinaryLengthExtractor(object):
# Example of Python-based binary_types.
@classmethod
def create(cls, param):
return cls()
def extract(self, key, value):
"""
Returns the length of the given binary data.
The key is typed as ``str`` (unicode).
The value is typed as ``bytes``.
This method should return list of key-values (pair of feature key
as ``str`` and its value as number).
"""
return [("length_{0}".format(key), len(value))]
class BinaryLengthExtractorTest(TestCase):
def test_extract(self):
ex = BinaryLengthExtractor.create({})
self.assertEqual([('length_v', 9)], ex.extract('v', b'XXXX-XXXX'))