Skip to content

Commit

Permalink
Fix intermittently failing test, don't know why but sometimes Sprintf…
Browse files Browse the repository at this point in the history
…(%+v) puts 2 spaces between variables, sometimes one. Now we format to JSON in the example test and this probably won't happen again
  • Loading branch information
Peter Nemere committed Mar 25, 2024
1 parent 310feaa commit b2d5c78
Showing 1 changed file with 35 additions and 19 deletions.
54 changes: 35 additions & 19 deletions api/coreg/import_test.go
Original file line number Diff line number Diff line change
@@ -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|<nil>
// xOffset:186 yOffset:216 xScale:1.1359178 yScale:1.1359178|coreg-186_216-PCB_0921_0748739251_000RAS_N045000032302746300020LUJ01-A.png|<nil>
// xOffset:40 yOffset:519 xScale:4.478153 yScale:4.478153|coreg-40_519-SC3_0921_0748732957_027RAS_N0450000SRLC11373_0000LMJ01.png|<nil>
// xOffset:186 yOffset:216 xScale:1.1359178 yScale:1.1359178|coreg-186_216-PCB_0921_0748739251_000RAS_N045000032302746300020LUJ01.png|<nil>
// <nil>||Warped image name does not have expected components
// <nil>||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|<nil>
// {"xOffset":40, "yOffset":519, "xScale":4.478153, "yScale":4.478153}
// coreg-186_216-PCB_0921_0748739251_000RAS_N045000032302746300020LUJ01-A.png|<nil>
// {"xOffset":186, "yOffset":216, "xScale":1.1359178, "yScale":1.1359178}
// coreg-40_519-SC3_0921_0748732957_027RAS_N0450000SRLC11373_0000LMJ01.png|<nil>
// {"xOffset":40, "yOffset":519, "xScale":4.478153, "yScale":4.478153}
// coreg-186_216-PCB_0921_0748739251_000RAS_N045000032302746300020LUJ01.png|<nil>
// {"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
// {}
}

0 comments on commit b2d5c78

Please sign in to comment.