<s> import unittest <EOL> import env <EOL> import json <EOL> from os import path <EOL> from noralize_cell import ReturnKeywordAndObject <EOL> class TestCompletions ( unittest . TestCase ) : <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> cls . current_view = path . join ( env . RESOURCES_DIR , '<STR_LIT>' ) <EOL> cls . rf_cell = '<STR_LIT:U+0020>' <EOL> cls . rkao = ReturnKeywordAndObject ( <EOL> cls . current_view , <EOL> cls . rf_cell <EOL> ) <EOL> def test_get_rf_cell ( self ) : <EOL> kw_in_line = '<STR_LIT>' <EOL> line = '<STR_LIT>' . format ( self . rf_cell , kw_in_line ) <EOL> column = len ( line ) <EOL> rf_cell = self . rkao . get_rf_cell ( line , column ) <EOL> self . assertEqual ( rf_cell , kw_in_line ) <EOL> column = <NUM_LIT:5> <EOL> rf_cell = self . rkao . get_rf_cell ( line , column ) <EOL> self . assertEqual ( rf_cell , kw_in_line ) <EOL> column = <NUM_LIT:4> <EOL> rf_cell = self . rkao . get_rf_cell ( line , column ) <EOL> self . assertEqual ( rf_cell , kw_in_line ) <EOL> column = <NUM_LIT:2> <EOL> rf_cell = self . rkao . get_rf_cell ( line , column ) <EOL> self . assertEqual ( rf_cell , None ) <EOL> kw_1_in_line = '<STR_LIT>' <EOL> kw_2_in_line = '<STR_LIT>' <EOL> argument = '<STR_LIT>' <EOL> column = <NUM_LIT:20> <EOL> line = '<STR_LIT>' . format ( <EOL> self . rf_cell , <EOL> kw_1_in_line , <EOL> kw_2_in_line , <EOL> argument <EOL> ) <EOL> rf_cell = self . rkao . get_rf_cell ( line , column ) <EOL> self . assertEqual ( rf_cell , kw_2_in_line ) <EOL> column = <NUM_LIT:7> <EOL> rf_cell = self . rkao . get_rf_cell ( line , column ) <EOL> self . assertEqual ( rf_cell , kw_1_in_line ) <EOL> def test_normalize_kw_only ( self ) : <EOL> kw = '<STR_LIT>' <EOL> line = '<STR_LIT>' . format ( self . rf_cell , kw ) <EOL> column = len ( line ) <EOL> keyword , object_name = self . rkao . normalize ( line , column ) <EOL> self . assertEqual ( keyword , kw ) <EOL> self . assertEqual ( object_name , None ) <EOL> def test_normalize_kw_and_lib ( self ) : <EOL> kw = '<STR_LIT>' <EOL> library = '<STR_LIT>' <EOL> line = '<STR_LIT>' . format ( self . rf_cell , library , kw ) <EOL> column = len ( line ) - <NUM_LIT:1> <EOL> keyword , object_name = self . rkao . normalize ( line , column ) <EOL> self . assertEqual ( object_name , library ) <EOL> self . assertEqual ( keyword , kw ) <EOL> kw = '<STR_LIT>' <EOL> library = '<STR_LIT>' <EOL> line = '<STR_LIT>' . format ( self . rf_cell , library , kw ) <EOL> column = len ( line ) - <NUM_LIT:1> <EOL> keyword , object_name = self . rkao . normalize ( line , column ) <EOL> self . assertEqual ( keyword , kw ) <EOL> self . assertEqual ( object_name , library ) <EOL> def test_normalize_long_lib_and_space_in_kw ( self ) : <EOL> kw = '<STR_LIT>' <EOL> library = '<STR_LIT>' <EOL> line = '<STR_LIT>' . format ( self . rf_cell , library , kw ) <EOL> column = len ( line ) - <NUM_LIT:6> <EOL> keyword , object_name = self . rkao . normalize ( line , column ) <EOL> self . assertEqual ( object_name , library ) <EOL> self . assertEqual ( keyword , kw ) <EOL> def test_separate_keyword_from_object_no_space ( self ) : <EOL> kw = '<STR_LIT>' <EOL> library = '<STR_LIT>' <EOL> cell = '<STR_LIT>' . format ( library , kw ) <EOL> object_name , keyword = self . rkao . separate_keyword_from_object ( cell ) <EOL> self . assertEqual ( object_name , library ) <EOL> self . assertEqual ( keyword , kw ) <EOL> def test_separate_keyword_from_object_space ( self ) : <EOL> kw = '<STR_LIT>' <EOL> library = '<STR_LIT>' <EOL> cell = '<STR_LIT>' . format ( library , kw ) <EOL> object_name , keyword = self . rkao . separate_keyword_from_object ( cell ) <EOL> self . assertEqual ( object_name , library ) <EOL> self . assertEqual ( keyword , kw ) <EOL> def test_separate_keyword_from_object_lib_with_dots ( self ) : <EOL> kw = '<STR_LIT>' <EOL> library = '<STR_LIT>' <EOL> cell = '<STR_LIT>' . format ( library , kw ) <EOL> object_name , keyword = self . rkao . separate_keyword_from_object ( cell ) <EOL> self . assertEqual ( object_name , library ) <EOL> self . assertEqual ( keyword , kw ) <EOL> def test_get_data ( self ) : <EOL> self . rkao . _get_data ( ) <EOL> self . assertTrue ( '<STR_LIT>' in self . rkao . data ) <EOL> @ property <EOL> def add_dolibrary_kw1 ( self ) : <EOL> return [ <EOL> "<STR_LIT>" , [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] , <EOL> "<STR_LIT>" <EOL> ] <EOL> @ property <EOL> def add_dolibrary_kw2 ( self ) : <EOL> return [ <EOL> "<STR_LIT>" , [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] , <EOL> "<STR_LIT>" <EOL> ] <EOL> @ property <EOL> def add_otherlibrary_kw1 ( self ) : <EOL> return [ <EOL> "<STR_LIT>" , [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] , <EOL> "<STR_LIT>" <EOL> ] <EOL> @ property <EOL> def add_spical_long_otherlibrary_kw1 ( self ) : <EOL> return [ <EOL> "<STR_LIT>" , [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] , <EOL> "<STR_LIT>" <EOL> ] <EOL> def do_setup ( self ) : <EOL> f = open ( self . current_view ) <EOL> data = json . load ( f ) <EOL> f . close ( ) <EOL> completion = data [ '<STR_LIT>' ] <EOL> completion . append ( self . add_dolibrary_kw1 ) <EOL> completion . append ( self . add_dolibrary_kw2 ) <EOL> completion . append ( self . add_otherlibrary_kw1 ) <EOL> completion . append ( self . add_spical_long_otherlibrary_kw1 ) <EOL> data [ '<STR_LIT>' ] = completion <EOL> f = open ( self . current_view , '<STR_LIT:w>' ) <EOL> json . dump ( data , f , indent = <NUM_LIT:4> ) <EOL> f . close ( ) <EOL> self . do_setup = True </s>
