Skip to content

Instantly share code, notes, and snippets.

@crankycoder
Last active November 3, 2017 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crankycoder/64566d8c6de1243890c85ba80eb96c0e to your computer and use it in GitHub Desktop.
Save crankycoder/64566d8c6de1243890c85ba80eb96c0e to your computer and use it in GitHub Desktop.
-bash-4.2$ pytest
========================================= test session starts ==========================================
platform linux2 -- Python 2.7.12, pytest-3.2.3, py-1.4.34, pluggy-0.4.0
rootdir: /home/hadoop/taar, inifile:
plugins: cov-2.5.1
collected 24 items
test_collaborativerecommender.py ....
test_legacyrecommender.py ...
test_localerecommender.py ....
test_profile_fetcher.py ..
test_recommendation_manager.py .F
test_similarityrecommender.py ..F..F
test_utils.py ...
=============================================== FAILURES ===============================================
_____________________________________ test_recommendation_strategy _____________________________________
def test_recommendation_strategy():
EXPECTED_ADDONS = ["expected_id", "other-id"]
# Create a stub ProfileFetcher that always returns the same
# client data.
class StubFetcher:
def get(self, client_id):
return {}
# Configure the recommender so that only the second model
# can recommend and return the expected addons.
recommenders = (
StubRecommender(False, []),
StubRecommender(True, EXPECTED_ADDONS),
StubRecommender(False, []),
)
# Make sure the recommender returns the expected addons.
manager = RecommendationManager(StubFetcher(), recommenders)
> assert manager.recommend("client-id", 10) == EXPECTED_ADDONS
test_recommendation_manager.py:55:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <taar.recommenders.recommendation_manager.RecommendationManager object at 0x7f3f56c81810>
client_id = 'client-id', limit = 10, extra_data = {}
def recommend(self, client_id, limit, extra_data={}):
"""Return recommendations for the given client.
The recommendation logic will go through each recommender and pick the
first one that "can_recommend".
:param client_id: the client unique id.
:param limit: the maximum number of recommendations to return.
:param extra_data: a dictionary with extra client data.
"""
# Get the info for the requested client id.
client_info = self.profile_fetcher.get(client_id)
if client_info is None:
return []
# Compute the recommendation.
for r in self.recommenders:
> if r.can_recommend(client_info, extra_data):
E TypeError: can_recommend() takes exactly 2 arguments (3 given)
/mnt/anaconda2/lib/python2.7/site-packages/mozilla_taar-0.0.16.dev9+ga3157d4-py2.7.egg/taar/recommenders/recommendation_manager.py:54: TypeError
_________________________________________ test_recommendations _________________________________________
instantiate_mocked_s3_bucket = s3.ServiceResource()
def test_recommendations(instantiate_mocked_s3_bucket):
# Create a new instance of a SimilarityRecommender.
r = SimilarityRecommender()
> recommendations = r.recommend(generate_a_fake_taar_client(), 10)
test_similarityrecommender.py:124:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/mnt/anaconda2/lib/python2.7/site-packages/mozilla_taar-0.0.16.dev9+ga3157d4-py2.7.egg/taar/recommenders/similarity_recommender.py:151: in recommend
donor_set_ranking, indices = self.get_similar_donors(client_data)
/mnt/anaconda2/lib/python2.7/site-packages/mozilla_taar-0.0.16.dev9+ga3157d4-py2.7.egg/taar/recommenders/similarity_recommender.py:133: in get_similar_donors
lambda x, y: distance.hamming(x, y))
/mnt/anaconda2/lib/python2.7/site-packages/scipy/spatial/distance.py:2020: in cdist
XA = _copy_array_if_base_present(_convert_to_double(XA))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
X = array([[u'nowhere-us', u'en-US', u'mac'],
[u'pompei-it', u'it-IT', u'Linux'],
[u'brasilia-br', u'br-PT', u'windows']], dtype=object)
def _convert_to_double(X):
if X.dtype != np.double:
> X = X.astype(np.double)
E ValueError: could not convert string to float: windows
/mnt/anaconda2/lib/python2.7/site-packages/scipy/spatial/distance.py:143: ValueError
_______________________________________ test_distance_functions ________________________________________
instantiate_mocked_s3_bucket = s3.ServiceResource()
def test_distance_functions(instantiate_mocked_s3_bucket):
# Tests the similarity functions via expected output when passing modified client data.
r = SimilarityRecommender()
# Generate a fake client.
test_client = generate_a_fake_taar_client()
> recs = r.recommend(test_client)
E TypeError: recommend() takes at least 3 arguments (2 given)
test_similarityrecommender.py:157: TypeError
================================= 3 failed, 21 passed in 3.22 seconds ==================================
-bash-4.2$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment