mumuki-sqlite-runner 3.3.1 → 3.3.2

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: c247a76a413469d5e8c749ee216bf4d406429c560e50c69dd62ff119125d9004
4
- data.tar.gz: b02f32da0c03682efbe31da8e906b9a21e52a0e6f99af670ef6fa4f1ec588011
3
+ metadata.gz: 4b25152c9fd36bed95d9ca16275446be2051c19cdf3c82dd4a3947bdcb8d1374
4
+ data.tar.gz: e38baeeeb4df27d0d61afc08edf59f8dbb7b391f0d30f2e72abc36d459649b06
5
5
  SHA512:
6
- metadata.gz: bfdbc18de9b34c2b219aa222a499a91650a61b2dc213f2ac480a17be3de1d894f8b99739257b6a645d32f6f62472c63e0e4bb2b37cd3fe96ad67d608827998a5
7
- data.tar.gz: 94addefc89c3405e2b649e1c5a49bfd38538e25290b70891c0859d8756036a4dc6efdc8f187e425c9eba28574cf6e15a1c8d90e0d13d3e14ba4ed6a39d2d759c
6
+ metadata.gz: b108d2e67211448a23b53a67c17f0c13479d9ab4b7cea0fa744762a03d4760fea5e155fade026957bf1e9e446055bf9b1292df20fd78f5fca7356604eeb8cf41
7
+ data.tar.gz: 60a3a18d2959835184fcee8713b8d529da138ef20c57ab006186541487ccb50d01caac4c2f93965683d0cf9e230f669fbb52f41d2288d42a20c3752fc17422c2
@@ -16,5 +16,8 @@ module Sqlite
16
16
  tests.map(&:to_struct)
17
17
  end
18
18
 
19
+ def fail!(*args)
20
+ raise Mumukit::RequestValidationError, I18n.t(*args)
21
+ end
19
22
  end
20
23
  end
@@ -5,26 +5,30 @@ module Sqlite
5
5
 
6
6
  def render_success(result, message)
7
7
  @message = message
8
- @header = result[:dataset].header
9
- @rows = result[:dataset].rows
8
+ @table_name = result[:table_name]
9
+ @header = result[:dataset].header
10
+ @rows = result[:dataset].rows
11
+ @extra_message = extra_message result
10
12
  template_file_success.result binding
11
13
  end
12
14
 
13
15
  def render_error(result, solution, error)
14
16
  @error = error
17
+ @table_name = result[:table_name]
15
18
  @result = parse_dataset(result[:dataset].header, result[:dataset].rows)
16
19
  @solution = parse_dataset(solution[:dataset].header, solution[:dataset].rows)
17
-
20
+ @expected_message = expected_message result
21
+ @obtained_message = I18n.t 'obtained'
18
22
  template_file_error.result binding
19
23
  end
20
24
 
21
25
  protected
22
26
 
23
27
  def parse_dataset(header, rows)
24
- header_sign = header.shift
28
+ header_sign = first_column(header)
25
29
  rows = rows.map do |row|
26
30
  {
27
- sign: row.shift,
31
+ sign: first_column(row),
28
32
  row: row
29
33
  }
30
34
  end
@@ -37,7 +41,7 @@ module Sqlite
37
41
  },
38
42
  rows: rows.map do |row|
39
43
  {
40
- sign:row[:sign],
44
+ sign: row[:sign],
41
45
  class: diff_class_of(row[:sign]),
42
46
  fields: row[:row]
43
47
  }
@@ -46,6 +50,10 @@ module Sqlite
46
50
 
47
51
  end
48
52
 
53
+ def first_column(row)
54
+ row.first.present? && row.first =~ /^[+-]$/ ? row.shift : '✓'
55
+ end
56
+
49
57
  def diff_class_of(value)
50
58
  case value
51
59
  when '+'
@@ -57,6 +65,18 @@ module Sqlite
57
65
  end
58
66
  end
59
67
 
68
+ def extra_message(result)
69
+ result[:show_query] ? I18n.t('message.success.show_query', query: result[:query]) : ''
70
+ end
71
+
72
+ def expected_message(result)
73
+ if result[:show_query]
74
+ I18n.t('message.failure.show_query', query: result[:query])
75
+ else
76
+ I18n.t 'expected'
77
+ end
78
+ end
79
+
60
80
  def template_file_success
61
81
  ERB.new File.read("#{__dir__}/view/rows_success.html.erb")
62
82
  end
@@ -1,9 +1,15 @@
1
1
  en:
2
2
  dataset: "Dataset %{number}"
3
+ default_table_name: 'Result'
4
+ expected: 'It was expected:'
5
+ obtained: 'It was obtained:'
3
6
  message:
4
7
  success:
5
8
  query: 'Correct Query!'
9
+ show_query: 'The query `%{query}` returns:'
6
10
  failure:
11
+ show_query: 'The query `%{query}` should return:'
12
+ semicolon_ending: 'You should finish each SQL statement with a semicolon (;)'
7
13
  columns: 'Columns do not match'
8
14
  rows: 'Rows do not match'
9
15
  query: 'Queries do not match'
@@ -1,9 +1,15 @@
1
1
  es:
2
2
  dataset: "Set de datos %{number}"
3
+ default_table_name: 'Resultado'
4
+ expected: 'Se esperaba:'
5
+ obtained: 'Se obtuvo:'
3
6
  message:
4
7
  success:
5
8
  query: '¡Consulta correcta!'
9
+ show_query: 'La consulta `%{query}` devolvió:'
6
10
  failure:
11
+ show_query: 'Se esperaba que la consulta `%{query}` devolviera:'
12
+ semicolon_ending: 'Tenés que terminar cada sentencia SQL con punto y coma (;)'
7
13
  columns: 'Las columnas no coinciden'
8
14
  rows: 'Las filas no coinciden'
9
15
  query: 'Las consultas no coinciden'
@@ -26,6 +26,14 @@ module Sqlite
26
26
  ''
27
27
  end
28
28
 
29
+ def show_query?
30
+ false
31
+ end
32
+
33
+ def table_name
34
+ has?(:result_alias) ? get(:result_alias) : I18n.t('default_table_name')
35
+ end
36
+
29
37
  protected
30
38
 
31
39
  def transform_test
@@ -11,6 +11,10 @@ module Sqlite
11
11
  }
12
12
  end
13
13
 
14
+ def show_query?
15
+ true
16
+ end
17
+
14
18
  def get_final_query
15
19
  has?(:final) ? get(:final) : get(:query)
16
20
  end
@@ -16,7 +16,7 @@ require_relative './version_hook'
16
16
  require_relative './metadata_hook'
17
17
  require_relative './html_renderer'
18
18
  require_relative './multiple_executions_runner'
19
- require_relative './parsers/general_parser'
19
+ require_relative './parsers/base_parser'
20
20
  require_relative './parsers/query_parser'
21
21
  require_relative './parsers/display_parser'
22
22
  require_relative './parsers/datasets_parser'
@@ -19,9 +19,10 @@ class SqliteTestHook < Mumukit::Templates::FileHook
19
19
  # Transform Mumuki Request into Docker file style
20
20
  def compile_file_content(request)
21
21
  parse_tests request.test
22
+ student_code = parse_student_code "#{request.content&.strip}#{get_final_query}"
22
23
  {
23
24
  init: "#{request.extra&.strip}",
24
- student: "#{request.content&.strip}#{get_final_query}",
25
+ student: student_code,
25
26
  tests: get_tests
26
27
  }.to_json
27
28
  end
@@ -84,11 +85,20 @@ class SqliteTestHook < Mumukit::Templates::FileHook
84
85
  datasets.map.with_index do |dataset, i|
85
86
  {
86
87
  id: i + 1,
87
- dataset: Sqlite::Dataset.new(dataset)
88
+ dataset: Sqlite::Dataset.new(dataset),
89
+ table_name: @tests[i].table_name,
90
+ show_query: @tests[i].show_query?,
91
+ query: @tests[i].get_final_query
88
92
  }
89
93
  end
90
94
  end
91
95
 
96
+ def parse_student_code(code)
97
+ code = code&.strip
98
+ fail! 'message.failure.semicolon_ending' unless code&.end_with? ';'
99
+ code
100
+ end
101
+
92
102
  # This method receives a list of test cases and transforms each one according it parser
93
103
  def parse_tests(tests)
94
104
  @tests = collect_tests(tests).map do |test|
@@ -29,8 +29,4 @@ class SqliteValidationHook < Mumukit::Hook
29
29
  fail! "message.failure.tests.fields.#{test.type}" unless parser.test_has_valid_fields? test
30
30
  end
31
31
  end
32
-
33
- def fail!(*args)
34
- raise Mumukit::RequestValidationError, I18n.t(*args)
35
- end
36
32
  end
@@ -1,3 +1,3 @@
1
1
  module SqliteVersionHook
2
- VERSION = '3.3.1'
2
+ VERSION = '3.3.2'
3
3
  end
@@ -1,29 +1,4 @@
1
1
  <style>
2
- table.sqlite_error {
3
- width: auto;
4
- }
5
- table.sqlite_result {
6
- border: none;
7
- }
8
- table.sqlite_solution {
9
- border: none;
10
- }
11
- table.sqlite_error tr:nth-child(even) {
12
- background-color: #EEEEEE;
13
- }
14
- table.sqlite_error tr:nth-child(odd) {
15
- background-color: #FFFFFF;
16
- }
17
- table.sqlite_error th {
18
- color: white;
19
- font-weight: bold;
20
- background-color: #2E2F30;
21
- }
22
- table.sqlite_error td {
23
- width: auto;
24
- text-align: left;
25
- }
26
-
27
2
  .required {
28
3
  color: #5cb85c;
29
4
  font-style: italic;
@@ -32,25 +7,6 @@
32
7
  color: #d9534f;
33
8
  font-style: italic;
34
9
  }
35
-
36
- .required :first-child,
37
- .errored :first-child,
38
- .nothing :first-child {
39
- font-style: normal;
40
- padding-left: 2px;
41
- padding-right: 2px;
42
- background-color: white;
43
- border-left: none;
44
- border-bottom: 1px solid white;
45
- }
46
- .required :first-child {
47
- color: white;
48
- background-color: #5cb85c;
49
- }
50
- .errored :first-child {
51
- color: white;
52
- background-color: #d9534f;
53
- }
54
10
  </style>
55
11
 
56
12
  <h5><%= @error %></h5>
@@ -59,55 +15,61 @@
59
15
 
60
16
  <!-- Result -->
61
17
  <div class="col-md-6">
62
- <h6>Se esperaba:</h6>
63
- <table class="table table-bordered sqlite_error sqlite_result">
64
- <thead>
65
- <tr class="<%= @result[:header][:class] %>">
66
- <th><%= @result[:header][:sign] %></th>
67
- <% @result[:header][:fields].each do |field| %>
68
- <th><%= field %></th>
18
+ <h6><%= @expected_message %></h6>
19
+
20
+ <div class="mu-sql-table-rendered">
21
+ <header><%= @table_name %></header>
22
+ <table>
23
+ <thead>
24
+ <tr class="<%= @result[:header][:class] %>">
25
+ <th><%= @result[:header][:sign] %></th>
26
+ <% @result[:header][:fields].each do |field| %>
27
+ <th><%= field %></th>
28
+ <% end %>
29
+ </tr>
30
+ </thead>
31
+ <tbody>
32
+ <% @result[:rows].each do |row| %>
33
+ <tr class="<%= row[:class] %>">
34
+ <td><%= row[:sign] %></td>
35
+ <% row[:fields].each do |field| %>
36
+ <td><%= field %></td>
37
+ <% end %>
38
+ </tr>
69
39
  <% end %>
70
- </tr>
71
- </thead>
40
+ </tbody>
41
+ </table>
42
+ </div>
43
+
72
44
 
73
- <tbody>
74
- <% @result[:rows].each do |row| %>
75
- <tr class="<%= row[:class] %>">
76
- <td><%= row[:sign] %></td>
77
- <% row[:fields].each do |field| %>
78
- <td><%= field %></td>
79
- <% end %>
80
- </tr>
81
- <% end %>
82
- </tbody>
83
- </table>
84
45
  </div>
85
46
 
86
47
  <!-- Solution -->
87
48
  <div class="col-md-6">
88
- <h6>Se obtuvo:</h6>
89
- <table class="table table-bordered sqlite_error sqlite_solution">
90
- <thead>
91
- <tr class="<%= @result[:header][:class] %>">
92
- <th><%= @result[:header][:sign] %></th>
93
- <% @solution[:header][:fields].each do |field| %>
94
- <th><%= field %></th>
49
+ <h6><%= @obtained_message %></h6>
50
+
51
+ <div class="mu-sql-table-rendered">
52
+ <header><%= @table_name %></header>
53
+ <table>
54
+ <thead>
55
+ <tr class="<%= @result[:header][:class] %>">
56
+ <th><%= @result[:header][:sign] %></th>
57
+ <% @solution[:header][:fields].each do |field| %>
58
+ <th><%= field %></th>
59
+ <% end %>
60
+ </tr>
61
+ </thead>
62
+ <tbody>
63
+ <% @solution[:rows].each do |row| %>
64
+ <tr class="<%= row[:class] %>">
65
+ <td><%= row[:sign] %></td>
66
+ <% row[:fields].each do |field| %>
67
+ <td><%= field %></td>
68
+ <% end %>
69
+ </tr>
95
70
  <% end %>
96
- </tr>
97
- </thead>
98
-
99
- <tbody>
100
- <% @solution[:rows].each do |row| %>
101
- <tr class="<%= row[:class] %>">
102
- <td><%= row[:sign] %></td>
103
- <% row[:fields].each do |field| %>
104
- <td><%= field %></td>
105
- <% end %>
106
- </tr>
107
- <% end %>
108
- </tbody>
109
- </table>
71
+ </tbody>
72
+ </table>
73
+ </div>
110
74
  </div>
111
75
  </div>
112
-
113
-
@@ -1,42 +1,26 @@
1
- <style>
2
- table.sqlite_success {
3
- width: auto;
4
- border: none;
5
- }
6
- table.sqlite_success tr:nth-child(even) {
7
- background-color: #DDDDDD;
8
- }
9
- table.sqlite_success tr:nth-child(odd) {
10
- background-color: #FFFFFF;
11
- }
12
- table.sqlite_success th {
13
- color: white;
14
- font-weight: bold;
15
- background-color: #BBBBBB;
16
- }
17
- table.sqlite_success td {
18
- width: auto;
19
- text-align: left;
20
- }
21
- </style>
22
-
23
1
  <h5><%= message %></h5>
24
- <table class="table table-bordered sqlite_success">
25
- <thead>
26
- <tr>
27
- <% @header.each do |field| %>
28
- <th><%= field %></th>
29
- <% end %>
30
- </tr>
31
- </thead>
2
+ <% if @extra_message %>
3
+ <h6><%= @extra_message %></h6>
4
+ <% end %>
32
5
 
33
- <tbody>
34
- <% @rows.each do |row| %>
35
- <tr>
36
- <% row.each do |field| %>
37
- <td><%= field %></td>
6
+ <div class="mu-sql-table-rendered">
7
+ <header><%= @table_name %></header>
8
+ <table>
9
+ <thead>
10
+ <tr>
11
+ <% @header.each do |field| %>
12
+ <th><%= field %></th>
38
13
  <% end %>
39
- </tr>
40
- <% end %>
41
- </tbody>
42
- </table>
14
+ </tr>
15
+ </thead>
16
+ <tbody>
17
+ <% @rows.each do |row| %>
18
+ <tr>
19
+ <% row.each do |field| %>
20
+ <td><%= field %></td>
21
+ <% end %>
22
+ </tr>
23
+ <% end %>
24
+ </tbody>
25
+ </table>
26
+ </div>
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.3.1
4
+ version: 3.3.2
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: 2018-01-04 00:00:00.000000000 Z
11
+ date: 2018-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mumukit
@@ -156,14 +156,14 @@ dependencies:
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: '1.3'
159
+ version: '3.1'
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: '1.3'
166
+ version: '3.1'
167
167
  description:
168
168
  email:
169
169
  - leandro.jdl@gmail.com
@@ -180,10 +180,10 @@ files:
180
180
  - lib/locales/es.yml
181
181
  - lib/metadata_hook.rb
182
182
  - lib/multiple_executions_runner.rb
183
+ - lib/parsers/base_parser.rb
183
184
  - lib/parsers/datasets_parser.rb
184
185
  - lib/parsers/display_parser.rb
185
186
  - lib/parsers/final_dataset_parser.rb
186
- - lib/parsers/general_parser.rb
187
187
  - lib/parsers/query_parser.rb
188
188
  - lib/sqlite_runner.rb
189
189
  - lib/test_hook.rb
@@ -211,7 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
211
211
  version: '0'
212
212
  requirements: []
213
213
  rubyforge_project:
214
- rubygems_version: 2.7.4
214
+ rubygems_version: 2.7.6
215
215
  signing_key:
216
216
  specification_version: 4
217
217
  summary: SQLite Runner for Mumuki