coopy 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,126 @@
1
+ require 'test/unit'
2
+ require 'coopy'
3
+ require 'tmpdir'
4
+ require 'fileutils'
5
+
6
+ class CoopyTest < Test::Unit::TestCase
7
+ def initialize(*args)
8
+ super(*args)
9
+ odir = File.dirname(__FILE__)
10
+ @broken_bridges = File.join(odir,"broken_bridges.sqlite")
11
+ @bridges = File.join(odir,"bridges.sqlite")
12
+ @dir = nil
13
+ end
14
+
15
+ def setup
16
+ @dir = Dir.mktmpdir
17
+ @ct = 0
18
+ @output = ""
19
+ new_output
20
+ end
21
+
22
+ def teardown
23
+ FileUtils.remove_entry_secure @dir
24
+ @dir = nil
25
+ end
26
+
27
+ def new_output
28
+ @ct = @ct+1
29
+ tmp = @output
30
+ @output = File.join(@dir,"output#{@ct}.txt")
31
+ tmp
32
+ end
33
+
34
+ def cp(src,key)
35
+ target = File.join(@dir,"#{key}.sqlite")
36
+ FileUtils.cp src, target
37
+ target
38
+ end
39
+
40
+ def read(fname)
41
+ begin
42
+ File.open(fname,"r") do |f|
43
+ return f.read
44
+ end
45
+ rescue
46
+ return ""
47
+ end
48
+ end
49
+
50
+ def diff(*argv)
51
+ Coopy.diff(["--output",@output] + argv)
52
+ new_output
53
+ end
54
+
55
+ def rediff(*argv)
56
+ Coopy.rediff(["--output",@output] + argv)
57
+ new_output
58
+ end
59
+
60
+ def patch(*argv)
61
+ Coopy.patch(argv)
62
+ end
63
+
64
+ def assert_rows_equal(x1,x2)
65
+ txt = read(diff("--format","stats",x1,x2))
66
+ assert_match(/row,insert,0$/,txt)
67
+ assert_match(/row,delete,0$/,txt)
68
+ assert_match(/row,update,0$/,txt)
69
+ end
70
+
71
+ def assert_rows_unequal(x1,x2)
72
+ txt = read(diff("--format","stats",x1,x2))
73
+ assert_match(/row,((insert)|(delete)|(update)),[^0]/,txt)
74
+ end
75
+
76
+ def test_basic_stats
77
+ txt = read(diff("--format","stats",@broken_bridges,@bridges))
78
+ assert_match(/row,insert,1$/,txt)
79
+ assert_match(/row,delete,1$/,txt)
80
+ assert_match(/row,update,1$/,txt)
81
+ end
82
+
83
+ def test_basic_csv
84
+ txt = read(diff("--format","csv",@broken_bridges,@bridges))
85
+ assert_match(/,/,txt)
86
+ assert_no_match(/<tr/,txt)
87
+ end
88
+
89
+ def test_basic_html
90
+ txt = read(diff("--format","html",@broken_bridges,@bridges))
91
+ assert_match(/<tr/,txt)
92
+ end
93
+
94
+ def test_basic_apply
95
+ v1 = cp(@broken_bridges,"v1")
96
+ v2 = cp(@bridges,"v2")
97
+ assert_rows_unequal(v1,v2)
98
+ diff("--format","apply",v1,v2)
99
+ assert_rows_equal(v1,v2)
100
+ end
101
+
102
+ def diff_patch(b1,b2)
103
+ v1 = cp(b1,"v1")
104
+ v2 = cp(b2,"v2")
105
+ @diff = diff(v1,v2)
106
+ assert_rows_unequal(v1,v2)
107
+ patch(v1,@diff)
108
+ assert_rows_equal(v1,v2)
109
+ end
110
+
111
+ def test_basic_diff_patch
112
+ diff_patch(@broken_bridges,@bridges)
113
+ end
114
+
115
+ def test_reverse_diff_patch
116
+ diff_patch(@bridges,@broken_bridges)
117
+ end
118
+
119
+ def test_basic_rediff
120
+ v1 = cp(@broken_bridges,"v1")
121
+ v2 = cp(@bridges,"v2")
122
+ @diff = diff(v1,v2)
123
+ @diff2 = rediff(@diff)
124
+ assert_equal read(@diff), read(@diff2)
125
+ end
126
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: coopy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.4
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Paul Fitzpatrick
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sqlite3
16
+ requirement: &18788660 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *18788660
25
+ description: Data diffs/patches
26
+ email: paul@robotrebuilt.com
27
+ executables:
28
+ - sqlite_diff
29
+ - sqlite_patch
30
+ - sqlite_rediff
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - Rakefile
35
+ - lib/coopy.rb
36
+ - lib/coopy/diff_render_html.rb
37
+ - lib/coopy/diff_render_log.rb
38
+ - lib/coopy/sql_compare.rb
39
+ - lib/coopy/sequel_sql_wrapper.rb
40
+ - lib/coopy/diff_apply_sql.rb
41
+ - lib/coopy/diff_parser.rb
42
+ - lib/coopy/sqlite_sql_wrapper.rb
43
+ - lib/coopy/scraperwiki_utils.rb
44
+ - lib/coopy/diff_output_stats.rb
45
+ - lib/coopy/diff_output_tdiff.rb
46
+ - lib/coopy/dbi_sql_wrapper.rb
47
+ - lib/coopy/diff_render_csv.rb
48
+ - lib/coopy/diff_output_group.rb
49
+ - lib/coopy/diff_output_table.rb
50
+ - lib/coopy/row_change.rb
51
+ - lib/coopy/diff_output_raw.rb
52
+ - lib/coopy/diff_output.rb
53
+ - lib/coopy/scraperwiki_sql_wrapper.rb
54
+ - lib/coopy/diff_columns.rb
55
+ - lib/coopy/sql_wrapper.rb
56
+ - lib/coopy/diff_output_action.rb
57
+ - bin/sqlite_diff
58
+ - bin/sqlite_rediff
59
+ - bin/sqlite_patch
60
+ - test/test_coopy.rb
61
+ homepage: http://share.find.coop/
62
+ licenses: []
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 1.8.11
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Coopy!
85
+ test_files:
86
+ - test/test_coopy.rb