mumuki-sqlite-runner 3.1.0 → 3.2.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
  SHA256:
3
- metadata.gz: e971b83ccdad28673f28cfa2ee6c40721ef5584e25d6d15e5ced8bd961e0f766
4
- data.tar.gz: 7987a0938706989f590071825bb83842384a3e3d4b61f9a55b3f865f42d98cc5
3
+ metadata.gz: e2ae7f324d12e24d38f8ac0fbf573406453c0cece8e1853800314feb3ba9b2b8
4
+ data.tar.gz: c0619a88e63b5df94d0dc9c715a7539dddc6a9b82d38bf7b89461a6b080c8326
5
5
  SHA512:
6
- metadata.gz: fed2e43fcb1f7f3ed534f4bb26f7e1f512b0ce70ed6ce4d972677fa0cd136418322ec4a189a5e4534ec4191aada64cb549b8ea43b5b3a542582c890fc1047226
7
- data.tar.gz: e0c229624b5cf5b524fba4ae1db2b8320459982d346a2f9bf0cec3cf4e51a2c72e50cf13d2e6bf62478b5acebbc0e9ceed4ba6fb52f83e1cb3283d9a501c8e4a
6
+ metadata.gz: b971e4cc0cac4b5f9d71067bd06e4e9ace57b31c14184fadfb269d35471a101f0a4fda7d35f6148db7c6c4fe417db5d559edf23db2188ef64aaf6d9443544f45
7
+ data.tar.gz: 6d1fb79de256ba8903fe326da8beef481c28e7b04a26b094f872fe48992bfd273e55c366e03f6c87dfba099a6206b5774be44d01371fafc7e5d44ada0e4b80d7
data/lib/helpers.rb ADDED
@@ -0,0 +1,21 @@
1
+ module Sqlite
2
+ module TestHelper
3
+
4
+ def set_test_parsers_hash
5
+ @test_parsers = {
6
+ query: Sqlite::QueryTestParser,
7
+ display: Sqlite::DisplayTestParser,
8
+ datasets: Sqlite::DatasetTestParser,
9
+ final_dataset: Sqlite::FinalDatasetTestParser,
10
+ }
11
+ @test_parsers.default = Sqlite::InvalidTestParser
12
+ end
13
+
14
+ def load_tests(test)
15
+ tests = YAML.load test
16
+ tests = [tests] unless tests.kind_of? Array
17
+ tests.map(&:to_struct)
18
+ end
19
+
20
+ end
21
+ end
data/lib/locales/en.yml CHANGED
@@ -7,3 +7,6 @@ en:
7
7
  columns: 'Columns do not match'
8
8
  rows: 'Rows do not match'
9
9
  query: 'Queries do not match'
10
+ tests:
11
+ lint: "Invalid tests, It should be a valid YAML format. Try with this validator http://www.yamllint.com/"
12
+ types: "Unsupported test type '%{type}'. Use one of these: datasets, query, display, final_dataset"
data/lib/locales/es.yml CHANGED
@@ -7,3 +7,6 @@ es:
7
7
  columns: 'Las columnas no coinciden'
8
8
  rows: 'Las filas no coinciden'
9
9
  query: 'Las consultas no coinciden'
10
+ tests:
11
+ lint: "¡Tests inválidos! No tienen el formato YAML correcto. Podés probar en este validador http://www.yamllint.com/"
12
+ types: "El test type '%{type}' no está soportado. Tenés que usar uno de éstos: datasets, query, display, final_dataset"
@@ -6,6 +6,7 @@ module Sqlite
6
6
  required :parse, 'You need to implement parse method when use CommonTestParse mixin!'
7
7
 
8
8
  def initialize(test)
9
+ @test = test
9
10
  @result = parse test
10
11
  end
11
12
 
@@ -13,6 +14,23 @@ module Sqlite
13
14
  solution
14
15
  end
15
16
 
17
+ def has?(key)
18
+ !@test[key.to_sym].blank?
19
+ end
20
+
21
+ def get(key)
22
+ @test[key.to_sym]
23
+ end
24
+
25
+ def has_final?
26
+ # Only FinalDataset should have final query
27
+ false
28
+ end
29
+
30
+ def get_final
31
+ ''
32
+ end
33
+
16
34
  protected
17
35
 
18
36
  def final_parse(test, override = {})
@@ -3,11 +3,6 @@ module Sqlite
3
3
 
4
4
  include Sqlite::CommonTestParser
5
5
 
6
- def initialize(test)
7
- @test = test
8
- @result = parse test
9
- end
10
-
11
6
  # test = {
12
7
  # type: dataset,
13
8
  # seed: INSERT INTO ...,
@@ -0,0 +1,18 @@
1
+ module Sqlite
2
+ class DisplayTestParser
3
+ include Sqlite::CommonTestParser
4
+
5
+ def has_final?
6
+ has?(:query)
7
+ end
8
+
9
+ def get_final
10
+ # Assume has_final? is true
11
+ get(:query)
12
+ end
13
+
14
+ def parse(test)
15
+ final_parse test, { expected: get_final }
16
+ end
17
+ end
18
+ end
@@ -1,9 +1,13 @@
1
1
  module Sqlite
2
2
  class FinalDatasetTestParser < DatasetTestParser
3
3
 
4
- def initialize(test)
5
- super(test)
6
- @final = test[:query] || test[:final]
4
+ def has_final?
5
+ has?(:final) || has?(:query)
6
+ end
7
+
8
+ def get_final
9
+ # Assume has_final? is true
10
+ has?(:final) ? get(:final) : get(:query)
7
11
  end
8
12
 
9
13
  end
@@ -3,16 +3,8 @@ module Sqlite
3
3
 
4
4
  include Sqlite::CommonTestParser
5
5
 
6
- # return {
7
- # seed: -- NONE,
8
- # expected: -- NONE
9
- # }
10
6
  def parse(test)
11
- final_parse(test, {
12
- seed: COMMENT,
13
- expected: COMMENT
14
- })
7
+ raise I18n.t('message.failure.tests.types', type: test.type)
15
8
  end
16
-
17
9
  end
18
10
  end
data/lib/sqlite_runner.rb CHANGED
@@ -10,16 +10,19 @@ Mumukit.configure do |config|
10
10
  config.structured = true
11
11
  end
12
12
 
13
+ require_relative './dataset'
14
+ require_relative './checker'
13
15
  require_relative './version_hook'
14
- require_relative './test_hook'
15
16
  require_relative './metadata_hook'
16
- require_relative './checker'
17
- require_relative './multiple_executions_runner'
18
17
  require_relative './html_renderer'
19
- require_relative './dataset'
18
+ require_relative './multiple_executions_runner'
20
19
  require_relative './parsers/common_test_parser'
21
20
  require_relative './parsers/query_test_parser'
21
+ require_relative './parsers/display_test_parser'
22
22
  require_relative './parsers/dataset_test_parser'
23
23
  require_relative './parsers/final_dataset_test_parser'
24
24
  require_relative './parsers/invalid_test_parser'
25
+ require_relative './helpers'
26
+ require_relative './test_hook'
27
+ require_relative './validation_hook'
25
28
  require_relative './errors'
data/lib/test_hook.rb CHANGED
@@ -5,67 +5,36 @@ require 'diffy'
5
5
  # This Hook allow to run Sqlite Worker from an ad-hoc program that receives .json files.
6
6
 
7
7
  class SqliteTestHook < Mumukit::Templates::FileHook
8
-
9
- # Define that worker runs on a freshly-cleaned environment
10
8
  isolated
9
+ include Sqlite::TestHelper
11
10
 
12
11
  def initialize(config = nil)
13
12
  super(config)
14
- @test_parsers = {
15
- query: Sqlite::QueryTestParser,
16
- datasets: Sqlite::DatasetTestParser,
17
- final_dataset: Sqlite::FinalDatasetTestParser,
18
- }
19
- @test_parsers.default = Sqlite::InvalidTestParser
13
+ set_test_parsers_hash
20
14
  end
21
15
 
22
- # Just define file extension
23
16
  def tempfile_extension
24
17
  '.json'
25
18
  end
26
19
 
27
- # Define the command to be run by sqlite worker
28
20
  def command_line(filename)
29
21
  "runsql #{filename}"
30
22
  end
31
23
 
32
24
  # Transform Mumuki Request into Docker file style
33
- # Request = {
34
- # test: {
35
- # type: (string) query|dataset,
36
- # seed: (string) sql code to populate tables,
37
- # expected: (string) query sentence | resulting table
38
- # },
39
- # extra: (string) sql code to create tables,
40
- # content: (string) student's solution,
41
- # expectations: [] # not using
42
- # }
43
- #
44
25
  def compile_file_content(request)
45
26
  tests = parse_tests request.test
46
27
  final = get_final_query
47
28
  {
48
- init: request.extra.strip,
49
- student: request.content.strip << final,
29
+ init: "#{request.extra&.strip}",
30
+ student: "#{request.content&.strip}#{final}",
50
31
  tests: tests
51
32
  }.to_json
52
33
  end
53
34
 
54
- # Define how output results
55
- # Expected:
56
- # {
57
- # "expected": [
58
- # "name\nTest 1.1\nTest 1.2\nTest 1.3\n",
59
- # "name\nTest 2.1\nTest 2.2\nTest 2.3\n"
60
- # ],
61
- # "student": [
62
- # "id|name\n1|Test 1.1\n2|Test 1.2\n3|Test 1.3\n",
63
- # "id|name\n1|Test 2.1\n2|Test 2.2\n3|Test 2.3\n"
64
- # ]
65
- # }
35
+ # Transform Docker result into Response to Mumuki
66
36
  def post_process_file(_file, result, status)
67
- output = JSON.parse(result)
68
-
37
+ output = JSON.parse result
69
38
  case status
70
39
  when :passed
71
40
  expected, student = parse_output output
@@ -83,12 +52,12 @@ class SqliteTestHook < Mumukit::Templates::FileHook
83
52
  student = output['student']
84
53
  expected = output['expected']
85
54
  expected.map!.with_index do |expect, i|
86
- @expected_parser[i].choose expect
55
+ @tests[i].choose expect
87
56
  end
88
-
89
57
  diff(expected, student)
90
58
  end
91
59
 
60
+ # Make diff between expected and student dataset result and mark each line one according comparision
92
61
  def diff(expected, student)
93
62
  zipped = expected.zip(student).map do |expected_i, student_i|
94
63
  diff = Diffy::SplitDiff.new student_i << "\n", expected_i << "\n"
@@ -119,34 +88,17 @@ class SqliteTestHook < Mumukit::Templates::FileHook
119
88
  end
120
89
  end
121
90
 
122
- # This method receives a list of test cases.
123
- # Each one could be like one of these:
124
- #
125
- # type: query
126
- # seed: INSERT INTO ...
127
- # expected: SELECT * FROM ...
128
- #
129
- # type: dataset
130
- # seed: INSERT INTO ...
131
- # expected: |
132
- # id|field
133
- # 1|row 1
134
- # ...
91
+ # This method receives a list of test cases and transforms each one according it parser
135
92
  def parse_tests(tests)
136
- tests = YAML.load tests
137
- tests = [tests] unless tests.kind_of? Array
138
- @tests = tests.map do | test |
139
- test = test.to_struct
93
+ @tests = load_tests(tests).map do | test |
140
94
  @test_parsers[test.type.to_sym].new test
141
95
  end
142
-
143
- @expected_parser = @tests
144
96
  @tests.map(&:result)
145
97
  end
146
98
 
147
99
  def get_final_query
148
- parsers = @expected_parser.select { |parser| !parser.final.blank? }
149
- parsers.empty? ? '' : parsers.first.final
100
+ tests = @tests.select { |test| test.has_final? }
101
+ tests.empty? ? '' : tests.first.get_final
150
102
  end
151
103
 
152
104
  # Initialize Metatest Framework with Checker & Runner
@@ -0,0 +1,31 @@
1
+ class SqliteValidationHook < Mumukit::Hook
2
+
3
+ include Sqlite::TestHelper
4
+
5
+ def initialize(config = nil)
6
+ super(config)
7
+ set_test_parsers_hash
8
+ end
9
+
10
+ def validate!(request)
11
+ lint_tests request.test
12
+ types_tests request.test
13
+ end
14
+
15
+ def lint_tests(tests)
16
+ begin
17
+ YAML.load tests
18
+ rescue
19
+ raise Mumukit::RequestValidationError, I18n.t('message.failure.tests.lint')
20
+ end
21
+ end
22
+
23
+ def types_tests(tests)
24
+ # Assumes that pass lint_tests
25
+ load_tests(tests).each do |test|
26
+ valid = @test_parsers.has_key? test.type.to_sym
27
+ raise Mumukit::RequestValidationError, I18n.t('message.failure.tests.types', type: test.type) unless valid
28
+ end
29
+ end
30
+
31
+ end
data/lib/version_hook.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module SqliteVersionHook
2
- VERSION = '3.1.0'
2
+ VERSION = '3.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mumuki-sqlite-runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leandro Di Lorenzo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-18 00:00:00.000000000 Z
11
+ date: 2017-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mumukit
@@ -174,6 +174,7 @@ files:
174
174
  - lib/checker.rb
175
175
  - lib/dataset.rb
176
176
  - lib/errors.rb
177
+ - lib/helpers.rb
177
178
  - lib/html_renderer.rb
178
179
  - lib/locales/en.yml
179
180
  - lib/locales/es.yml
@@ -181,11 +182,13 @@ files:
181
182
  - lib/multiple_executions_runner.rb
182
183
  - lib/parsers/common_test_parser.rb
183
184
  - lib/parsers/dataset_test_parser.rb
185
+ - lib/parsers/display_test_parser.rb
184
186
  - lib/parsers/final_dataset_test_parser.rb
185
187
  - lib/parsers/invalid_test_parser.rb
186
188
  - lib/parsers/query_test_parser.rb
187
189
  - lib/sqlite_runner.rb
188
190
  - lib/test_hook.rb
191
+ - lib/validation_hook.rb
189
192
  - lib/version_hook.rb
190
193
  - lib/view/rows_error.html.erb
191
194
  - lib/view/rows_success.html.erb