darwin/csv2json

rake fails

hoffmanc opened this issue · 5 comments

/usr/bin/ruby1.8 -I"lib:lib:test" "/usr/lib/ruby/gems/1.8/gems/rake-0.8.6/lib/rake/rake_test_loader.rb" "test/test_csv2json.rb"
(in /home/hoffmanc/ocer/darwin-csv2json-0436af7)
All dependencies seem to be installed.
Loaded suite /usr/lib/ruby/gems/1.8/gems/rake-0.8.6/lib/rake/rake_test_loader
Started
population_comma.csv
F
Finished in 0.024187 seconds.

  1. Failure:
    test: Csv2json should parse some test files. (TestCsv2json)
    [./test/test_csv2json.rb:18:in __bind_1269015901_504391' ./test/test_csv2json.rb:12:inopen'
    ./test/test_csv2json.rb:12:in __bind_1269015901_504391' ./test/test_csv2json.rb:9:inglob'
    ./test/test_csv2json.rb:9:in __bind_1269015901_504391' ./test/test_csv2json.rb:8:inchdir'
    ./test/test_csv2json.rb:8:in __bind_1269015901_504391' /usr/lib/ruby/gems/1.8/gems/shoulda-2.10.3/lib/shoulda/context.rb:362:incall'
    /usr/lib/ruby/gems/1.8/gems/shoulda-2.10.3/lib/shoulda/context.rb:362:in `test: Csv2json should parse some test files. ']:
    is not true.

1 tests, 1 assertions, 1 failures, 0 errors
rake aborted!
Command failed with status (1): [/usr/bin/ruby1.8 -I"lib:lib:test" "/usr/li...]

(See full trace by running task with --trace)

hm, you rake task don't have probably permissions to create temporary files

run it with sudo or clone the repo into home directory

Command failed with status (1): [/usr/bin/ruby1.8 -I"lib:lib:test" "/usr/li...]

I tried sudo, with no success. How do you know it is a permissions issue? status (1)? It is already in my home dir.

oh, and here is a python script that basically does everything you need:

import csv
from itertools import izip
f = open( 'export.csv', 'r' )
reader = csv.reader( f )
keys = ()
out = []
for property in reader:
if len(keys) == 0:
keys = property
else:
property = iter( property )
data = {}
for key in keys:
data[ key ] = property.next()
out += [ data ]
print out

I don't know. I'm not a ruby master :)

Thanks for sharing the python script, The ruby script is not much longer:
http://github.com/darwin/csv2json/blob/master/lib/csv2json.rb

I just wrapped it into rubygems for convenient commandline installation.

This issue should now be fixed; tests were failing because the hash used to produce the JSON wasn't sorting the keys the same every time (so comparison with the sample data would fail). Today's commits have fixed this problem.