def difference_display(Prg, SelfObj, MarksNowDetected, TestWantedResults, AppendToFileIfDifference=None): print("Num of Marks now detected: ", len(MarksNowDetected.keys())) print("Num of wanted results: ", len( TestWantedResults)) WantedKeys = sorted(list(TestWantedResults.keys())) for Key in sorted(list(MarksNowDetected.keys())): # in MarkDetected dict() can be index gaps. # example: D = {0:"A", 3:"B", 5, "C"} # so we loop over on detected keys and always take the next element from the test - # the two dict's keys can be different but the order of the keys are fixed MarkDetected = mark_util.mark_to_string(MarksNowDetected[Key]) MarkWanted = TestWantedResults.get(WantedKeys.pop(0), "Key not in Wanted results: " + str(Key)) if MarkDetected != MarkWanted: if AppendToFileIfDifference: util.file_append(Prg, os.path.join(*AppendToFileIfDifference), "\n\n" + MarkDetected) else: PathDetected = os.path.join(Prg["DirTmpPath"], "test_detected_"+str(Key)+".txt") PathWanted = os.path.join(Prg["DirTmpPath"], "test_wanted_"+str(Key)+".txt") util.file_write(Prg, PathDetected, MarkDetected) util.file_write(Prg, PathWanted, MarkWanted) # theoretically all tests has been ok in released versions, this case happens only in dev time print("Dev message: test comparing with vimdiff:") os.system("vimdiff " + PathDetected + " " + PathWanted) SelfObj.assertEqual(MarkDetected, MarkWanted)
def text_block_analyse(Prg, PositionStart=(0, 0), ScanDirectionHorizontal="from_left_to_righ", ScanDirectionVertical="from_top_to_bottom"): # I want to handle RGB or Grayscale images only, # so I handle 3 or 1 color channels print("Selected Image Id", Prg["ImageIdSelected"]) Img = Prg["ImagesLoaded"][Prg["ImageIdSelected"]] print("Img width, height: ", Img["Width"], Img["Height"]) Marks = mark_collect_from_img_object(Prg, Img) print("Num of Marks:", len(Marks.keys())) print("TODO: convert marks to text") print(mark_util.mark_to_string(Marks[1]))
def test_mark_to_string(self): Mark = { "Coords": { (3, 3): 1, (4, 3): 1, (5, 3): 1, (4, 4): 1, (3, 5): 1, (4, 5): 1 }, "Width": 3, "Height": 3, "Xmin": 3, "Ymin": 3, "Xmax": 5, "Ymax": 5 } Wanted = ("OOO\n" ".O.\n" "OO.") self.assertEqual(Wanted, mark_util.mark_to_string(Mark))