Class: SqliteTestHook

Inherits:
Mumukit::Templates::FileHook
  • Object
show all
Defined in:
lib/test_hook.rb

Overview

This Hook allow to run Sqlite Worker from an ad-hoc program that receives .json files.

Instance Method Summary collapse

Instance Method Details

#command_line(filename) ⇒ Object

Define the command to be run by sqlite worker



18
19
20
# File 'lib/test_hook.rb', line 18

def command_line(filename)
  "runsql #{filename}"
end

#compile_file_content(request) ⇒ Object

Define the .json file template from request structure Input: request =

test: (yaml string) teacher's code that define which testing verification student code should pass,
extra: (sql string) teacher's code that prepare field where student code should run,
content: (sql string) student code,
expectations: [] not using for now



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/test_hook.rb', line 30

def compile_file_content(request)
  solution, data = parse_test request.test

  content = {
      init: request.extra.strip,
      solution: solution,
      student: request.content.strip,
      datasets: data
  }

  content.to_json
end

#post_process_file(_file, result, status) ⇒ Object

Define how output results Expected:

"solutions": [
    "name\nTest 1.1\nTest 1.2\nTest 1.3\n",
    "name\nTest 2.1\nTest 2.2\nTest 2.3\n"
],
"results": [
    "id|name\n1|Test 1.1\n2|Test 1.2\n3|Test 1.3\n",
    "id|name\n1|Test 2.1\n2|Test 2.2\n3|Test 2.3\n"
]



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/test_hook.rb', line 55

def post_process_file(_file, result, status)
  output = JSON.parse(result)

  case status
    when :passed
      solutions, results = parse_output output
      framework.test solutions, results
    when :failed
      [output['output'], status]
    else
      [output, status]
  end
end

#tempfile_extensionObject

Just define file extension



13
14
15
# File 'lib/test_hook.rb', line 13

def tempfile_extension
  '.json'
end