forked from kshedden/datareader
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e51931
commit 20a53d7
Showing
5 changed files
with
110 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package datareader_test | ||
|
||
import ( | ||
"bytes" | ||
"encoding/csv" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/dominodatalab/datareader" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type testFile struct { | ||
path string | ||
} | ||
|
||
func TestToCsvConvertsSAS(t *testing.T) { | ||
files, err := filepath.Glob("test_files/data/*.sas7bdat") | ||
require.NoError(t, err) | ||
|
||
testcases := map[string]testFile{} | ||
for _, f := range files { | ||
testcases["converts "+f] = testFile{path: f} | ||
} | ||
|
||
for name, tt := range testcases { | ||
t.Run(name, func(t *testing.T) { | ||
f, err := os.Open(tt.path) | ||
require.NoError(t, err) | ||
defer f.Close() | ||
|
||
sas, err := datareader.NewSAS7BDATReader(f) | ||
require.NoError(t, err) | ||
sas.ConvertDates = true | ||
sas.TrimStrings = true | ||
|
||
buf := new(bytes.Buffer) | ||
w := csv.NewWriter(buf) | ||
err = datareader.ToCsv(sas, 100, w) | ||
|
||
require.NoError(t, err) | ||
}) | ||
} | ||
} | ||
|
||
func TestToCsvConvertsStata(t *testing.T) { | ||
files, err := filepath.Glob("test_files/data/*.dta") | ||
require.NoError(t, err) | ||
|
||
testcases := map[string]testFile{} | ||
for _, f := range files { | ||
testcases["converts "+f] = testFile{path: f} | ||
} | ||
|
||
for name, tt := range testcases { | ||
t.Run(name, func(t *testing.T) { | ||
f, err := os.Open(tt.path) | ||
require.NoError(t, err) | ||
defer f.Close() | ||
|
||
stata, err := datareader.NewStataReader(f) | ||
require.NoError(t, err) | ||
stata.ConvertDates = true | ||
stata.InsertCategoryLabels = true | ||
stata.InsertStrls = true | ||
|
||
buf := new(bytes.Buffer) | ||
w := csv.NewWriter(buf) | ||
err = datareader.ToCsv(stata, 100, w) | ||
require.NoError(t, err) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters