ojo 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +24 -19
- data/Rakefile +8 -0
- data/lib/ojo.rb +1 -0
- data/lib/ojo/comparison.rb +3 -3
- data/lib/ojo/image_magician.rb +1 -1
- data/lib/ojo/manager.rb +6 -1
- data/lib/ojo/output.rb +34 -17
- data/lib/ojo/sorter.rb +39 -0
- data/lib/ojo/version.rb +1 -1
- data/test/demo/demo_test.rb +76 -0
- data/test/test_helper.rb +59 -3
- data/test/unit/comparison_test.rb +34 -28
- data/test/unit/image_magician_test.rb +27 -8
- data/test/unit/manager_test.rb +23 -42
- data/test/unit/output_test.rb +5 -5
- data/test/unit/sorter_test.rb +30 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 618f3f1156655238dadfee25fab6f745dd8f139f
|
4
|
+
data.tar.gz: 14b41142ea5e12eec0546265fbf71aaa216c79dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f707ead3df40588506279ed6aa0e55e43009fe29d5527eb9b484641fc2874fbd5b79ef9827739b06ab52c027a762f2a9842b023261f672485cf58d1d3cd1ff8c
|
7
|
+
data.tar.gz: 0df91c4cf4dded44d9d5e74576943ceda98b6731de2422fa278fa8ba5660be0a51ee6bc34ef2562d769c48dad3e71320d77383898d63b04e45da0361cfadbd90
|
data/README.md
CHANGED
@@ -68,25 +68,30 @@ After both sets of data have been run, the `Ojo` rake task `ojo:compare[branch_1
|
|
68
68
|
#### run
|
69
69
|
|
70
70
|
>> rake ojo:compare[master,login_page_update]
|
71
|
-
|
72
|
-
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
76
|
-
|
|
77
|
-
|
78
|
-
|
|
79
|
-
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
85
|
-
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
71
|
+
|
72
|
+
+---------------------------------------------------------------------------------------------+
|
73
|
+
| Ojo v.1.0.1 |
|
74
|
+
| file location: /path/to/screenshots |
|
75
|
+
| 04/02/2015 |
|
76
|
+
| data sets compared: master & login_page_update |
|
77
|
+
+---------------------------------------------------------------------------------------------+
|
78
|
+
| File | | Magnitude |
|
79
|
+
|--------------------------------------------------------------+---+--------------------------|
|
80
|
+
| current_user.png | F | ████████████████████████ |
|
81
|
+
| user.png | F | █████████████ |
|
82
|
+
| signed_in.png | P | |
|
83
|
+
| test_home.png | P | |
|
84
|
+
| master_only.png | - | |
|
85
|
+
| login_update_only.png | - | |
|
86
|
+
+---------------------------------------------------------------------------------------------+
|
87
|
+
| Results: 2 files were found to be different |
|
88
|
+
| Difference Files at /path/to/screenshots/diff |
|
89
|
+
+---------------------------------------------------------------------------------------------+
|
90
|
+
>> _
|
91
|
+
|
92
|
+
you can see here that not everything passed (or was exactly the same) in each test case. the __user__ and __current_user__ cases did not pass. to investigate, you can look at the _diff_ directory under _/path/to/screenshots/_. you will see what differences were found in each test case.
|
93
|
+
|
94
|
+
the __Magnitude__ column is a relative representation of the number of pixels found that changed between the two screenshots. it only shows relative levels of _failiness_.
|
90
95
|
|
91
96
|
in addition, you can see that there were extra files in each data set. other comparisons are not affected.
|
92
97
|
|
data/Rakefile
CHANGED
@@ -22,6 +22,14 @@ namespace :test do
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
desc 'demo'
|
26
|
+
Rake::TestTask.new :demo do |t|
|
27
|
+
t.libs << '.'
|
28
|
+
t.libs << 'test'
|
29
|
+
t.pattern = 'test/demo/**/*_test.rb'
|
30
|
+
t.verbose = false
|
31
|
+
end
|
32
|
+
|
25
33
|
task :test => %w(test:units test:phantom)
|
26
34
|
|
27
35
|
task :default => :test
|
data/lib/ojo.rb
CHANGED
data/lib/ojo/comparison.rb
CHANGED
@@ -6,7 +6,7 @@ module Ojo
|
|
6
6
|
FileUtils.mkdir_p(File.join(::Ojo.configuration.location, 'diff'))
|
7
7
|
|
8
8
|
all_same = true
|
9
|
-
results = { :location => ::Ojo.configuration.location, :branch_1 => branch_1, :branch_2 => branch_2, :results =>
|
9
|
+
results = { :location => ::Ojo.configuration.location, :branch_1 => branch_1, :branch_2 => branch_2, :results => [] }
|
10
10
|
|
11
11
|
::Ojo::ProgressBar.start({:min => 0, :max => all_files.count, :method => :percent, :step_size => 1})
|
12
12
|
|
@@ -16,8 +16,8 @@ module Ojo
|
|
16
16
|
file_1 = make_comparable_filename(branch_1, file)
|
17
17
|
file_2 = make_comparable_filename(branch_2, file)
|
18
18
|
|
19
|
-
this_same = compare_one_set(file_1, file_2, diff_file)
|
20
|
-
results[:results]
|
19
|
+
this_same, not_same_pixel_count = compare_one_set(file_1, file_2, diff_file)
|
20
|
+
results[:results] << { :same => this_same, :file_1 => file_1, :file_2 => file_2, :not_same_pixel_count => not_same_pixel_count }
|
21
21
|
all_same = all_same && (this_same != false)
|
22
22
|
|
23
23
|
File.delete(diff_file) if this_same
|
data/lib/ojo/image_magician.rb
CHANGED
data/lib/ojo/manager.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Ojo
|
2
2
|
class Manager
|
3
|
+
MAGNITUDE_MAX = 24
|
4
|
+
|
3
5
|
def location
|
4
6
|
puts "Ojo file location: #{::Ojo.configuration.location}"
|
5
7
|
end
|
@@ -42,7 +44,10 @@ module Ojo
|
|
42
44
|
end
|
43
45
|
|
44
46
|
results = ::Ojo::Ojo.new.compare(branch_1, branch_2)
|
45
|
-
::Ojo::
|
47
|
+
sorted_results = ::Ojo::Sorter.new(results[1], MAGNITUDE_MAX).sort
|
48
|
+
|
49
|
+
results[1][:results] = sorted_results
|
50
|
+
::Ojo::Output.new(MAGNITUDE_MAX).display_to_console results[1]
|
46
51
|
end
|
47
52
|
|
48
53
|
end
|
data/lib/ojo/output.rb
CHANGED
@@ -1,27 +1,42 @@
|
|
1
1
|
module Ojo
|
2
2
|
class Output
|
3
3
|
include Collimator::Table
|
4
|
+
attr_reader :magnitude_max
|
5
|
+
|
6
|
+
def initialize(magnitude_max)
|
7
|
+
@magnitude_max = magnitude_max
|
8
|
+
end
|
4
9
|
|
5
10
|
def display_to_console(data)
|
6
11
|
format_table data
|
7
12
|
|
8
13
|
failure_count = 0
|
9
14
|
|
10
|
-
data[:results].
|
11
|
-
|
12
|
-
file_2 = file_basename(data[:results][basename][:file_2])
|
15
|
+
data[:results].each do |result|
|
16
|
+
filename = file_basename(result[:file_1]) || file_basename(result[:file_2])
|
13
17
|
|
14
18
|
color = :blue
|
15
|
-
result_text = '
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
result_text = '-'
|
20
|
+
pixel_count = '-'
|
21
|
+
|
22
|
+
if test_performed?(result)
|
23
|
+
same = result[:same]
|
24
|
+
pixel_count = result[:not_same_pixel_count].to_s
|
25
|
+
color = if same
|
26
|
+
:green
|
27
|
+
else
|
28
|
+
pixel_count.to_i > 3 ? :red : :yellow
|
29
|
+
end
|
30
|
+
unless same
|
31
|
+
if pixel_count == 0
|
32
|
+
pixel_count = 1
|
33
|
+
end
|
34
|
+
end
|
35
|
+
result_text = same ? 'P' : 'F'
|
21
36
|
failure_count += 1 unless same
|
22
37
|
end
|
23
38
|
|
24
|
-
one_row
|
39
|
+
one_row filename, result_text, color, pixel_count
|
25
40
|
end
|
26
41
|
format_table_footer failure_count, data
|
27
42
|
end
|
@@ -49,23 +64,25 @@ module Ojo
|
|
49
64
|
Collimator::Table.header("Ojo v.#{VERSION}")
|
50
65
|
Collimator::Table.header("file location: #{data[:location]}")
|
51
66
|
Collimator::Table.header(Date.today.strftime('%m/%d/%Y'))
|
67
|
+
Collimator::Table.header("data sets compared: #{data[:branch_1]} & #{data[:branch_2]}")
|
52
68
|
end
|
53
69
|
|
54
70
|
def format_table(data)
|
55
71
|
format_table_header data
|
56
72
|
|
57
|
-
Collimator::Table.column(
|
58
|
-
Collimator::Table.column(
|
59
|
-
Collimator::Table.column('
|
73
|
+
Collimator::Table.column('File', :width => 60, :padding => 2, :justification => :left)
|
74
|
+
Collimator::Table.column('', :width => 3, :justification => :center)
|
75
|
+
Collimator::Table.column('Magnitude', :width => @magnitude_max + 1, :padding => 1, :justification => :left)
|
60
76
|
end
|
61
77
|
|
62
|
-
def one_row(
|
78
|
+
def one_row(file, result_text, color, magnitude = 0)
|
63
79
|
max_printable_length = 50
|
80
|
+
bar_character = "\u2588"
|
81
|
+
magnitude_bar = bar_character * (magnitude.to_i > @magnitude_max ? @magnitude_max : magnitude.to_i)
|
64
82
|
|
65
|
-
|
66
|
-
formatted_file_2 = make_printable_name(file_2, max_printable_length)
|
83
|
+
formatted_file = make_printable_name(file, max_printable_length)
|
67
84
|
|
68
|
-
row_data = [
|
85
|
+
row_data = [formatted_file, result_text, magnitude_bar]
|
69
86
|
Collimator::Table.row(:data => row_data, :color => color)
|
70
87
|
end
|
71
88
|
|
data/lib/ojo/sorter.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
module Ojo
|
2
|
+
class Sorter
|
3
|
+
attr_accessor :results
|
4
|
+
attr_reader :magnitude_max
|
5
|
+
|
6
|
+
def initialize(results, magnitude_max)
|
7
|
+
@results = results
|
8
|
+
@magnitude_max = magnitude_max
|
9
|
+
end
|
10
|
+
|
11
|
+
def sort
|
12
|
+
sub_set = @results[:results]
|
13
|
+
sub_set.sort! do |a, b|
|
14
|
+
a_val = a[:not_same_pixel_count] ? a[:not_same_pixel_count] : 0
|
15
|
+
b_val = b[:not_same_pixel_count] ? b[:not_same_pixel_count] : 0
|
16
|
+
b_val <=> a_val
|
17
|
+
end
|
18
|
+
sub_set = scale_not_same_pixel_count(sub_set, magnitude_max)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def scale_not_same_pixel_count(data, max)
|
24
|
+
return data if data.first[:not_same_pixel_count] == 0
|
25
|
+
|
26
|
+
log_scaled_data_points = data.map { |point| Math.log(point[:not_same_pixel_count].to_s.to_f) }.map{ |point| point == -1.0/0.0 ? 0 : point }
|
27
|
+
largest_data_point = log_scaled_data_points.first
|
28
|
+
scale_factor = 1.0 * largest_data_point / max
|
29
|
+
|
30
|
+
new_data = []
|
31
|
+
data.each_with_index do |v, i|
|
32
|
+
modified = v.clone
|
33
|
+
modified[:not_same_pixel_count] = log_scaled_data_points[i] / scale_factor
|
34
|
+
new_data << modified
|
35
|
+
end
|
36
|
+
new_data
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/ojo/version.rb
CHANGED
@@ -0,0 +1,76 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
class DemoTest < Ojo::OjoTestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
create_location_directories
|
7
|
+
@manager = ::Ojo::Manager.new
|
8
|
+
Collimator::ProgressBar.stubs(:put_current_progress)
|
9
|
+
Collimator::ProgressBar.stubs(:complete)
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
remove_location_directories
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_locations
|
17
|
+
@manager.location
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_data_sets
|
21
|
+
@manager.data_sets
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_compare
|
25
|
+
make_some_real_files
|
26
|
+
|
27
|
+
branch_1_name = @branch_1.split('/').last
|
28
|
+
branch_2_name = @branch_2.split('/').last
|
29
|
+
|
30
|
+
@manager.compare branch_1_name, branch_2_name
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_compare__missing_branch_names
|
34
|
+
make_some_real_files
|
35
|
+
|
36
|
+
branch_1_name = @branch_1.split('/').last
|
37
|
+
branch_2_name = @branch_2.split('/').last
|
38
|
+
|
39
|
+
@manager.compare nil, branch_2_name
|
40
|
+
puts ''
|
41
|
+
puts ''
|
42
|
+
|
43
|
+
@manager.compare branch_1_name, nil
|
44
|
+
puts ''
|
45
|
+
puts ''
|
46
|
+
|
47
|
+
branch_1a = File.join(@location, 'branch_1a')
|
48
|
+
FileUtils.mkdir_p(branch_1a)
|
49
|
+
file_1a = File.join(branch_1a, 'test_one.png')
|
50
|
+
generate_one_real_file file_1a
|
51
|
+
|
52
|
+
@manager.compare nil, nil
|
53
|
+
puts ''
|
54
|
+
puts ''
|
55
|
+
|
56
|
+
@manager.compare branch_1_name, branch_2_name
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_compare__missing_files
|
60
|
+
make_some_real_files
|
61
|
+
|
62
|
+
filename = File.join(@branch_1, 'test_two.png')
|
63
|
+
generate_one_real_file filename
|
64
|
+
filename = File.join(@branch_2, 'test_three.png')
|
65
|
+
generate_one_real_file filename
|
66
|
+
|
67
|
+
Collimator::ProgressBar.stubs(:put_current_progress)
|
68
|
+
Collimator::ProgressBar.stubs(:complete)
|
69
|
+
|
70
|
+
branch_1_name = @branch_1.split('/').last
|
71
|
+
branch_2_name = @branch_2.split('/').last
|
72
|
+
|
73
|
+
@manager.compare branch_1_name, branch_2_name
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -51,8 +51,6 @@ module Ojo
|
|
51
51
|
|
52
52
|
im = "convert -size #{size_of_image} xc:white -fill white -stroke red #{shapes_string} #{image_destination}"
|
53
53
|
|
54
|
-
#puts "\nim: #{im}"
|
55
|
-
|
56
54
|
err = nil
|
57
55
|
status = Open4::popen4(im) do |pid, stdin, stdout, stderr|
|
58
56
|
err = stderr.read
|
@@ -61,6 +59,33 @@ module Ojo
|
|
61
59
|
raise "generate image: #{err}" unless status.success?
|
62
60
|
end
|
63
61
|
|
62
|
+
def make_some_real_files
|
63
|
+
file_1 = File.join(@branch_1, 'test_one.png')
|
64
|
+
file_2 = File.join(@branch_2, 'test_one.png')
|
65
|
+
generate_one_real_file file_1
|
66
|
+
generate_one_real_file file_2
|
67
|
+
end
|
68
|
+
|
69
|
+
def make_some_temp_files
|
70
|
+
@temp_diff_location = File.join(::Ojo.configuration.location, 'diff')
|
71
|
+
@temp_diff_filename = File.join(@temp_diff_location, 'some_test_diff.txt')
|
72
|
+
FileUtils.mkdir_p @temp_diff_location
|
73
|
+
File.open(@temp_diff_filename, 'w') { |f| f.write '' }
|
74
|
+
|
75
|
+
@filename_1 = File.join(@branch_1, 'some_test.txt')
|
76
|
+
@filename_2 = File.join(@branch_2, 'some_test.txt')
|
77
|
+
File.open(@filename_1, 'w') { |f| f.write '' }
|
78
|
+
File.open(@filename_2, 'w') { |f| f.write '' }
|
79
|
+
end
|
80
|
+
|
81
|
+
def generate_one_real_file(name)
|
82
|
+
shapes = []
|
83
|
+
shapes << "rectangle 20,0 190,190"
|
84
|
+
shapes << "rectangle 30,10 100,60"
|
85
|
+
|
86
|
+
generate_image_with_shapes(name, '200x200', shapes)
|
87
|
+
end
|
88
|
+
|
64
89
|
def create_location_directories
|
65
90
|
@location = File.absolute_path('../../tmp', __FILE__)
|
66
91
|
@branch_1 = File.join(@location, 'branch_1')
|
@@ -72,6 +97,38 @@ module Ojo
|
|
72
97
|
::Ojo.configuration.location = @location
|
73
98
|
end
|
74
99
|
|
100
|
+
def assert_compare_output(output_string, branch_names)
|
101
|
+
sa = output_string.split("\n")
|
102
|
+
|
103
|
+
assert_match 'Ojo v.', sa[1]
|
104
|
+
assert_match 'file location:', sa[2]
|
105
|
+
assert_match 'data sets compared:', sa[4]
|
106
|
+
assert_match 'File', sa[6]
|
107
|
+
assert_match 'Magnitude', sa[6]
|
108
|
+
assert_match "\e[1;32mtest_one.png\e[0m", sa[8]
|
109
|
+
assert_match "\e[1;32mP\e[0m", sa[8]
|
110
|
+
assert_match 'Results: All Same', sa[10]
|
111
|
+
assert_match 'Difference Files at', sa[11]
|
112
|
+
end
|
113
|
+
|
114
|
+
def assert_compare_output__missing_files(output_string, branch_names)
|
115
|
+
sa = output_string.split("\n")
|
116
|
+
|
117
|
+
assert_match 'Ojo v.', sa[1]
|
118
|
+
assert_match 'file location:', sa[2]
|
119
|
+
assert_match 'data sets compared:', sa[4]
|
120
|
+
assert_match 'File', sa[6]
|
121
|
+
assert_match 'Magnitude', sa[6]
|
122
|
+
# assert_match "\e[1;32mtest_one.png\e[0m", sa[8]
|
123
|
+
# assert_match "\e[1;32mP\e[0m", sa[8]
|
124
|
+
# assert_match "\e[1;34mtest_", sa[9]
|
125
|
+
# assert_match "\e[1;34m-\e[0m", sa[9]
|
126
|
+
# assert_match "\e[1;34mtest_", sa[10]
|
127
|
+
# assert_match "\e[1;34m-\e[0m", sa[10]
|
128
|
+
assert_match 'Results: All Same', sa[12]
|
129
|
+
assert_match 'Difference Files at', sa[13]
|
130
|
+
end
|
131
|
+
|
75
132
|
def remove_location_directories
|
76
133
|
FileUtils.rm_rf Dir[File.join(@location, '*')]
|
77
134
|
end
|
@@ -84,6 +141,5 @@ module Ojo
|
|
84
141
|
ensure
|
85
142
|
$stdout = STDOUT
|
86
143
|
end
|
87
|
-
|
88
144
|
end
|
89
145
|
end
|
@@ -36,12 +36,10 @@ class ComparisonTest < Ojo::OjoTestCase
|
|
36
36
|
assert_equal @location, r[1][:location]
|
37
37
|
assert_equal 'branch_1', r[1][:branch_1]
|
38
38
|
assert_equal 'branch_2', r[1][:branch_2]
|
39
|
-
assert_equal 1, r[1][:results].
|
40
|
-
assert_equal
|
41
|
-
assert_equal
|
42
|
-
assert_equal
|
43
|
-
assert_equal file_2, r[1][:results]['test_one.png'][:file_2]
|
44
|
-
|
39
|
+
assert_equal 1, r[1][:results].count
|
40
|
+
assert_equal true, r[1][:results].first[:same]
|
41
|
+
assert_equal file_1, r[1][:results].first[:file_1]
|
42
|
+
assert_equal file_2, r[1][:results].first[:file_2]
|
45
43
|
end
|
46
44
|
|
47
45
|
def test_comparison__single_file__different
|
@@ -69,11 +67,10 @@ class ComparisonTest < Ojo::OjoTestCase
|
|
69
67
|
assert_equal @location, r[1][:location]
|
70
68
|
assert_equal 'branch_1', r[1][:branch_1]
|
71
69
|
assert_equal 'branch_2', r[1][:branch_2]
|
72
|
-
assert_equal 1, r[1][:results].
|
73
|
-
assert_equal
|
74
|
-
assert_equal
|
75
|
-
assert_equal
|
76
|
-
assert_equal file_2, r[1][:results]['test_one.png'][:file_2]
|
70
|
+
assert_equal 1, r[1][:results].count
|
71
|
+
assert_equal false, r[1][:results].first[:same]
|
72
|
+
assert_equal file_1, r[1][:results].first[:file_1]
|
73
|
+
assert_equal file_2, r[1][:results].first[:file_2]
|
77
74
|
end
|
78
75
|
|
79
76
|
def test_comparison__single_file__different_size
|
@@ -98,11 +95,10 @@ class ComparisonTest < Ojo::OjoTestCase
|
|
98
95
|
assert_equal @location, r[1][:location]
|
99
96
|
assert_equal 'branch_1', r[1][:branch_1]
|
100
97
|
assert_equal 'branch_2', r[1][:branch_2]
|
101
|
-
assert_equal 1, r[1][:results].
|
102
|
-
assert_equal
|
103
|
-
assert_equal
|
104
|
-
assert_equal
|
105
|
-
assert_equal file_2, r[1][:results]['test_one.png'][:file_2]
|
98
|
+
assert_equal 1, r[1][:results].count
|
99
|
+
assert_equal false, r[1][:results].first[:same]
|
100
|
+
assert_equal file_1, r[1][:results].first[:file_1]
|
101
|
+
assert_equal file_2, r[1][:results].first[:file_2]
|
106
102
|
end
|
107
103
|
|
108
104
|
def test_comparison__multiple_files
|
@@ -130,7 +126,7 @@ class ComparisonTest < Ojo::OjoTestCase
|
|
130
126
|
assert_equal @location, r[1][:location]
|
131
127
|
assert_equal 'branch_1', r[1][:branch_1]
|
132
128
|
assert_equal 'branch_2', r[1][:branch_2]
|
133
|
-
assert_equal 3, r[1][:results].
|
129
|
+
assert_equal 3, r[1][:results].count
|
134
130
|
|
135
131
|
file_1_4 = File.join(@branch_1, 'file_four.png')
|
136
132
|
file_2_4 = File.join(@branch_2, 'file_four.png')
|
@@ -143,19 +139,22 @@ class ComparisonTest < Ojo::OjoTestCase
|
|
143
139
|
assert_equal @location, r[1][:location]
|
144
140
|
assert_equal 'branch_1', r[1][:branch_1]
|
145
141
|
assert_equal 'branch_2', r[1][:branch_2]
|
146
|
-
assert_equal 4, r[1][:results].
|
142
|
+
assert_equal 4, r[1][:results].count
|
143
|
+
|
144
|
+
files_tested = get_files_in_test(r[1][:results])
|
145
|
+
|
146
|
+
assert files_tested.include?(file_1_1)
|
147
|
+
assert files_tested.include?(file_1_2)
|
148
|
+
assert files_tested.include?(file_2_1)
|
149
|
+
assert files_tested.include?(file_2_3)
|
150
|
+
assert files_tested.include?(file_1_4)
|
151
|
+
assert files_tested.include?(file_2_4)
|
147
152
|
|
148
|
-
|
149
|
-
assert r[1][:results].keys.include?(File.basename(file_1_2))
|
150
|
-
assert r[1][:results].keys.include?(File.basename(file_2_1))
|
151
|
-
assert r[1][:results].keys.include?(File.basename(file_2_3))
|
152
|
-
assert r[1][:results].keys.include?(File.basename(file_1_4))
|
153
|
-
assert r[1][:results].keys.include?(File.basename(file_2_4))
|
153
|
+
all_results = r[1][:results].map { |r| r[:same] }
|
154
154
|
|
155
|
-
assert_equal
|
156
|
-
assert_equal
|
157
|
-
assert_equal
|
158
|
-
assert_equal false, r[1][:results][File.basename(file_1_4)][:same]
|
155
|
+
assert_equal 1, all_results.count(false)
|
156
|
+
assert_equal 1, all_results.count(true)
|
157
|
+
assert_equal 2, all_results.count(nil)
|
159
158
|
|
160
159
|
diff_location = File.join(Ojo.configuration.location, 'diff')
|
161
160
|
assert_equal 1, Dir[File.join(diff_location, '*.png')].count
|
@@ -165,4 +164,11 @@ class ComparisonTest < Ojo::OjoTestCase
|
|
165
164
|
assert File.exist?(File.join(diff_location, File.basename(file_1_4)))
|
166
165
|
end
|
167
166
|
|
167
|
+
private
|
168
|
+
|
169
|
+
def get_files_in_test(results)
|
170
|
+
file_1_files = results.map { |result| result[:file_1] }
|
171
|
+
file_2_files = results.map { |result| result[:file_2] }
|
172
|
+
file_1_files + file_2_files
|
173
|
+
end
|
168
174
|
end
|
@@ -10,20 +10,39 @@ class ImageMagicianTest < Ojo::OjoTestCase
|
|
10
10
|
raw = raw_string('1', '22', '303', '4044')
|
11
11
|
color_values = @image_magician.send(:get_color_values, raw)
|
12
12
|
|
13
|
-
assert_equal '1',
|
14
|
-
assert_equal '22',
|
15
|
-
assert_equal '303',
|
13
|
+
assert_equal '1', color_values[:red]
|
14
|
+
assert_equal '22', color_values[:green]
|
15
|
+
assert_equal '303', color_values[:blue]
|
16
16
|
assert_equal '4044', color_values[:all]
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_unpack_comparison_result
|
20
20
|
assert @image_magician.unpack_comparison_result(raw_string('0', '0', '0', '0')), 'all colors equal 0'
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
refute
|
25
|
-
|
26
|
-
|
22
|
+
packed = raw_string('123', '234', '345', '456')
|
23
|
+
unpacked = @image_magician.unpack_comparison_result(packed)
|
24
|
+
refute unpacked[0], 'all colors greater than 0'
|
25
|
+
assert_equal 456, unpacked[1]
|
26
|
+
|
27
|
+
packed = raw_string('123', '0', '0', '0')
|
28
|
+
unpacked = @image_magician.unpack_comparison_result(packed)
|
29
|
+
refute unpacked[0], 'red greater than 0'
|
30
|
+
assert_equal 0, unpacked[1]
|
31
|
+
|
32
|
+
packed = raw_string('0', '234', '0', '0')
|
33
|
+
unpacked = @image_magician.unpack_comparison_result(packed)
|
34
|
+
refute unpacked[0], 'green greater than 0'
|
35
|
+
assert_equal 0, unpacked[1]
|
36
|
+
|
37
|
+
packed = raw_string('0', '0', '345', '0')
|
38
|
+
unpacked = @image_magician.unpack_comparison_result(packed)
|
39
|
+
refute unpacked[0], 'blue greater than 0'
|
40
|
+
assert_equal 0, unpacked[1]
|
41
|
+
|
42
|
+
packed = raw_string('0', '0', '0', '456')
|
43
|
+
unpacked = @image_magician.unpack_comparison_result(packed)
|
44
|
+
refute unpacked[0], "'all' greater than 0"
|
45
|
+
assert_equal 456, unpacked[1]
|
27
46
|
end
|
28
47
|
|
29
48
|
private
|
data/test/unit/manager_test.rb
CHANGED
@@ -79,6 +79,29 @@ class ManagerTest < Ojo::OjoTestCase
|
|
79
79
|
assert_compare_output out.string, %w(branch_1 branch_2)
|
80
80
|
end
|
81
81
|
|
82
|
+
def test_compare_missing_files
|
83
|
+
make_some_real_files
|
84
|
+
|
85
|
+
filename = File.join(@branch_1, 'test_two.png')
|
86
|
+
generate_one_real_file filename
|
87
|
+
filename = File.join(@branch_2, 'test_three.png')
|
88
|
+
generate_one_real_file filename
|
89
|
+
|
90
|
+
Collimator::ProgressBar.stubs(:put_current_progress)
|
91
|
+
Collimator::ProgressBar.stubs(:complete)
|
92
|
+
|
93
|
+
branch_1_name = @branch_1.split('/').last
|
94
|
+
branch_2_name = @branch_2.split('/').last
|
95
|
+
|
96
|
+
out = capture_output do
|
97
|
+
Date.stub :today, Date.parse('1/10/2014') do
|
98
|
+
@manager.compare branch_1_name, branch_2_name
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
assert_compare_output__missing_files out.string, %w(branch_1 branch_2)
|
103
|
+
end
|
104
|
+
|
82
105
|
def test_compare__missing_branch_names
|
83
106
|
make_some_real_files
|
84
107
|
Collimator::ProgressBar.stubs(:put_current_progress)
|
@@ -123,48 +146,6 @@ class ManagerTest < Ojo::OjoTestCase
|
|
123
146
|
|
124
147
|
private
|
125
148
|
|
126
|
-
def assert_compare_output(output_string, branch_names)
|
127
|
-
sa = output_string.split("\n")
|
128
|
-
|
129
|
-
assert_equal '+-----------------------------------------------------------------------------------------------------------------------------------------+', sa[0]
|
130
|
-
assert_match 'Ojo v.', sa[1]
|
131
|
-
assert_match 'file location:', sa[2]
|
132
|
-
assert_equal '| 10/01/2014 |', sa[3]
|
133
|
-
assert_equal '+-----------------------------------------------------------------------------------------------------------------------------------------+', sa[4]
|
134
|
-
assert_match branch_names.first, sa[5]
|
135
|
-
assert_match branch_names.last, sa[5]
|
136
|
-
assert_equal '|--------------------------------------------------------------+--------------------------------------------------------------+-----------|', sa[6]
|
137
|
-
assert_equal "| \e[1;32mtest_one.png\e[0m | \e[1;32mtest_one.png\e[0m | \e[1;32mPASS\e[0m |", sa[7]
|
138
|
-
assert_equal '+-----------------------------------------------------------------------------------------------------------------------------------------+', sa[8]
|
139
|
-
assert_equal '| Results: All Same |', sa[9]
|
140
|
-
assert_match 'Difference Files at', sa[10]
|
141
|
-
assert_equal '+-----------------------------------------------------------------------------------------------------------------------------------------+', sa[11]
|
142
|
-
end
|
143
|
-
|
144
|
-
def make_some_real_files
|
145
|
-
file_1 = File.join(@branch_1, 'test_one.png')
|
146
|
-
file_2 = File.join(@branch_2, 'test_one.png')
|
147
|
-
generate_one_real_file file_1
|
148
|
-
generate_one_real_file file_2
|
149
|
-
end
|
150
|
-
|
151
|
-
def generate_one_real_file(name)
|
152
|
-
shapes = []
|
153
|
-
shapes << "rectangle 20,0 190,190"
|
154
|
-
shapes << "rectangle 30,10 100,60"
|
155
149
|
|
156
|
-
generate_image_with_shapes(name, '200x200', shapes)
|
157
|
-
end
|
158
|
-
|
159
|
-
def make_some_temp_files
|
160
|
-
@temp_diff_location = File.join(Ojo.configuration.location, 'diff')
|
161
|
-
@temp_diff_filename = File.join(@temp_diff_location, 'some_test_diff.txt')
|
162
|
-
FileUtils.mkdir_p @temp_diff_location
|
163
|
-
File.open(@temp_diff_filename, 'w') { |f| f.write '' }
|
164
150
|
|
165
|
-
@filename_1 = File.join(@branch_1, 'some_test.txt')
|
166
|
-
@filename_2 = File.join(@branch_2, 'some_test.txt')
|
167
|
-
File.open(@filename_1, 'w') { |f| f.write '' }
|
168
|
-
File.open(@filename_2, 'w') { |f| f.write '' }
|
169
|
-
end
|
170
151
|
end
|
data/test/unit/output_test.rb
CHANGED
@@ -3,7 +3,7 @@ require_relative '../test_helper'
|
|
3
3
|
class OutputTest < Ojo::OjoTestCase
|
4
4
|
|
5
5
|
def test_not_too_long
|
6
|
-
s = ::Ojo::Output.new.send(:make_printable_name, 'Geordie', 10)
|
6
|
+
s = ::Ojo::Output.new(24).send(:make_printable_name, 'Geordie', 10)
|
7
7
|
assert_equal 7, s.length
|
8
8
|
assert_equal 'Geordie', s
|
9
9
|
end
|
@@ -11,28 +11,28 @@ class OutputTest < Ojo::OjoTestCase
|
|
11
11
|
def test_too_long_filename__even_max_odd_string
|
12
12
|
max_length = 10
|
13
13
|
starting_string = 'SomeOddNumberOfCharactersInThisString'
|
14
|
-
s = ::Ojo::Output.new.send(:make_printable_name, starting_string, max_length)
|
14
|
+
s = ::Ojo::Output.new(24).send(:make_printable_name, starting_string, max_length)
|
15
15
|
assert_equal 'Som....ing', s
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_too_long_filename__even_max_even_string
|
19
19
|
max_length = 10
|
20
20
|
starting_string = 'SomeEvenNumberOfCharactersInThisString'
|
21
|
-
s = ::Ojo::Output.new.send(:make_printable_name, starting_string, max_length)
|
21
|
+
s = ::Ojo::Output.new(24).send(:make_printable_name, starting_string, max_length)
|
22
22
|
assert_equal 'Som....ng', s
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_too_long_filename__odd_max_odd_string
|
26
26
|
max_length = 11
|
27
27
|
starting_string = 'SomeOddNumberOfCharactersInThisString'
|
28
|
-
s = ::Ojo::Output.new.send(:make_printable_name, starting_string, max_length)
|
28
|
+
s = ::Ojo::Output.new(24).send(:make_printable_name, starting_string, max_length)
|
29
29
|
assert_equal 'Som....ing', s
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_too_long_filename__odd_max_even_string
|
33
33
|
max_length = 11
|
34
34
|
starting_string = 'SomeEvenNumberOfCharactersInThisString'
|
35
|
-
s = ::Ojo::Output.new.send(:make_printable_name, starting_string, max_length)
|
35
|
+
s = ::Ojo::Output.new(24).send(:make_printable_name, starting_string, max_length)
|
36
36
|
assert_equal 'Some....ing', s
|
37
37
|
end
|
38
38
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
class SorterTest < Ojo::OjoTestCase
|
4
|
+
|
5
|
+
def test_sort_results
|
6
|
+
results = {:results => [
|
7
|
+
{ :same => true, :file_1 => 'full_1/file_1', :file_2 => 'full_1/file_2', :not_same_pixel_count => 0 },
|
8
|
+
{ :same => false, :file_1 => 'full_2/file_1', :file_2 => 'full_2/file_2', :not_same_pixel_count => 31 },
|
9
|
+
{ :same => false, :file_1 => 'full_3/file_1', :file_2 => 'full_3/file_2', :not_same_pixel_count => 12 },
|
10
|
+
{ :same => false, :file_1 => 'full_4/file_1', :file_2 => 'full_4/file_2', :not_same_pixel_count => 55 },
|
11
|
+
{ :same => true, :file_1 => 'full_5/file_1', :file_2 => 'full_5/file_2', :not_same_pixel_count => 0 },
|
12
|
+
{ :same => false, :file_1 => 'full_6/file_1', :file_2 => 'full_6/file_2', :not_same_pixel_count => 33 },
|
13
|
+
{ :same => false, :file_1 => 'full_7/file_1', :file_2 => 'full_7/file_2', :not_same_pixel_count => 100 },
|
14
|
+
{ :same => true, :file_1 => 'full_8/file_1', :file_2 => 'full_8/file_2', :not_same_pixel_count => 0 },
|
15
|
+
{ :same => false, :file_1 => 'full_9/file_1', :file_2 => 'full_9/file_2', :not_same_pixel_count => 63 }
|
16
|
+
]
|
17
|
+
}
|
18
|
+
|
19
|
+
expected_sorted_order = %w(full_7 full_9 full_4 full_6 full_2 full_3)
|
20
|
+
|
21
|
+
sorter = ::Ojo::Sorter.new(results, 24)
|
22
|
+
sorted_results = sorter.sort
|
23
|
+
|
24
|
+
assert_equal results[:results].count, sorted_results.count
|
25
|
+
|
26
|
+
expected_sorted_order.each_with_index do |file, i|
|
27
|
+
assert_match file, sorted_results[i][:file_1]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ojo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- geordie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02
|
11
|
+
date: 2015-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -91,9 +91,11 @@ files:
|
|
91
91
|
- lib/ojo/output.rb
|
92
92
|
- lib/ojo/rails/engine.rb
|
93
93
|
- lib/ojo/screenshot.rb
|
94
|
+
- lib/ojo/sorter.rb
|
94
95
|
- lib/ojo/version.rb
|
95
96
|
- lib/tasks/ojo.rake
|
96
97
|
- ojo.gemspec
|
98
|
+
- test/demo/demo_test.rb
|
97
99
|
- test/page_objects.rb
|
98
100
|
- test/page_objects/test_app/index_page.rb
|
99
101
|
- test/page_objects/test_app/test_app_page.rb
|
@@ -119,6 +121,7 @@ files:
|
|
119
121
|
- test/unit/image_magician_test.rb
|
120
122
|
- test/unit/manager_test.rb
|
121
123
|
- test/unit/output_test.rb
|
124
|
+
- test/unit/sorter_test.rb
|
122
125
|
homepage: ''
|
123
126
|
licenses:
|
124
127
|
- MIT
|
@@ -144,6 +147,7 @@ signing_key:
|
|
144
147
|
specification_version: 4
|
145
148
|
summary: ojo is the eyes of the appearance test
|
146
149
|
test_files:
|
150
|
+
- test/demo/demo_test.rb
|
147
151
|
- test/page_objects.rb
|
148
152
|
- test/page_objects/test_app/index_page.rb
|
149
153
|
- test/page_objects/test_app/test_app_page.rb
|
@@ -169,3 +173,4 @@ test_files:
|
|
169
173
|
- test/unit/image_magician_test.rb
|
170
174
|
- test/unit/manager_test.rb
|
171
175
|
- test/unit/output_test.rb
|
176
|
+
- test/unit/sorter_test.rb
|