Class: BasePythonTestHook

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

Direct Known Subclasses

Python2TestHook, Python3TestHook

Instance Method Summary collapse

Instance Method Details

#command_line(filename) ⇒ Object



9
10
11
# File 'lib/base/test_hook.rb', line 9

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

#compile_file_content(request) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/base/test_hook.rb', line 13

def compile_file_content(request)
  <<python
# -*- coding: UTF-8 -*-

import unittest
import xmlrunner
import sys
from datetime import datetime, date

#{request.extra}
#{request.content}
#{test_class(request.test)}

unittest.main(
testRunner=xmlrunner.XMLTestRunner(output='./xml-unittest-output'),
failfast=False,
buffer=False,
catchbreak=False
)
python
end

#line_number_reference_regexpObject



44
45
46
# File 'lib/base/test_hook.rb', line 44

def line_number_reference_regexp
  /"#{masked_tempfile_path}", line (\d+)/m
end

#post_process_file(_file, output, status) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/base/test_hook.rb', line 35

def post_process_file(_file, output, status)
  xml = output.split("Generating XML reports...\n").last
  raise StandardError, 'No XML found' unless xml.start_with? '<?xml'

  [generate_test_results(Nokogiri::XML(xml))]
rescue
  [output, :errored]
end

#rebuild_line_number_reference(new_line_number) ⇒ Object



48
49
50
# File 'lib/base/test_hook.rb', line 48

def rebuild_line_number_reference(new_line_number)
  "\"#{masked_tempfile_path}\", line #{new_line_number}"
end

#tempfile_extensionObject



5
6
7
# File 'lib/base/test_hook.rb', line 5

def tempfile_extension
  '.py'
end