-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathtest_csv2json.rb
More file actions
63 lines (53 loc) · 1.95 KB
/
Copy pathtest_csv2json.rb
File metadata and controls
63 lines (53 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require 'test_helper'
class TestCSV2JSON < Test::Unit::TestCase
def test_converting_csv_to_dotstrings
csv_file = "test/data/test_data.csv"
converter = Babelish::CSV2JSON.new(csv_file, 'English' => "en")
converter.convert
assert File.exist?("en.json"), "the ouptut file does not exist"
# clean up
system("rm -rf en.json")
end
def test_converting_csv_to_dotstrings_one_output_option
csv_file = "test/data/test_data.csv"
single_file = 'myfile.json'
converter = Babelish::CSV2JSON.new(csv_file,
{'English' => "en"},
:output_basename => 'myfile',
:ignore_lang_path => true)
converter.convert
assert File.exist?(single_file), "the ouptut file does not exist"
# clean up
system("rm -rf ./" + single_file)
end
def test_converting_csv_to_json_with_unpretty_json
csv_file = "test/data/test_data.csv"
expected_json_filename = "test_unpretty_json.json"
given_json_filename = "output.json"
expected_json = File.read("test/data/" + expected_json_filename)
converter = Babelish::CSV2JSON.new(csv_file,
{ "English" => "en" },
output_basename: "output",
pretty_json: false)
converter.convert
given_json = File.read(given_json_filename)
assert_equal(expected_json, given_json, "JSON file has incorrect format")
# clean up
system("rm -rf ./" + given_json_filename)
end
def test_converting_csv_to_json_with_pretty_json
csv_file = "test/data/test_data.csv"
expected_json_filename = "test_pretty_json.json"
given_json_filename = "output.json"
expected_json = File.read("test/data/" + expected_json_filename)
converter = Babelish::CSV2JSON.new(csv_file,
{ "English" => "en" },
output_basename: "output",
pretty_json: true)
converter.convert
given_json = File.read(given_json_filename)
assert_equal(expected_json, given_json, "JSON file has incorrect format")
# clean up
system("rm -rf ./" + given_json_filename)
end
end