Example #1
0
 def test_generate_candidates_product_with_weight(self):
     value = "30 g"
     insight_data = {"matcher_type": "with_mention", "text": value}
     predictions = [self.generate_prediction(value, insight_data)]
     assert (list(
         ProductWeightImporter.generate_candidates(
             self.get_product(quantity="30 g"), predictions)) == [])
Example #2
0
 def test_generate_candidates_multiple_predictions_different_subtypes(self):
     value_1 = "30 g net"
     value_2 = "150 g"
     data_1 = {"matcher_type": "with_ending_mention", "text": value_1}
     data_2 = {"matcher_type": "no_mention", "text": value_2}
     predictions = [
         self.generate_prediction(value_1, data_1),
         self.generate_prediction(value_2, data_2),
     ]
     candidates = list(
         ProductWeightImporter.generate_candidates(self.get_product(),
                                                   predictions))
     assert len(candidates) == 1
     candidate = candidates[0]
     assert candidate.automatic_processing is None
     assert candidate.value == value_1
Example #3
0
 def test_generate_candidates_single(self):
     value = "30 g"
     insight_data = {"matcher_type": "with_mention", "text": value}
     predictions = [self.generate_prediction(value, insight_data)]
     candidates = list(
         ProductWeightImporter.generate_candidates(self.get_product(),
                                                   predictions))
     assert len(candidates) == 1
     candidate = candidates[0]
     assert isinstance(candidate, ProductInsight)
     assert candidate.automatic_processing is None
     assert candidate.type == "product_weight"
     assert candidate.data == insight_data
     assert candidate.value_tag is None
     assert candidate.predictor == "ocr"
     assert candidate.barcode == DEFAULT_BARCODE
Example #4
0
 def test_generate_candidates_from_product_name(self):
     value_1 = "30 g net"
     data_1 = {
         "matcher_type": "with_ending_mention",
         "text": value_1,
         "source": "product_name",
     }
     predictions = [
         self.generate_prediction(value_1, data_1),
     ]
     candidates = list(
         ProductWeightImporter.generate_candidates(self.get_product(),
                                                   predictions))
     assert len(candidates) == 1
     candidate = candidates[0]
     assert candidate.automatic_processing is False
     assert candidate.value == value_1
Example #5
0
 def test_is_conflicting_insight(self):
     assert ProductWeightImporter.is_conflicting_insight(
         ProductInsight(value="30 g"), ProductInsight(value="30 g"))
     assert not ProductWeightImporter.is_conflicting_insight(
         ProductInsight(value="30 g"), ProductInsight(value="40 g"))
Example #6
0
 def test_get_required_prediction_types(self):
     assert ProductWeightImporter.get_required_prediction_types() == {
         PredictionType.product_weight
     }
Example #7
0
 def test_get_type(self):
     assert ProductWeightImporter.get_type() == InsightType.product_weight