<s> """<STR_LIT>""" <EOL> import unittest <EOL> from homeassistant . const import ATTR_LATITUDE , ATTR_LONGITUDE <EOL> from homeassistant . core import State <EOL> from homeassistant . helpers import location <EOL> class TestHelpersLocation ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_has_location_with_invalid_states ( self ) : <EOL> """<STR_LIT>""" <EOL> for state in ( None , <NUM_LIT:1> , "<STR_LIT:hello>" , object ) : <EOL> self . assertFalse ( location . has_location ( state ) ) <EOL> def test_has_location_with_states_with_invalid_locations ( self ) : <EOL> """<STR_LIT>""" <EOL> state = State ( '<STR_LIT>' , '<STR_LIT>' , { <EOL> ATTR_LATITUDE : '<STR_LIT>' , <EOL> ATTR_LONGITUDE : <NUM_LIT> <EOL> } ) <EOL> self . assertFalse ( location . has_location ( state ) ) <EOL> def test_has_location_with_states_with_valid_location ( self ) : <EOL> """<STR_LIT>""" <EOL> state = State ( '<STR_LIT>' , '<STR_LIT>' , { <EOL> ATTR_LATITUDE : <NUM_LIT> , <EOL> ATTR_LONGITUDE : <NUM_LIT> <EOL> } ) <EOL> self . assertTrue ( location . has_location ( state ) ) <EOL> def test_closest_with_no_states_with_location ( self ) : <EOL> """<STR_LIT>""" <EOL> state = State ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> state2 = State ( '<STR_LIT>' , '<STR_LIT>' , { <EOL> ATTR_LATITUDE : '<STR_LIT>' , <EOL> ATTR_LONGITUDE : <NUM_LIT> , <EOL> } ) <EOL> state3 = State ( '<STR_LIT>' , '<STR_LIT>' , { <EOL> ATTR_LONGITUDE : <NUM_LIT> , <EOL> } ) <EOL> self . assertIsNone ( <EOL> location . closest ( <NUM_LIT> , <NUM_LIT> , [ state , state2 , state3 ] ) ) <EOL> def test_closest_returns_closest ( self ) : <EOL> """<STR_LIT>""" <EOL> state = State ( '<STR_LIT>' , '<STR_LIT>' , { <EOL> ATTR_LATITUDE : <NUM_LIT> , <EOL> ATTR_LONGITUDE : <NUM_LIT> , <EOL> } ) <EOL> state2 = State ( '<STR_LIT>' , '<STR_LIT>' , { <EOL> ATTR_LATITUDE : <NUM_LIT> , <EOL> ATTR_LONGITUDE : <NUM_LIT> , <EOL> } ) <EOL> self . assertEqual ( <EOL> state , location . closest ( <NUM_LIT> , <NUM_LIT> , [ state , state2 ] ) ) </s>
