aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2019-10-25 11:10:40 +0100
committerMatthew Lemon <lemon@matthewlemon.com>2019-10-25 11:10:40 +0100
commit03073b44eaa801afc2faad7175669c2ee377838d (patch)
treec094638c54213764e25a6d178beb9df5e91fc0d5
parente9aa53ccc3572bd17c22a3aa99851863cd2bde82 (diff)
added test and some cleanup
Diffstat (limited to '')
-rw-r--r--main.go6
-rw-r--r--reader/reader.go9
-rw-r--r--reader/reader_test.go15
3 files changed, 19 insertions, 11 deletions
diff --git a/main.go b/main.go
index 911e51d..525191f 100644
--- a/main.go
+++ b/main.go
@@ -1,10 +1,6 @@
package main
-import (
- "datamaps-go/reader"
-)
-
func main() {
//reader.ReadDML("/home/lemon/Documents/datamaps/input/datamap.csv")
- data, err := reader.ReadXLSX("/home/lemon/Documents/datamaps/input/A417%20Air%20Balloon_Q1%20Apr%20-%20June%202019_Return.xlsm")
+ //reader.ReadXLSX("/home/lemon/Documents/datamaps/input/A417%20Air%20Balloon_Q1%20Apr%20-%20June%202019_Return.xlsm")
}
diff --git a/reader/reader.go b/reader/reader.go
index e4a6915..33e1773 100644
--- a/reader/reader.go
+++ b/reader/reader.go
@@ -2,6 +2,7 @@ package reader
import (
"encoding/csv"
+ "errors"
"fmt"
"io"
"io/ioutil"
@@ -36,7 +37,7 @@ func ReadDML(path string) (*[]DatamapLine, error) {
var s []DatamapLine
data, err := ioutil.ReadFile(path)
if err != nil {
- return &s, &fileError{path, "Cannot open."}
+ return &s, errors.New("Cannot find file")
}
r := csv.NewReader(strings.NewReader(string(data)))
for {
@@ -45,7 +46,7 @@ func ReadDML(path string) (*[]DatamapLine, error) {
break
}
if err != nil {
- fmt.Printf("Cannot read line %s, ", err)
+ return &s, errors.New("Cannot read line %s")
}
if record[0] == "cell_key" {
// this must be the header
@@ -56,10 +57,6 @@ func ReadDML(path string) (*[]DatamapLine, error) {
Sheet: strings.Trim(record[1], " "),
Cellref: strings.Trim(record[2], " ")}
s = append(s, dml)
- // fmt.Printf("Key: %s; sheet: %s cellref: %s\n", dml.Key, dml.Sheet, dml.Cellref)
- // klen, slen := Keylens(dml)
- // fmt.Printf("Key length: %d\n", klen)
- // fmt.Printf("Sheet length: %d\n\n", slen)
}
return &s, nil
}
diff --git a/reader/reader_test.go b/reader/reader_test.go
index ba3172e..a7dd281 100644
--- a/reader/reader_test.go
+++ b/reader/reader_test.go
@@ -22,3 +22,18 @@ func TestReadDML(t *testing.T) {
t.Errorf("dmlData[0].Sheet = %s; want Introduction", dmlData[0].Key)
}
}
+
+func TestNoFileReturnsError(t *testing.T) {
+ _, err := ReadDML("/home/bobbins.csv")
+ // if we get no error, something has gone wrong
+ if err == nil {
+ t.Errorf("Should have thrown error %s", err)
+ }
+}
+
+func TestBadDMLLine(t *testing.T) {
+ _, err := ReadDML("/home/lemon/code/python/bcompiler-engine/tests/resources/datamap_empty_cols.csv")
+ if err != nil {
+ t.Errorf("This will trigger")
+ }
+}