From b2d5c7880f2c2b522cd1e6c64e64f279a16dbd9a Mon Sep 17 00:00:00 2001 From: Peter Nemere Date: Tue, 26 Mar 2024 06:51:49 +1000 Subject: [PATCH] Fix intermittently failing test, don't know why but sometimes Sprintf(%+v) puts 2 spaces between variables, sometimes one. Now we format to JSON in the example test and this probably won't happen again --- api/coreg/import_test.go | 54 ++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/api/coreg/import_test.go b/api/coreg/import_test.go index 3be52e05..7fe82dda 100644 --- a/api/coreg/import_test.go +++ b/api/coreg/import_test.go @@ -1,31 +1,47 @@ package coreg -import "fmt" +import ( + "fmt" + "log" + + protos "github.com/pixlise/core/v4/generated-protos" + "google.golang.org/protobuf/encoding/protojson" +) + +func printWarpXform(xform *protos.ImageMatchTransform, name string, err error) { + fmt.Printf("%v|%v\n", name, err) + + if b, err := protojson.Marshal(xform); err != nil { + log.Fatalln(err) + } else { + fmt.Printf("%v\n", string(b)) + } +} func Example_readWarpedImageTransform() { - xform, name, err := readWarpedImageTransform("warped-zoom_4.478153138946561-win_519_40_1232_1183-SN100D0-SC3_0921_0748732957_027RAS_N0450000SRLC11373_0000LMJ01-A.png") - fmt.Printf("%+v|%v|%v\n", xform, name, err) + printWarpXform(readWarpedImageTransform("warped-zoom_4.478153138946561-win_519_40_1232_1183-SN100D0-SC3_0921_0748732957_027RAS_N0450000SRLC11373_0000LMJ01-A.png")) - xform, name, err = readWarpedImageTransform("warped-zoom_1.1359177671479777-win_216_186_167_183-PCB_0921_0748739251_000RAS_N045000032302746300020LUJ01-A.png") - fmt.Printf("%+v|%v|%v\n", xform, name, err) + printWarpXform(readWarpedImageTransform("warped-zoom_1.1359177671479777-win_216_186_167_183-PCB_0921_0748739251_000RAS_N045000032302746300020LUJ01-A.png")) - xform, name, err = readWarpedImageTransform("warped-zoom_4.478153138946561-win_519_40_1232_1183-SN100D0-SC3_0921_0748732957_027RAS_N0450000SRLC11373_0000LMJ01.png") - fmt.Printf("%+v|%v|%v\n", xform, name, err) + printWarpXform(readWarpedImageTransform("warped-zoom_4.478153138946561-win_519_40_1232_1183-SN100D0-SC3_0921_0748732957_027RAS_N0450000SRLC11373_0000LMJ01.png")) - xform, name, err = readWarpedImageTransform("warped-zoom_1.1359177671479777-win_216_186_167_183-PCB_0921_0748739251_000RAS_N045000032302746300020LUJ01.png") - fmt.Printf("%+v|%v|%v\n", xform, name, err) + printWarpXform(readWarpedImageTransform("warped-zoom_1.1359177671479777-win_216_186_167_183-PCB_0921_0748739251_000RAS_N045000032302746300020LUJ01.png")) - xform, name, err = readWarpedImageTransform("warped-win_216_186_167_183-PCB_0921_0748739251_000RAS_N045000032302746300020LUJ01.png") - fmt.Printf("%+v|%v|%v\n", xform, name, err) + printWarpXform(readWarpedImageTransform("warped-win_216_186_167_183-PCB_0921_0748739251_000RAS_N045000032302746300020LUJ01.png")) - xform, name, err = readWarpedImageTransform("warped-zoom_4.478153138946561-win_519_40_1232_1183-SN100D0-SC3_0921_0748732957_027RASS_N0450000SRLC11373_0000LMJ01.png") - fmt.Printf("%+v|%v|%v\n", xform, name, err) + printWarpXform(readWarpedImageTransform("warped-zoom_4.478153138946561-win_519_40_1232_1183-SN100D0-SC3_0921_0748732957_027RASS_N0450000SRLC11373_0000LMJ01.png")) // Output: - // xOffset:40 yOffset:519 xScale:4.478153 yScale:4.478153|coreg-40_519-SC3_0921_0748732957_027RAS_N0450000SRLC11373_0000LMJ01-A.png| - // xOffset:186 yOffset:216 xScale:1.1359178 yScale:1.1359178|coreg-186_216-PCB_0921_0748739251_000RAS_N045000032302746300020LUJ01-A.png| - // xOffset:40 yOffset:519 xScale:4.478153 yScale:4.478153|coreg-40_519-SC3_0921_0748732957_027RAS_N0450000SRLC11373_0000LMJ01.png| - // xOffset:186 yOffset:216 xScale:1.1359178 yScale:1.1359178|coreg-186_216-PCB_0921_0748739251_000RAS_N045000032302746300020LUJ01.png| - // ||Warped image name does not have expected components - // ||Failed to find GDS file name section in image name: SC3_0921_0748732957_027RASS_N0450000SRLC11373_0000LMJ01. Error: Failed to parse meta from file name + // coreg-40_519-SC3_0921_0748732957_027RAS_N0450000SRLC11373_0000LMJ01-A.png| + // {"xOffset":40, "yOffset":519, "xScale":4.478153, "yScale":4.478153} + // coreg-186_216-PCB_0921_0748739251_000RAS_N045000032302746300020LUJ01-A.png| + // {"xOffset":186, "yOffset":216, "xScale":1.1359178, "yScale":1.1359178} + // coreg-40_519-SC3_0921_0748732957_027RAS_N0450000SRLC11373_0000LMJ01.png| + // {"xOffset":40, "yOffset":519, "xScale":4.478153, "yScale":4.478153} + // coreg-186_216-PCB_0921_0748739251_000RAS_N045000032302746300020LUJ01.png| + // {"xOffset":186, "yOffset":216, "xScale":1.1359178, "yScale":1.1359178} + // |Warped image name does not have expected components + // {} + // |Failed to find GDS file name section in image name: SC3_0921_0748732957_027RASS_N0450000SRLC11373_0000LMJ01. Error: Failed to parse meta from file name + // {} }