fitting 2.11.0 → 2.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9fe2c40a89499b32b2a4989a88cb8d294c420191
4
- data.tar.gz: cd0deaa0b1fb6003bc6c58054def0843fa22e656
3
+ metadata.gz: 8234af5ba817adef5ce3ff1bf03d4e84c7747169
4
+ data.tar.gz: c8a247c8467765022ef0f5f2c7b58b669464cdaf
5
5
  SHA512:
6
- metadata.gz: 1e2e177b230a274a1e53d2eb525f6f59f89ffcdcc9ae4392183f0021ae727f3a4d48499dd870bf853ea49a21d7eeec00c9196f1659506348d14dae07287688e3
7
- data.tar.gz: a4ae0ec1d99a3f6b9d9e9fd10bcdeaf592be1335ada092481dece76250da9caa5f4f3cf084d290f792bb16fa897fe361a0967c4c739f918fcedb53a4e8d3bac9
6
+ metadata.gz: 00863f51cc9692a16ce6cb24aaf83309c4490daac1430081e45081e3c5d24dfe6dba0e17b1df659f3ee84a0b1e49ecaa8c76a1ef5bfc301a70752db6beeafe18
7
+ data.tar.gz: fda881919cf0c1bef0ed9228a8d450e866e234da599822f843bed76a146b02ebc143d85d87bda60c294603066a98c4179f9e7dc27162f7b91489eb9d9b90563f
@@ -1,5 +1,10 @@
1
1
  # Change log
2
2
 
3
+ ### 2.12.0 - 2019-09-10
4
+
5
+ * features
6
+ * Add l size (for cover oneOf in json-schema) in rake tasks fitting:documentation_responses, fitting:documentation_responses_error
7
+
3
8
  ### 2.11.0 - 2019-09-09
4
9
 
5
10
  * features
data/README.md CHANGED
@@ -154,6 +154,11 @@ new json-schema: {"$schema"=>"http://json-schema.org/draft-04/schema#", "type"=>
154
154
  In addition to the previous comand, you will learn the coverage(enum) json-schemas with task `rake fitting:documentation_responses[m]`
155
155
  For details `rake fitting:documentation_responses_error[m]`
156
156
 
157
+ ### l size
158
+
159
+ In addition to the previous comand, you will learn the coverage(oneOf) json-schemas with task `rake fitting:documentation_responses[l]`
160
+ For details `rake fitting:documentation_responses_error[l]`
161
+
157
162
  ## Check tests cover
158
163
 
159
164
  ### xs size
@@ -0,0 +1,30 @@
1
+ module Fitting
2
+ class Cover
3
+ class JSONSchemaOneOf
4
+ def initialize(json_schema)
5
+ @json_schema = json_schema
6
+ end
7
+
8
+ def combi
9
+ @combinations = []
10
+
11
+ return @combinations unless @json_schema['oneOf'] || @json_schema['allOf']
12
+
13
+ if @json_schema['oneOf']
14
+ one_of = @json_schema.delete("oneOf")
15
+ one_of.each_index do |index|
16
+ @combinations.push([@json_schema.merge(one_of[index]), ['one_of', "properties.#{index}"]])
17
+ end
18
+ elsif @json_schema['allOf']
19
+ all_of = @json_schema.delete("allOf")
20
+ one_of = all_of[0].delete("oneOf")
21
+ one_of.each_index do |index|
22
+ @combinations.push([@json_schema.merge(one_of[index]), ['one_of', "properties.#{index}"]])
23
+ end
24
+ end
25
+
26
+ @combinations
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,6 +1,7 @@
1
1
  require 'json-schema'
2
2
  require 'fitting/cover/json_schema'
3
3
  require 'fitting/cover/json_schema_enum'
4
+ require 'fitting/cover/json_schema_one_of'
4
5
  require 'fitting/records/unit/combination'
5
6
 
6
7
  module Fitting
@@ -51,6 +52,19 @@ module Fitting
51
52
  @combinations_with_enum
52
53
  end
53
54
 
55
+ def combinations_with_one_of
56
+ return @combinations_with_one_of if @combinations_with_one_of
57
+ @combinations_with_one_of = []
58
+ qwe = Fitting::Cover::JSONSchema.new(@json_schema).combi + Fitting::Cover::JSONSchemaEnum.new(@json_schema).combi + Fitting::Cover::JSONSchemaOneOf.new(@json_schema).combi
59
+ qwe.map do |comb|
60
+ @combinations_with_one_of.push(Fitting::Records::Unit::Combination.new(
61
+ comb,
62
+ bodies
63
+ ))
64
+ end
65
+ @combinations_with_one_of
66
+ end
67
+
54
68
  def cover
55
69
  @cover ||= if bodies == []
56
70
  0
@@ -74,6 +88,18 @@ module Fitting
74
88
  (count + 1) * 100 / (combinations_with_enum.size + 1)
75
89
  end
76
90
  end
91
+
92
+ def cover_one_of
93
+ @cover_one_of ||= if bodies == []
94
+ 0
95
+ else
96
+ count = 0
97
+ combinations_with_one_of.map do |combination|
98
+ count += 1 unless combination.valid_bodies == []
99
+ end
100
+ (count + 1) * 100 / (combinations_with_one_of.size + 1)
101
+ end
102
+ end
77
103
  end
78
104
  end
79
105
  end
@@ -0,0 +1,27 @@
1
+ module Fitting
2
+ class Statistics
3
+ class CoverErrorOneOf
4
+ def initialize(request_unit)
5
+ @request_unit = request_unit
6
+ end
7
+
8
+ def to_s
9
+ res = ''
10
+ @request_unit.map do |request|
11
+ request.responses.map do |response|
12
+ next unless response.tested_bodies != []
13
+ response.json_schemas.map do |json_schema|
14
+ json_schema.combinations_with_one_of.map do |combination|
15
+ next unless combination.valid_bodies == []
16
+ res += "request method: #{request.method}\nrequest path: #{request.path}\n"\
17
+ "response status: #{response.status}\nsource json-schema: #{json_schema.json_schema}\n"\
18
+ "combination: #{combination.description}\nnew json-schema: #{combination.json_schema}\n\n"
19
+ end
20
+ end
21
+ end
22
+ end
23
+ res
24
+ end
25
+ end
26
+ end
27
+ end
@@ -45,6 +45,8 @@ module Fitting
45
45
  res.push("#{json_schema.cover}% #{response.status}")
46
46
  elsif @depth == 'cover_enum'
47
47
  res.push("#{json_schema.cover_enum}% #{response.status}")
48
+ elsif @depth == 'cover_one_of'
49
+ res.push("#{json_schema.cover_one_of}% #{response.status}")
48
50
  end
49
51
  end
50
52
  end
@@ -0,0 +1,92 @@
1
+ module Fitting
2
+ class Statistics
3
+ class MeasurementCoverOneOf
4
+ attr_reader :requests, :all_responses, :cover_responses, :not_cover_responses, :max_response_path,
5
+ :coverage_fully, :coverage_non, :coverage_partially, :not_covered_responses
6
+
7
+ def initialize(requests)
8
+ @requests = requests
9
+ @all_responses = 0
10
+ @cover_responses = 0
11
+ @not_cover_responses = 0
12
+ @max_response_path = 0
13
+ @coverage_fully = []
14
+ @coverage_non = []
15
+ @coverage_partially = []
16
+ @not_covered_responses = []
17
+ check_responses
18
+ end
19
+
20
+ def check_responses
21
+ return if @ready
22
+
23
+ @requests.map do |request|
24
+ chech_request(request)
25
+ end
26
+
27
+ @ready = true
28
+ end
29
+
30
+ private
31
+
32
+ def chech_request(request)
33
+ check_cover(request)
34
+ coverage_push(request)
35
+
36
+ @max_response_path = request.path.to_s.size / 8 if request.path.to_s.size / 8 > @max_response_path
37
+ request.responses.map do |response|
38
+ check_response(response, request)
39
+ end
40
+ end
41
+
42
+ def check_response(response, request)
43
+ json_schema_index = 0
44
+ response.json_schemas.map do |json_schema|
45
+ json_schema_index = check_json_schema(json_schema, request, response, json_schema_index)
46
+ end
47
+ end
48
+
49
+ def check_json_schema(json_schema, request, response, json_schema_index)
50
+ if json_schema.cover_one_of != 100
51
+ @not_cover_responses += 1
52
+ @not_covered_responses.push("#{request.method}\t#{request.path} #{response.status} #{json_schema_index}")
53
+ else
54
+ @cover_responses += 1
55
+ end
56
+ @all_responses += 1
57
+ json_schema_index + 1
58
+ end
59
+
60
+ def coverage_push(request)
61
+ if @all == @cover
62
+ @coverage_fully.push(request)
63
+ elsif @all == @not_cover
64
+ @coverage_non.push(request)
65
+ else
66
+ @coverage_partially.push(request)
67
+ end
68
+ end
69
+
70
+ def check_cover(request)
71
+ @all = 0
72
+ @cover = 0
73
+ @not_cover = 0
74
+
75
+ request.responses.map do |response|
76
+ response.json_schemas.map do |json_schema|
77
+ count_cover(json_schema)
78
+ end
79
+ end
80
+ end
81
+
82
+ def count_cover(json_schema)
83
+ @all += 1
84
+ if json_schema.cover_one_of != 100
85
+ @not_cover += 1
86
+ else
87
+ @cover += 1
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -3,6 +3,7 @@ require 'fitting/statistics/analysis'
3
3
  require 'fitting/statistics/measurement'
4
4
  require 'fitting/statistics/measurement_cover'
5
5
  require 'fitting/statistics/measurement_cover_enum'
6
+ require 'fitting/statistics/measurement_cover_one_of'
6
7
  require 'fitting/records/unit/request'
7
8
  require 'fitting/storage/white_list'
8
9
  require 'fitting/records/documented/request'
@@ -53,6 +54,8 @@ module Fitting
53
54
  Fitting::Statistics::MeasurementCover.new(white_unit)
54
55
  elsif @depth == 'cover_enum'
55
56
  Fitting::Statistics::MeasurementCoverEnum.new(white_unit)
57
+ elsif @depth == 'cover_one_of'
58
+ Fitting::Statistics::MeasurementCoverOneOf.new(white_unit)
56
59
  end
57
60
  end
58
61
 
@@ -64,6 +67,8 @@ module Fitting
64
67
  Fitting::Statistics::MeasurementCover.new(black_unit)
65
68
  elsif @depth == 'cover_enum'
66
69
  Fitting::Statistics::MeasurementCoverEnum.new(black_unit)
70
+ elsif @depth == 'cover_one_of'
71
+ Fitting::Statistics::MeasurementCoverOneOf.new(black_unit)
67
72
  end
68
73
  end
69
74
 
@@ -0,0 +1,50 @@
1
+ require 'fitting/statistics/cover_error_one_of'
2
+ require 'fitting/records/unit/request'
3
+ require 'fitting/storage/white_list'
4
+ require 'fitting/records/documented/request'
5
+
6
+ module Fitting
7
+ class Statistics
8
+ class TemplateCoverErrorOneOf
9
+ def initialize(tested_requests, config)
10
+ @tested_requests = tested_requests
11
+ @config = config
12
+ end
13
+
14
+ def stats
15
+ "#{white_statistics}\n\n"
16
+ end
17
+
18
+ def white_statistics
19
+ @white_statistics ||= Fitting::Statistics::CoverErrorOneOf.new(white_unit)
20
+ end
21
+
22
+ def white_unit
23
+ @white_unit_requests ||= documented_requests_white.inject([]) do |res, documented_request|
24
+ res.push(Fitting::Records::Unit::Request.new(documented_request, @tested_requests))
25
+ end
26
+ end
27
+
28
+ def documented_requests_white
29
+ @documented_requests_white ||= documented.find_all(&:white)
30
+ end
31
+
32
+ def documented
33
+ @documented_requests ||= @config.tomogram.to_a.inject([]) do |res, tomogram_request|
34
+ res.push(Fitting::Records::Documented::Request.new(tomogram_request, white_list.to_a))
35
+ end
36
+ end
37
+
38
+ def white_list
39
+ @white_list ||= Fitting::Storage::WhiteList.new(
40
+ @config.prefix,
41
+ @config.white_list,
42
+ @config.resource_white_list,
43
+ @config.include_resources,
44
+ @config.include_actions,
45
+ @config.tomogram.to_resources
46
+ )
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,3 +1,3 @@
1
1
  module Fitting
2
- VERSION = '2.11.0'.freeze
2
+ VERSION = '2.12.0'.freeze
3
3
  end
@@ -4,8 +4,10 @@ require 'fitting/records/realized_unit'
4
4
  require 'fitting/templates/realized_template'
5
5
  require 'fitting/statistics/template_cover_error'
6
6
  require 'fitting/statistics/template_cover_error_enum'
7
+ require 'fitting/statistics/template_cover_error_one_of'
7
8
 
8
9
  namespace :fitting do
10
+ # deprecated
9
11
  desc 'Fitting documentation'
10
12
  task :documentation do
11
13
  documented_unit = Fitting::Statistics::Template.new(
@@ -53,12 +55,24 @@ namespace :fitting do
53
55
  )
54
56
  puts documented_unit.stats
55
57
 
58
+ unless documented_unit.not_covered == "\n"
59
+ puts 'Not all responses from the whitelist are covered!'
60
+ exit 1
61
+ end
62
+ elsif args.size == 'l'
63
+ documented_unit = Fitting::Statistics::Template.new(
64
+ Fitting::Records::Spherical::Requests.new,
65
+ Fitting.configuration,
66
+ 'cover_one_of'
67
+ )
68
+ puts documented_unit.stats
69
+
56
70
  unless documented_unit.not_covered == "\n"
57
71
  puts 'Not all responses from the whitelist are covered!'
58
72
  exit 1
59
73
  end
60
74
  else
61
- puts 'need key xs, s or m'
75
+ puts 'need key xs, s, m or l'
62
76
  end
63
77
  end
64
78
 
@@ -76,11 +90,18 @@ namespace :fitting do
76
90
  Fitting.configuration
77
91
  )
78
92
  puts documented_unit.stats
93
+ elsif args.size == 'l'
94
+ documented_unit = Fitting::Statistics::TemplateCoverErrorOneOf.new(
95
+ Fitting::Records::Spherical::Requests.new,
96
+ Fitting.configuration
97
+ )
98
+ puts documented_unit.stats
79
99
  else
80
- puts 'need key s or m'
100
+ puts 'need key s, m or l'
81
101
  end
82
102
  end
83
103
 
104
+ # deprecated
84
105
  desc 'Fitting tests'
85
106
  task :tests do
86
107
  realized_unit = Fitting::Records::RealizedUnit.new(
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fitting
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.11.0
4
+ version: 2.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - d.efimov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-08 00:00:00.000000000 Z
11
+ date: 2019-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema
@@ -198,6 +198,7 @@ files:
198
198
  - lib/fitting/configuration/yaml.rb
199
199
  - lib/fitting/cover/json_schema.rb
200
200
  - lib/fitting/cover/json_schema_enum.rb
201
+ - lib/fitting/cover/json_schema_one_of.rb
201
202
  - lib/fitting/cover/response.rb
202
203
  - lib/fitting/documentation.rb
203
204
  - lib/fitting/matchers/response_matcher.rb
@@ -221,12 +222,14 @@ files:
221
222
  - lib/fitting/statistics/analysis.rb
222
223
  - lib/fitting/statistics/cover_error.rb
223
224
  - lib/fitting/statistics/cover_error_enum.rb
225
+ - lib/fitting/statistics/cover_error_one_of.rb
224
226
  - lib/fitting/statistics/great.rb
225
227
  - lib/fitting/statistics/list.rb
226
228
  - lib/fitting/statistics/lists.rb
227
229
  - lib/fitting/statistics/measurement.rb
228
230
  - lib/fitting/statistics/measurement_cover.rb
229
231
  - lib/fitting/statistics/measurement_cover_enum.rb
232
+ - lib/fitting/statistics/measurement_cover_one_of.rb
230
233
  - lib/fitting/statistics/not_covered_responses.rb
231
234
  - lib/fitting/statistics/percent.rb
232
235
  - lib/fitting/statistics/requests_stats.rb
@@ -234,6 +237,7 @@ files:
234
237
  - lib/fitting/statistics/template.rb
235
238
  - lib/fitting/statistics/template_cover_error.rb
236
239
  - lib/fitting/statistics/template_cover_error_enum.rb
240
+ - lib/fitting/statistics/template_cover_error_one_of.rb
237
241
  - lib/fitting/storage/responses.rb
238
242
  - lib/fitting/storage/white_list.rb
239
243
  - lib/fitting/templates/realized_template.rb