Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
jubatus/plugin/src/fv_converter/python_bridge/python/binary_length.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
31 lines (21 sloc)
861 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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')) |