Class: LearnTest::Strategies::PythonUnittest

Inherits:
LearnTest::Strategy show all
Defined in:
lib/learn_test/strategies/python_unittest.rb

Instance Attribute Summary

Attributes inherited from LearnTest::Strategy

#options, #runner

Instance Method Summary collapse

Methods inherited from LearnTest::Strategy

#argv, #configure, #die, #initialize, #learn_oauth_token, #push_results?, #run_install, #user_id, #username

Constructor Details

This class inherits a constructor from LearnTest::Strategy

Instance Method Details

#check_dependenciesObject



15
16
17
18
# File 'lib/learn_test/strategies/python_unittest.rb', line 15

def check_dependencies
  LearnTest::PythonUnittest::RequirementsChecker.check_installation
  LearnTest::PythonUnittest::NoseInstaller.install
end

#cleanupObject



53
54
55
# File 'lib/learn_test/strategies/python_unittest.rb', line 53

def cleanup
  FileUtils.rm('.results.json')
end

#detectObject



11
12
13
# File 'lib/learn_test/strategies/python_unittest.rb', line 11

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

#outputObject



24
25
26
# File 'lib/learn_test/strategies/python_unittest.rb', line 24

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

#resultsObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/learn_test/strategies/python_unittest.rb', line 32

def results
  {
    username: username,
    github_user_id: user_id,
    learn_oauth_token: learn_oauth_token,
    repo_name: runner.repo,
    build: {
      test_suite: [{
        framework: 'unittest',
        formatted_output: output,
        duration: calculate_duration
      }]
    },
    examples: output[:stats][:total],
    passing_count: output[:stats][:passes],
    pending_count: output[:stats][:skipped],
    failure_count: output[:stats][:errors],
    failure_descriptions: concat_failure_descriptions
  }
end

#runObject



20
21
22
# File 'lib/learn_test/strategies/python_unittest.rb', line 20

def run
  system("nosetests #{options[:argv].join(' ')} --verbose --with-json --json-file='./.results.json'")
end

#service_endpointObject



7
8
9
# File 'lib/learn_test/strategies/python_unittest.rb', line 7

def service_endpoint
  '/e/flatiron_unittest'
end

#test_filesObject



28
29
30
# File 'lib/learn_test/strategies/python_unittest.rb', line 28

def test_files
  @test_files ||= Dir.glob("**/*_test.py")
end