<s> import unittest <EOL> import json <EOL> from math import sqrt <EOL> import msgpackrpc <EOL> from jubatus . nearest_neighbor . client import NearestNeighbor <EOL> from jubatus . nearest_neighbor . types import * <EOL> from jubatus_test . test_util import TestUtil <EOL> from jubatus . common import Datum <EOL> host = "<STR_LIT:127.0.0.1>" <EOL> port = <NUM_LIT> <EOL> timeout = <NUM_LIT:10> <EOL> class NearestNeighborTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . config = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { } , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : { } , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : { } , <EOL> "<STR_LIT>" : [ { "<STR_LIT:key>" : "<STR_LIT:*>" , "<STR_LIT:type>" : "<STR_LIT:str>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } ] , <EOL> "<STR_LIT>" : { } , <EOL> "<STR_LIT>" : [ { "<STR_LIT:key>" : "<STR_LIT:*>" , "<STR_LIT:type>" : "<STR_LIT>" } ] <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : <NUM_LIT:64> <EOL> } <EOL> } <EOL> TestUtil . write_file ( '<STR_LIT>' , json . dumps ( self . config ) ) <EOL> self . srv = TestUtil . fork_process ( '<STR_LIT>' , port , '<STR_LIT>' ) <EOL> try : <EOL> self . cli = NearestNeighbor ( host , port , "<STR_LIT:name>" ) <EOL> except : <EOL> TestUtil . kill_process ( self . srv ) <EOL> raise <EOL> def tearDown ( self ) : <EOL> if self . cli : <EOL> self . cli . get_client ( ) . close ( ) <EOL> TestUtil . kill_process ( self . srv ) <EOL> def test_get_client ( self ) : <EOL> self . assertTrue ( isinstance ( self . cli . get_client ( ) , msgpackrpc . client . Client ) ) <EOL> def test_get_config ( self ) : <EOL> config = self . cli . get_config ( ) <EOL> self . assertEqual ( json . dumps ( json . loads ( config ) , sort_keys = True ) , json . dumps ( self . config , sort_keys = True ) ) <EOL> def test_neighbor_row ( self ) : <EOL> self . cli . clear ( ) <EOL> d = Datum ( { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : <NUM_LIT:1.0> , "<STR_LIT>" : <NUM_LIT> } ) <EOL> self . cli . set_row ( "<STR_LIT>" , d ) <EOL> d1 = self . cli . neighbor_row_from_id ( "<STR_LIT>" , <NUM_LIT:10> ) <EOL> d2 = self . cli . neighbor_row_from_datum ( d , <NUM_LIT:10> ) <EOL> def test_similar_row ( self ) : <EOL> self . cli . clear ( ) <EOL> d = Datum ( { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : <NUM_LIT:1.0> , "<STR_LIT>" : <NUM_LIT> } ) <EOL> self . cli . set_row ( "<STR_LIT>" , d ) <EOL> s1 = self . cli . similar_row_from_id ( "<STR_LIT>" , <NUM_LIT:10> ) <EOL> s2 = self . cli . similar_row_from_datum ( d , <NUM_LIT:10> ) <EOL> def test_clear ( self ) : <EOL> self . cli . clear ( ) <EOL> def test_save ( self ) : <EOL> self . assertEqual ( len ( self . cli . save ( "<STR_LIT>" ) ) , True ) <EOL> def test_load ( self ) : <EOL> model_name = "<STR_LIT>" <EOL> self . cli . save ( model_name ) <EOL> self . assertTrue ( self . cli . load ( model_name ) ) <EOL> def test_get_status ( self ) : <EOL> self . cli . get_status ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> test_suite = unittest . TestLoader ( ) . loadTestsFromTestCase ( NearestNeighborTest ) <EOL> unittest . TextTestRunner ( ) . run ( test_suite ) </s>
