lundi 5 octobre 2015

How can I test if two objects are equal in python?

I have made a function that connects to a twitter api. This function returns an twitter object. I want to create a testing function that checks if the returned object is really a twitter object. So this is my function:

def authenticate_twitter_api():
"""Make connection with twitters REST api"""
try:
    logger.info('Starting Twitter Authentication')
    twitter_api = twitter.Twitter(auth=twitter.OAuth(config.TWITTER_ACCESS_KEY, config.TWITTER_ACCESS_SECRET,
                                                     config.TWITTER_CONSUMER_KEY, config.TWITTER_CONSUMER_SECRET))
    print twitter_api
    logger.info("Service has started")
    return twitter_api
except:
    logger.error("Authentication Error. Could not connect to twitter api service")

When i run this function it returns:

<twitter.api.Twitter object at 0x7fc751783910>

Now, i want to create a testing function, maybe through numpy.testing in order to check if the type is a object.

numpy.testing.assert_equal(actual, desired, err_msg='')

actual = type(authenticate_twitter_api())
desired =<class 'twitter.api.Twitter'>

And here is the problem. I can't save an object to 'desired'.

What can i do ?

Aucun commentaire:

Enregistrer un commentaire