Class: CommitLive::Strategies::PythonUnittest

Inherits:
CommitLive::Strategy show all
Defined in:
lib/commit-live/tests/strategies/python-test.rb

Instance Method Summary collapse

Methods inherited from CommitLive::Strategy

#check_dependencies, #configure

Instance Method Details

#cleanupObject



52
53
54
55
56
# File 'lib/commit-live/tests/strategies/python-test.rb', line 52

def cleanup
	if File.exists?('.results.json')
		FileUtils.rm('.results.json')
	end
end

#detectObject



7
8
9
# File 'lib/commit-live/tests/strategies/python-test.rb', line 7

def detect
	files.any? {|f| f.match(/.*.py$/) }
end

#filesObject



11
12
13
# File 'lib/commit-live/tests/strategies/python-test.rb', line 11

def files
	@files ||= Dir.entries('.')
end


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/commit-live/tests/strategies/python-test.rb', line 19

def print_results
	if File.exists?('.results.json')
		rows = []
		totalPassed = 0
		totalFailed = 0
		test_results = results
		columns = ['Test Case', 'Status']
		test_results["results"].each do |value|
			newRow = [value["name"], value["type"]]
			isErrorOrFail = value['type'] == 'failure' || value['type'] == 'error'
			totalFailed += 1 if isErrorOrFail
			newRow << value['message'] if isErrorOrFail
			totalPassed += 1 if value['type'] == 'success'
			rows << newRow
		end
		if totalFailed > 0
			columns << 'Message'
		end
		table = Terminal::Table.new do |t|
			t.headings = columns
			t.rows = rows
			t.style = { :all_separators => true }
		end
		puts table
		puts "Total Passed: #{totalPassed}"
		puts "Total Failed: #{totalFailed}"
	end
end

#resultsObject



48
49
50
# File 'lib/commit-live/tests/strategies/python-test.rb', line 48

def results
	@output ||= Oj.load(File.read('.results.json'), mode: :compat)
end

#run(dir) ⇒ Object



15
16
17
# File 'lib/commit-live/tests/strategies/python-test.rb', line 15

def run(dir)
	system("nosetests #{dir} --verbose --with-json --json-file=\"./.results.json\" > /dev/null 2>&1")
end