def test_templates_avoiding_almost_identical_products(self): """ Tests whether nearly identical products are NOT templates of one another. """ for i in range(1, dp.N_PROD_NONSENSE): target = "p_nonsense_" + str(i) templates = pttfidf.get_product_templates_tfidf(self.session_context, [target]).get(target, {}) nose.tools.ok_(len(templates) > 0, "No templates were generated for product " + target) template_products = [t[1] for t in templates] way_too_similar = "p_nonsense_" + str(i + 1) nose.tools.ok_(way_too_similar not in template_products, "Nearly identical templates!")
def test_templates(self): """ Tests the product templates (tfidf) that are computed and saved in the db. """ # Economia for i in range(1, dp.N_PROD_ECONOMIA + 1): target = "p_eco_" + str(i) templates = pttfidf.get_product_templates_tfidf(self.session_context, [target]).get(target, {}) language = self._find_language(target) nose.tools.ok_(language not in [None, "unknown"], "Could not retrieve the language correctly") if language == "portuguese": nose.tools.ok_(len(templates) > 0, "No templates were generated for product " + target) nose.tools.eq_(templates[0][1][:6], "p_eco_", "A questionable template order was obtained " + "for product %s: %s" % (target, templates)) for _, template_id in templates: nose.tools.ok_("expired" not in template_id, "An expired template was obtained") # Esportes for i in range(1, dp.N_PROD_ESPORTES + 1): target = "p_esp_" + str(i) templates = pttfidf.get_product_templates_tfidf(self.session_context, [target]).get(target, {}) language = self._find_language(target) nose.tools.ok_(language not in [None, "unknown"], "Could not retrieve the language correctly") if language == "portuguese": nose.tools.ok_(len(templates) > 0, "No templates were generated for product " + target) nose.tools.eq_(templates[0][1][:6], "p_esp_", "A questionable template order was obtained " + "for product %s: %s" % (target, templates)) for _, template_id in templates: nose.tools.ok_("expired" not in template_id, "An expired template was obtained") # Musica for i in range(1, dp.N_PROD_MUSICA + 1): target = "p_mus_" + str(i) templates = pttfidf.get_product_templates_tfidf(self.session_context, [target]).get(target, {}) language = self._find_language(target) nose.tools.ok_(language not in [None, "unknown"], "Could not retrieve the language correctly") if language == "portuguese": nose.tools.ok_(len(templates) > 0, "No templates were generated for product " + target) nose.tools.eq_(templates[0][1][:6], "p_mus_", "A questionable template order was obtained " + "for product %s: %s" % (target, templates)) # Tecnologia for i in range(1, dp.N_PROD_TECNOLOGIA + 1): target = "p_tec_" + str(i) templates = pttfidf.get_product_templates_tfidf(self.session_context, [target]).get(target, {}) language = self._find_language(target) nose.tools.ok_(language not in [None, "unknown"], "Could not retrieve the language correctly") if language == "portuguese": nose.tools.ok_(len(templates) > 0, "No templates were generated for product " + target) nose.tools.eq_(templates[0][1][:6], "p_tec_", "A questionable template order was obtained " + "for product %s: %s" % (target, templates))