<s> import unittest <EOL> from robotide . robotapi import VariableTable , KeywordTable , TestCaseTable <EOL> from robotide . controller . macrocontrollers import ( <EOL> UserKeywordController , TestCaseController ) <EOL> from robotide . controller . tablecontrollers import ( <EOL> VariableTableController , KeywordTableController , TestCaseTableController ) <EOL> from robotide . validators import ( <EOL> ScalarVariableNameValidator , ListVariableNameValidator , <EOL> UserKeywordNameValidator , TestCaseNameValidator ) <EOL> class _NameValidationTest ( object ) : <EOL> def mock_ctrl ( self ) : <EOL> self . datafile = self <EOL> self . datafile_controller = self <EOL> self . mark_dirty = lambda : <NUM_LIT:0> <EOL> self . update_namespace = lambda : <NUM_LIT:0> <EOL> self . register_for_namespace_updates = lambda * args : <NUM_LIT:0> <EOL> def test_new_name_validation_pass ( self ) : <EOL> self . assertTrue ( self . validate ( '<STR_LIT>' ) ) <EOL> def test_new_name_validation_fails_when_same_already_exists ( self ) : <EOL> self . add_named ( '<STR_LIT>' ) <EOL> self . assertFalse ( self . validate ( '<STR_LIT>' ) ) <EOL> def test_new_name_validation_fails_when_normalized_same_already_exists ( self ) : <EOL> self . add_named ( '<STR_LIT>' ) <EOL> self . assertFalse ( self . validate ( '<STR_LIT>' ) ) <EOL> def test_rename_validation_pass ( self ) : <EOL> self . assertTrue ( self . rename_validate ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def test_rename_validation_fails_when_same_already_exists ( self ) : <EOL> self . add_named ( '<STR_LIT>' ) <EOL> self . assertFalse ( self . rename_validate ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def test_rename_validation_pass_when_different_than_previous_but_normalized_eq ( self ) : <EOL> self . assertTrue ( self . rename_validate ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> class _VariableNameValidationTest ( _NameValidationTest ) : <EOL> def setUp ( self ) : <EOL> self . _variable_table_ctrl = VariableTableController ( <EOL> self , VariableTable ( self ) ) <EOL> self . mock_ctrl ( ) <EOL> def add_named ( self , name ) : <EOL> self . _variable_table_ctrl . add_variable ( <EOL> '<STR_LIT>' % ( self . symbol , name ) , '<STR_LIT:value>' ) <EOL> def validate ( self , name , old = None ) : <EOL> self . _validator = self . validator_class ( self . _variable_table_ctrl , old ) <EOL> return self . _validator . _validate ( '<STR_LIT>' % ( self . symbol , name ) ) == '<STR_LIT>' <EOL> def rename_validate ( self , old , new ) : <EOL> self . add_named ( old ) <EOL> return self . validate ( new , '<STR_LIT>' % ( self . symbol , old ) ) <EOL> class ScalarNameValidationTest ( _VariableNameValidationTest , unittest . TestCase ) : <EOL> symbol = '<STR_LIT:$>' <EOL> validator_class = ScalarVariableNameValidator <EOL> class ListVariableNameValidationTest ( _VariableNameValidationTest , unittest . TestCase ) : <EOL> symbol = '<STR_LIT:@>' <EOL> validator_class = ListVariableNameValidator <EOL> class _MacroNameValidationTest ( _NameValidationTest ) : <EOL> def setUp ( self ) : <EOL> self . mock_ctrl ( ) <EOL> self . _table_ctrl = self . table_ctrl_class ( self , self . table_class ( self ) ) <EOL> self . _ctrl = self . ctrl_class ( self . _table_ctrl , self ) <EOL> def add_named ( self , name ) : <EOL> return self . _ctrl . _parent . new ( name ) <EOL> def validate ( self , name , old = None ) : <EOL> validator = self . validator_class ( self . _ctrl , old ) <EOL> return validator . _validate ( name ) == '<STR_LIT>' <EOL> def rename_validate ( self , old , new ) : <EOL> self . _ctrl = self . add_named ( old ) <EOL> return self . validate ( new , old ) <EOL> class KeywordNameValidationTest ( _MacroNameValidationTest , unittest . TestCase ) : <EOL> table_class = KeywordTable <EOL> table_ctrl_class = KeywordTableController <EOL> ctrl_class = UserKeywordController <EOL> validator_class = UserKeywordNameValidator <EOL> class TestCaseNameValidationTest ( _MacroNameValidationTest , unittest . TestCase ) : <EOL> table_class = TestCaseTable <EOL> table_ctrl_class = TestCaseTableController <EOL> ctrl_class = TestCaseController <EOL> validator_class = TestCaseNameValidator </s>
