ruport 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +4 -2
- data/README +4 -3
- data/Rakefile +1 -1
- data/lib/ruport.rb +1 -4
- data/lib/ruport/config.rb +6 -11
- data/lib/ruport/data/collection.rb +8 -2
- data/lib/ruport/data/groupable.rb +0 -2
- data/lib/ruport/data/record.rb +0 -13
- data/lib/ruport/data/set.rb +0 -8
- data/lib/ruport/data/table.rb +1 -18
- data/lib/ruport/data/taggable.rb +1 -6
- data/lib/ruport/format/latex.rb +5 -8
- data/lib/ruport/format/pdf.rb +56 -0
- data/lib/ruport/format/plugin.rb +5 -0
- data/lib/ruport/format/svg.rb +26 -4
- data/lib/ruport/format/text.rb +25 -2
- data/lib/ruport/format/xml.rb +1 -1
- data/lib/ruport/generator.rb +1 -1
- data/lib/ruport/mailer.rb +1 -4
- data/lib/ruport/query.rb +0 -9
- data/lib/ruport/renderer.rb +15 -1
- data/lib/ruport/report.rb +5 -22
- data/test/test_mailer.rb +86 -24
- data/test/test_report.rb +72 -1
- data/test/test_table.rb +15 -0
- data/test/unit.log +7 -277
- metadata +34 -44
- data/lib/ruport.rb~ +0 -69
- data/lib/ruport/data.rb.rej +0 -5
- data/lib/ruport/data.rb~ +0 -1
- data/lib/ruport/data/record.rb~ +0 -236
- data/lib/ruport/data/table.rb.rej +0 -67
- data/lib/ruport/data/table.rb~ +0 -414
- data/test/test_query.rb.rej +0 -161
- data/test/test_query.rb~ +0 -337
- data/test/test_record.rb.rej +0 -46
- data/test/test_table.rb~ +0 -336
data/test/test_record.rb.rej
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
***************
|
2
|
-
*** 170,180 ****
|
3
|
-
end
|
4
|
-
|
5
|
-
def test_records_with_differing_attrs_and_data_hash_differently
|
6
|
-
- r = Record.new :attributes => %w[a b], :data => [1,2]
|
7
|
-
- s = Record.new :attributes => %w[a b]
|
8
|
-
assert r.hash != s.hash
|
9
|
-
|
10
|
-
- t = Record.new :attributes => %w[a b], :data => [1,3]
|
11
|
-
assert r.hash != t.hash
|
12
|
-
end
|
13
|
-
end
|
14
|
-
--- 170,201 ----
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_records_with_differing_attrs_and_data_hash_differently
|
18
|
-
+ r = Record.new [1,2],:attributes => %w[a b]
|
19
|
-
+ s = Record.new [nil,nil],:attributes => %w[a b]
|
20
|
-
assert r.hash != s.hash
|
21
|
-
|
22
|
-
+ t = Record.new [1,3],:attributes => %w[a b]
|
23
|
-
assert r.hash != t.hash
|
24
|
-
end
|
25
|
-
+
|
26
|
-
+ # ticket:71
|
27
|
-
+ def test_record_has_indifferent_access
|
28
|
-
+ t = Record.new [1,2,3], :attributes => %w[a b c]
|
29
|
-
+ assert_equal [1,2,3], [t[0],t[1],t[2]]
|
30
|
-
+ assert_equal [1,2,3], [t["a"],t["b"],t["c"]]
|
31
|
-
+ assert_equal [1,2,3], [t.a,t.b,t.c]
|
32
|
-
+
|
33
|
-
+ #FIXME: Dinko, the commented out tests need to pass
|
34
|
-
+
|
35
|
-
+ # assert_equal [1,2,3], [t[:a],t[:b],t[:c]]
|
36
|
-
+
|
37
|
-
+ x = Record.new [1,2,3], :attributes => [:a,:b,:c]
|
38
|
-
+ assert_equal [1,2,3], [x[0],x[1],x[2]]
|
39
|
-
+ assert_equal [1,2,3], [x[:a],x[:b],x[:c]]
|
40
|
-
+
|
41
|
-
+ #FIXME: ...
|
42
|
-
+
|
43
|
-
+ #assert_equal [1,2,3], [x["a"],x["b"],x["c"]]
|
44
|
-
+ #assert_equal [1,2,3], [x.a,x.b,x.c]
|
45
|
-
+ end
|
46
|
-
end
|
data/test/test_table.rb~
DELETED
@@ -1,336 +0,0 @@
|
|
1
|
-
require "test/unit"
|
2
|
-
require "ruport"
|
3
|
-
begin; require "rubygems"; rescue LoadError; nil; end
|
4
|
-
|
5
|
-
class TestTable < Test::Unit::TestCase
|
6
|
-
def test_constructors
|
7
|
-
table = Ruport::Data::Table.new
|
8
|
-
table2 = Ruport::Data::Table.new :column_names => %w[a b c]
|
9
|
-
table3 = Ruport::Data::Table.new :data => [[1,2,3]]
|
10
|
-
table4 = Ruport::Data::Table.new :column_names => %w[col1 col2 col3],
|
11
|
-
:data => [[1,2,3]]
|
12
|
-
tables = [table,table2,table3,table4]
|
13
|
-
tables.zip([[],%w[a b c], [], %w[col1 col2 col3]]).each do |t,n|
|
14
|
-
assert_equal n, t.column_names
|
15
|
-
|
16
|
-
t = [[1,2,3],[4,5,6]].to_table(%w[a b c])
|
17
|
-
t[0].tag :foo
|
18
|
-
t[1].tag :bar
|
19
|
-
table_from_records = t.data.to_table(t.column_names)
|
20
|
-
assert_equal [:foo], table_from_records[0].tags
|
21
|
-
assert_equal [:bar], table_from_records[1].tags
|
22
|
-
end
|
23
|
-
|
24
|
-
a = Ruport::Data::Record.new [1,2,3]
|
25
|
-
assert a.respond_to?(:[])
|
26
|
-
b = a.dup
|
27
|
-
b.attributes = %w[col1 col2 col3]
|
28
|
-
tables.zip([[],[],[a],[b]]).each { |t,n| assert_equal n, t.data }
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_ensure_table_creation_allows_record_coercion
|
32
|
-
table = [[1,2,3],[4,5,6],[7,8,9]].to_table
|
33
|
-
table_with_names = [[1,2,3],[4,5,6],[7,8,9]].to_table(%w[a b c])
|
34
|
-
|
35
|
-
a,b,c = nil
|
36
|
-
assert_nothing_raised { a = table.to_a.to_table(%w[a b c]) }
|
37
|
-
assert_nothing_raised { b = table.to_a.to_table(%w[d e f]) }
|
38
|
-
assert_nothing_raised { c = table_with_names.to_a.to_table }
|
39
|
-
|
40
|
-
[a,b,c].each { |t| assert_equal(3,t.length) }
|
41
|
-
assert_equal %w[a b c], a.column_names
|
42
|
-
a.each { |r|
|
43
|
-
assert_equal %w[a b c], r.attributes
|
44
|
-
assert_nothing_raised { r.a; r.b; r.c }
|
45
|
-
[r.a,r.b,r.c].each { |i| assert(i.kind_of?(Numeric)) }
|
46
|
-
}
|
47
|
-
assert_equal %w[d e f], b.column_names
|
48
|
-
b.each { |r|
|
49
|
-
assert_equal %w[d e f], r.attributes
|
50
|
-
assert_nothing_raised { r.d; r.e; r.f }
|
51
|
-
[r.d,r.e,r.f].each { |i| assert(i.kind_of?(Numeric)) }
|
52
|
-
}
|
53
|
-
c.each { |r|
|
54
|
-
assert_nothing_raised { r[0]; r[1]; r[2] }
|
55
|
-
[r[0],r[1],r[2]].each { |i| assert(i.kind_of?(Numeric)) }
|
56
|
-
}
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_sigma
|
60
|
-
table = [[1,2],[3,4],[5,6]].to_table(%w[col1 col2])
|
61
|
-
assert table.respond_to?(:sigma)
|
62
|
-
assert table.respond_to?(:sum)
|
63
|
-
assert_equal(9,table.sigma(0))
|
64
|
-
assert_equal(9,table.sigma("col1"))
|
65
|
-
assert_equal(21,table.sigma { |r| r.col1 + r.col2 })
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_append_record
|
69
|
-
table = Ruport::Data::Table.new :column_names => %w[a b c]
|
70
|
-
table << Ruport::Data::Record.new([1,2,3], :attributes => %w[a b c])
|
71
|
-
assert_equal([1,2,3],table[0].data)
|
72
|
-
assert_equal(%w[a b c],table[0].attributes)
|
73
|
-
rec = table[0].dup
|
74
|
-
rec.attributes = %w[a b c d]
|
75
|
-
assert_raise(ArgumentError) { table << rec }
|
76
|
-
assert_raise(ArgumentError) { table << Object.new }
|
77
|
-
assert_raise(ArgumentError) { table << [].to_table }
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_append_table
|
81
|
-
first = Ruport::Data::Table.new :column_names => %w[a b c],
|
82
|
-
:data => [[1,2,3],[4,5,6]]
|
83
|
-
|
84
|
-
second = Ruport::Data::Table.new :column_names => %w[a b c],
|
85
|
-
:data => [[7,8,9],[10,11,12]]
|
86
|
-
|
87
|
-
combo = first + second
|
88
|
-
|
89
|
-
assert_equal Ruport::Data::Table.new(:column_names => %w[a b c],
|
90
|
-
:data => [[1,2,3],[4,5,6],[7,8,9],[10,11,12]]), combo
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_csv_load
|
94
|
-
table = Ruport::Data::Table.load("test/samples/data.csv")
|
95
|
-
assert_equal %w[col1 col2 col3], table.column_names
|
96
|
-
rows = [%w[a b c],["d",nil,"e"]]
|
97
|
-
table.each { |r| assert_equal rows.shift, r.data
|
98
|
-
assert_equal %w[col1 col2 col3], r.attributes }
|
99
|
-
expected = [%w[1 2 3],%w[4 5 6]].to_table(%w[a b c])
|
100
|
-
|
101
|
-
# ticket:94
|
102
|
-
table = Ruport::Data::Table.load( "test/samples/data.tsv",
|
103
|
-
:csv_options => { :col_sep => "\t" } )
|
104
|
-
assert_equal expected, table
|
105
|
-
|
106
|
-
table = Ruport::Data::Table.load("test/samples/data.csv", :has_names => false)
|
107
|
-
assert_equal([],table.column_names)
|
108
|
-
assert_equal([%w[col1 col2 col3],%w[a b c],["d",nil,"e"]].to_table, table)
|
109
|
-
|
110
|
-
end
|
111
|
-
|
112
|
-
# ticket:76
|
113
|
-
def test_parse
|
114
|
-
|
115
|
-
assert_nothing_raised {
|
116
|
-
Ruport::Data::Table.parse("a,b,c\n1,2,3\n")
|
117
|
-
}
|
118
|
-
|
119
|
-
table = Ruport::Data::Table.parse("a,b,c\n1,2,3\n4,5,6\n")
|
120
|
-
expected = [%w[1 2 3],%w[4 5 6]].to_table(%w[a b c])
|
121
|
-
|
122
|
-
table = Ruport::Data::Table.parse( "a\tb\tc\n1\t2\t3\n4\t5\t6\n",
|
123
|
-
:csv_options => { :col_sep => "\t" } )
|
124
|
-
assert_equal expected, table
|
125
|
-
|
126
|
-
table = Ruport::Data::Table.parse("a,b,c\n1,2,3\n4,5,6\n", :has_names => false)
|
127
|
-
assert_equal([],table.column_names)
|
128
|
-
assert_equal([%w[a b c],%w[1 2 3], %w[4 5 6]].to_table, table)
|
129
|
-
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_csv_block_form
|
133
|
-
expected = [%w[a b],%w[1 2],%w[3 4]]
|
134
|
-
t = Ruport::Data::Table.send(:get_table_from_csv,
|
135
|
-
:parse, "a,b\n1,2\n3,4", :has_names => false) do |s,r|
|
136
|
-
assert_equal expected.shift, r
|
137
|
-
s << r
|
138
|
-
end
|
139
|
-
assert_equal [%w[a b],%w[1 2],%w[3 4]].to_table, t
|
140
|
-
end
|
141
|
-
|
142
|
-
def test_ensure_using_csv_block_mode_works
|
143
|
-
expected = [%w[a b],%w[1 2],%w[3 4]]
|
144
|
-
t = Ruport::Data::Table.parse("a,b\n1,2\n3,4",:has_names => false) { |s,r|
|
145
|
-
assert_equal expected.shift, r
|
146
|
-
s << r
|
147
|
-
}
|
148
|
-
assert_equal [%w[a b],%w[1 2],%w[3 4]].to_table, t
|
149
|
-
x = Ruport::Data::Table.load("test/samples/data.csv") { |s,r|
|
150
|
-
assert_kind_of Ruport::Data::Table, s
|
151
|
-
assert_kind_of Array, r
|
152
|
-
}
|
153
|
-
end
|
154
|
-
|
155
|
-
|
156
|
-
def test_reorder
|
157
|
-
table = Ruport::Data::Table.load("test/samples/data.csv")
|
158
|
-
table.reorder! *%w[col1 col3]
|
159
|
-
assert_equal %w[col1 col3], table.column_names
|
160
|
-
rows = [%w[a c], %w[d e]]
|
161
|
-
table.each { |r| assert_equal rows.shift, r.data
|
162
|
-
assert_equal %w[col1 col3], r.attributes }
|
163
|
-
a = [[1,2,3],[4,5,6]].to_table(%w[a b c]).reorder 2,0
|
164
|
-
rows = [[3,1],[6,4]]
|
165
|
-
a.each { |r| assert_equal rows.shift, r.data
|
166
|
-
assert_equal %w[c a], r.attributes }
|
167
|
-
assert_equal %w[c a], a.column_names
|
168
|
-
|
169
|
-
b = [[1,2,3],[4,5,6]].to_table(%w[a b c]).reorder(%w[a c])
|
170
|
-
rows = [[1,3],[4,6]]
|
171
|
-
b.each { |r|
|
172
|
-
assert_equal rows.shift, r.data
|
173
|
-
assert_equal %w[a c], r.attributes
|
174
|
-
assert_equal b.column_names.object_id,
|
175
|
-
r.instance_eval{@attributes}.object_id
|
176
|
-
}
|
177
|
-
end
|
178
|
-
|
179
|
-
def test_append_column
|
180
|
-
a = [[1,2],[3,4],[5,6]].to_table(%w[a b])
|
181
|
-
a.append_column(:name => "c")
|
182
|
-
assert_equal [[1,2,nil],[3,4,nil],[5,6,nil]].to_table(%w[a b c]), a
|
183
|
-
a = [[1,2],[3,4],[5,6]].to_table
|
184
|
-
a.append_column
|
185
|
-
assert_equal [[1,2,nil],[3,4,nil],[5,6,nil]].to_table, a
|
186
|
-
a = [[1,2],[3,4],[5,6]].to_table(%w[a b])
|
187
|
-
a.append_column(:name => "c",:fill => "x")
|
188
|
-
assert_equal [[1,2,'x'],[3,4,'x'],[5,6,'x']].to_table(%w[a b c]), a
|
189
|
-
a.append_column(:name => "d") { |r| r.to_a.join("|") }
|
190
|
-
assert_equal(
|
191
|
-
[ [1,2,'x','1|2|x'],
|
192
|
-
[3,4,'x',"3|4|x"],
|
193
|
-
[5,6,'x','5|6|x']].to_table(%w[a b c d]), a)
|
194
|
-
|
195
|
-
end
|
196
|
-
|
197
|
-
def test_remove_column
|
198
|
-
a = [[1,2],[3,4],[5,6]].to_table(%w[a b])
|
199
|
-
b = a.dup
|
200
|
-
|
201
|
-
b.remove_column("b")
|
202
|
-
assert_equal [[1],[3],[5]].to_table(%w[a]), b
|
203
|
-
a.append_column(:name => "c")
|
204
|
-
assert_not_equal [[1,2],[3,4],[5,6]].to_table(%w[a b]), a
|
205
|
-
a.remove_column(:name => "c")
|
206
|
-
assert_equal [[1,2],[3,4],[5,6]].to_table(%w[a b]), a
|
207
|
-
assert_raises(ArgumentError){a.remove_column(:name => "frank")}
|
208
|
-
a.remove_column(0)
|
209
|
-
assert_equal [[2],[4],[6]].to_table(%w[b]), a
|
210
|
-
assert_equal %w[b], a.column_names
|
211
|
-
a = [[1,2],[3,4],[5,6]].to_table
|
212
|
-
a.remove_column(0)
|
213
|
-
assert_equal [[2],[4],[6]].to_table, a
|
214
|
-
end
|
215
|
-
|
216
|
-
def test_split
|
217
|
-
table = Ruport::Data::Table.new :column_names => %w[c1 c2 c3]
|
218
|
-
table << ['a',2,3]
|
219
|
-
table << ['d',5,6]
|
220
|
-
table << ['a',4,5]
|
221
|
-
table << ['b',3,4]
|
222
|
-
table << ['d',9,10]
|
223
|
-
|
224
|
-
group = table.split :group => "c1"
|
225
|
-
assert group.respond_to?(:each_group)
|
226
|
-
expected = %w[a d b]
|
227
|
-
|
228
|
-
group.each_group { |g| assert_equal(expected.shift, g) }
|
229
|
-
|
230
|
-
t = table.reorder("c2","c3")
|
231
|
-
|
232
|
-
data = [[t[0],t[2]],[t[1],t[4]],[t[3]]]
|
233
|
-
c1 = Ruport::Data::Record.new data, :attributes => %w[a d b]
|
234
|
-
assert_equal c1.a, group.a.to_a
|
235
|
-
assert_equal c1.d, group.d.to_a
|
236
|
-
assert_equal c1.b, group.b.to_a
|
237
|
-
|
238
|
-
table << ['a',2,7]
|
239
|
-
table << ['d',9,11]
|
240
|
-
|
241
|
-
group = table.split :group => %w[c1 c2]
|
242
|
-
assert group.respond_to?(:each_group)
|
243
|
-
expected = %w[a_2 d_5 a_4 b_3 d_9]
|
244
|
-
|
245
|
-
group.each_group { |g| assert_equal(expected.shift, g) }
|
246
|
-
|
247
|
-
t = table.reorder("c3")
|
248
|
-
data = [[t[0],t[5]],[t[1]],[t[2]],[t[3]],[t[4],t[6]]]
|
249
|
-
|
250
|
-
c1 = Ruport::Data::Record.new data, :attributes => %w[a_2 d_5 a_4 b_3 d_9]
|
251
|
-
|
252
|
-
assert_equal c1.a_2, group.a_2.to_a
|
253
|
-
assert_equal c1.d_5, group.d_5.to_a
|
254
|
-
assert_equal c1.a_4, group.a_4.to_a
|
255
|
-
assert_equal c1.b_3, group.b_3.to_a
|
256
|
-
assert_equal c1.d_9, group.d_9.to_a
|
257
|
-
|
258
|
-
end
|
259
|
-
|
260
|
-
def test_append_chain
|
261
|
-
table = Ruport::Data::Table.new :column_names => %w[a b c]
|
262
|
-
table << [1,2,3] << [4,5,6] << [7,8,9]
|
263
|
-
assert_equal 3, table.length
|
264
|
-
assert_equal 5, table[1].b
|
265
|
-
end
|
266
|
-
|
267
|
-
def test_to_hack
|
268
|
-
table = Ruport::Data::Table.new :column_names => %w[a b],
|
269
|
-
:data => [[1,2],[3,4],[5,6]]
|
270
|
-
assert_equal("a,b\n1,2\n3,4\n5,6\n",table.to_csv)
|
271
|
-
end
|
272
|
-
|
273
|
-
def test_to_set
|
274
|
-
table = Ruport::Data::Table.new :column_names => %w[a b],
|
275
|
-
:data => [[1,2],[3,4],[5,6]]
|
276
|
-
a = table.to_set
|
277
|
-
b = Ruport::Data::Set.new :data => [table[1],table[0],table[2]]
|
278
|
-
|
279
|
-
assert_equal a,b
|
280
|
-
end
|
281
|
-
|
282
|
-
def test_array_hack
|
283
|
-
t = [[1,2],[3,4],[5,6]].to_table
|
284
|
-
assert_instance_of Ruport::Data::Table, t
|
285
|
-
assert_equal [], t.column_names
|
286
|
-
assert_equal Ruport::Data::Record.new([3,4]), t[1]
|
287
|
-
t = [[1,2],[3,4],[5,6]].to_table :column_names => %w[a b]
|
288
|
-
table = Ruport::Data::Table.new :column_names => %w[a b],
|
289
|
-
:data => [[1,2],[3,4],[5,6]]
|
290
|
-
|
291
|
-
assert_equal t, table
|
292
|
-
|
293
|
-
# test short form
|
294
|
-
table2 = [[1,2],[3,4],[5,6]].to_table %w[a b]
|
295
|
-
|
296
|
-
assert_equal table, table2
|
297
|
-
|
298
|
-
end
|
299
|
-
|
300
|
-
def test_ensure_coerce_sum
|
301
|
-
|
302
|
-
s = [["1"],["3"],["5"] ].to_table
|
303
|
-
t = [["1.23"],["1.5"]].to_table
|
304
|
-
|
305
|
-
assert_equal(9,s.sum(0))
|
306
|
-
assert_equal(2.73,t.sum(0))
|
307
|
-
|
308
|
-
end
|
309
|
-
|
310
|
-
def test_table_shortcut
|
311
|
-
self.class.send(:include,Ruport::Data::TableHelper)
|
312
|
-
|
313
|
-
a = table(%w[a b c]) do |t|
|
314
|
-
[[1,2,3],[4,5,6]].each { |r| t << r }
|
315
|
-
end
|
316
|
-
|
317
|
-
assert_equal([[1,2,3],[4,5,6]].to_table(%w[a b c]),a)
|
318
|
-
|
319
|
-
end
|
320
|
-
|
321
|
-
def test_setting_column_names_changes_record_attributes
|
322
|
-
table = Ruport::Data::Table.new :column_names => %w[a b c],
|
323
|
-
:data => [[1,2,3],[4,5,6]]
|
324
|
-
|
325
|
-
assert_equal %w[a b c], table.column_names
|
326
|
-
assert_equal %w[a b c], table.data[0].attributes
|
327
|
-
assert_equal %w[a b c], table.data[1].attributes
|
328
|
-
|
329
|
-
table.column_names = %w[d e f]
|
330
|
-
|
331
|
-
assert_equal %w[d e f], table.column_names
|
332
|
-
assert_equal %w[d e f], table.data[0].attributes
|
333
|
-
assert_equal %w[d e f], table.data[1].attributes
|
334
|
-
end
|
335
|
-
|
336
|
-
end
|