learn-test 2.5.6 → 2.6.0

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
- SHA1:
3
- metadata.gz: 53ebce05a6ed7c4c7cb3e41c7b613450854be494
4
- data.tar.gz: c6f35a2b5ffd314d8e3b5815c349fe384518a403
2
+ SHA256:
3
+ metadata.gz: cc7eb81e50945d683e8bb07870e1160c8ec269927106fd8f50d921cc71034002
4
+ data.tar.gz: ca2bb24e7603d0d6649ebb472568c2dcae6050f0f9ce9894c871ba53ca71ce46
5
5
  SHA512:
6
- metadata.gz: 7fa014a21fcc8f4acc418eae9612014a1266250c796e54076f5e971da98859f782cdde4009e365648b76a941e03f2f8c8e2e3bacbd19ef8d49c98d9f449d4c50
7
- data.tar.gz: eaf80dd6b238fa32525d413070907b5bf35b9c3b17013f18b596bf7cfa22a3f52115c7b0436ed2aaedc1751341800c2fabafd70553e00e8f4229c953ce7225bd
6
+ metadata.gz: e141cae46336820ddd5ce0114b84d52c4541af809bc89a9be402935ab1adef08db72be596b407d4bbf7c6b1fc92e15e31ad8e357af2dd98c97e3bdc6f7f635c0
7
+ data.tar.gz: 30400f93167d9db8e2138830618a29635c6edb9ed600a0e1ddf9212f52c30e3da3d09cbccf02893b208f1b2ae3f0fdbcffcfc5402499a52d7d651042162ebb90
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014-2015 Flatiron School
1
+ Copyright (c) 2014-2018 Flatiron School
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # learn-test
2
2
 
3
- Runs RSpec, Jasmine, and Python Unit Test test suites and uploads the results to Learn.
3
+ Runs RSpec, Jasmine, and Python Pytest test suites and uploads the results to Learn.
4
4
 
5
5
  ## Installation
6
6
 
@@ -22,7 +22,7 @@ And then execute:
22
22
 
23
23
  ## Usage
24
24
 
25
- From within a directory with an RSpec, Jasmine, Karma, Mocha, or Python Unit Test test suite, run:
25
+ From within a directory with an RSpec, Jasmine, Karma, Mocha, or Python Pytest test suite, run:
26
26
 
27
27
  ```
28
28
  $ learn-test
@@ -35,4 +35,3 @@ $ learn-test
35
35
  3. Commit your changes (`git commit -am 'Add some feature'`)
36
36
  4. Push to the branch (`git push origin my-new-feature`)
37
37
  5. Create a new Pull Request
38
-
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = LearnTest::VERSION
9
9
  spec.authors = ["Flatiron School"]
10
10
  spec.email = ["learn@flatironschool.com"]
11
- spec.summary = %q{Runs RSpec, Jasmine, Karma, Mocha, and Python Unit Test builds and pushes JSON output to Learn.}
11
+ spec.summary = %q{Runs RSpec, Jasmine, Karma, Mocha, and Python Pytest Test builds and pushes JSON output to Learn.}
12
12
  spec.homepage = "https://github.com/learn-co/learn-test"
13
13
  spec.license = "MIT"
14
14
 
@@ -17,7 +17,6 @@ require_relative 'learn_test/dependency'
17
17
  require_relative 'learn_test/strategy'
18
18
  require_relative 'learn_test/js_strategy'
19
19
  require_relative 'learn_test/strategies/jasmine'
20
- require_relative 'learn_test/strategies/python_unittest'
21
20
  require_relative 'learn_test/strategies/rspec'
22
21
  require_relative 'learn_test/strategies/karma'
23
22
  require_relative 'learn_test/strategies/protractor'
@@ -25,6 +24,7 @@ require_relative 'learn_test/strategies/java_junit'
25
24
  require_relative 'learn_test/strategies/csharp_nunit'
26
25
  require_relative 'learn_test/strategies/mocha'
27
26
  require_relative 'learn_test/strategies/green_onion'
27
+ require_relative 'learn_test/strategies/pytest'
28
28
 
29
29
  module LearnTest
30
30
  module Dependencies
@@ -39,5 +39,6 @@ module LearnTest
39
39
  autoload :SeleniumServer, 'learn_test/dependencies/selenium_server'
40
40
  autoload :Firefox, 'learn_test/dependencies/firefox'
41
41
  autoload :GreenOnion, 'learn_test/dependencies/green_onion'
42
+ autoload :Pytest, 'learn_test/dependencies/pytest'
42
43
  end
43
44
  end
@@ -8,11 +8,15 @@ module LearnTest
8
8
  [:dependencies, :devDependencies].any? { |key| js_package[key] && js_package[key][dep] }
9
9
  end
10
10
 
11
+ def modules_missing?(module_names)
12
+ module_names.any? { |name| !File.exist?("node_modules/#{name}") }
13
+ end
14
+
11
15
  def missing_dependencies?
12
16
  return true if !File.exist?("node_modules")
13
-
14
- [:dependencies, :devDependencies, :peerDependencies].any? do |d|
15
- (js_package[d] || {}).any? { |p, v| !File.exist?("node_modules/#{p}") }
17
+ [:dependencies, :devDependencies, :peerDependencies].any? do |dep_group|
18
+ modules = js_package[dep_group] || {}
19
+ modules_missing?(modules.keys)
16
20
  end
17
21
  end
18
22
 
@@ -57,7 +57,7 @@ module LearnTest
57
57
  LearnTest::Strategies::Protractor,
58
58
  LearnTest::Strategies::JavaJunit,
59
59
  LearnTest::Strategies::Mocha,
60
- LearnTest::Strategies::PythonUnittest,
60
+ LearnTest::Strategies::Pytest,
61
61
  ]
62
62
  end
63
63
 
@@ -0,0 +1,80 @@
1
+ require 'crack'
2
+ require_relative 'pytest/requirements_checker'
3
+
4
+ module LearnTest
5
+ module Strategies
6
+ class Pytest < LearnTest::Strategy
7
+
8
+ def service_endpoint
9
+ '/e/flatiron_pytest'
10
+ end
11
+
12
+ def detect
13
+ test_files.count > 0
14
+ end
15
+
16
+ def check_dependencies
17
+ LearnTest::Pytest::RequirementsChecker.check_installation
18
+ end
19
+
20
+ def run
21
+ system("python -m pytest #{options[:argv].join(' ')} --junitxml='./.results.xml'")
22
+ end
23
+
24
+ def output
25
+ @output ||= Crack::XML.parse(File.read('.results.xml'))["testsuite"]
26
+ end
27
+
28
+ def test_files
29
+ # pytest will run all files of the form test_*.py or *_test.py
30
+ @test_files ||= Dir.glob("**/test_*.py") + Dir.glob("**/*_test.py")
31
+ end
32
+
33
+ def results
34
+ failed_count = output["failures"].to_i + output["errors"].to_i
35
+ skipped_count = output["skips"].to_i
36
+ passed_count = output["tests"].to_i - failed_count - skipped_count
37
+ {
38
+ username: username,
39
+ github_user_id: user_id,
40
+ learn_oauth_token: learn_oauth_token,
41
+ repo_name: runner.repo,
42
+ build: {
43
+ test_suite: [{
44
+ framework: 'pytest',
45
+ formatted_output: output.to_json,
46
+ duration: output["time"]
47
+ }]
48
+ },
49
+ examples: output["tests"].to_i,
50
+ passing_count: passed_count,
51
+ pending_count: skipped_count,
52
+ failure_count: failed_count,
53
+ failure_descriptions: concat_failure_descriptions
54
+ }
55
+ end
56
+
57
+ def cleanup
58
+ FileUtils.rm('.results.xml')
59
+ end
60
+
61
+ private
62
+
63
+ def calculate_duration
64
+ output[:results].map do |example|
65
+ example[:time]
66
+ end.inject(:+)
67
+ end
68
+
69
+ def concat_failure_descriptions
70
+ output["testcase"].reduce([]) do |errors, example|
71
+ if example.has_key?("failure")
72
+ errors << example.map{|k, v| "#{k}: #{v}"}
73
+ end
74
+ errors
75
+ end
76
+ end
77
+
78
+ end
79
+ end
80
+ end
@@ -1,35 +1,28 @@
1
1
  require 'open3'
2
2
 
3
3
  module LearnTest
4
- module PythonUnittest
4
+ module Pytest
5
5
  class RequirementsChecker
6
6
  def self.check_installation
7
- new.check_installation
8
- end
9
-
10
- def check_installation
11
7
  PythonChecker.check
12
8
  PipChecker.check
9
+ PytestChecker.check
13
10
  end
14
11
  end
15
12
 
16
13
  class PythonChecker
17
14
  def self.check
18
- new.check
19
- end
20
-
21
- def check
22
- if !python_installed? || !correct_python_version?
15
+ if !self.python_installed? || !self.correct_python_version?
23
16
  puts "Please install python 2.7.x or 3.x.x"
24
17
  exit
25
18
  end
26
19
  end
27
20
 
28
- def python_installed?
21
+ def self.python_installed?
29
22
  !`which python`.empty?
30
23
  end
31
24
 
32
- def correct_python_version?
25
+ def self.correct_python_version?
33
26
  output = Open3.popen2e('python', '--version')
34
27
  version = output[1].read.strip
35
28
  !!version.match(/ 2.7.*| 3.*/)
@@ -38,20 +31,29 @@ module LearnTest
38
31
 
39
32
  class PipChecker
40
33
  def self.check
41
- new.check
42
- end
43
-
44
- def check
45
- if !pip_installed?
34
+ if !self.pip_installed?
46
35
  puts "Please ensure pip is installed"
47
36
  exit
48
37
  end
49
38
  end
50
39
 
51
- def pip_installed?
40
+ def self.pip_installed?
52
41
  !`which pip`.empty?
53
42
  end
54
43
  end
44
+
45
+ class PytestChecker
46
+ def self.check
47
+ if !self.pytest_installed?
48
+ puts "Please ensure pytest is installed"
49
+ exit
50
+ end
51
+ end
52
+
53
+ def self.pytest_installed?
54
+ !`which pytest`.empty?
55
+ end
56
+ end
57
+
55
58
  end
56
59
  end
57
-
@@ -1,3 +1,3 @@
1
1
  module LearnTest
2
- VERSION = '2.5.6'
2
+ VERSION = '2.6.0'
3
3
  end
@@ -16,44 +16,47 @@ describe LearnTest::Strategies::Mocha do
16
16
  }
17
17
  }
18
18
  end
19
+
19
20
  let(:runner) { double("Runner", options: {}) }
20
21
  let(:strategy) { LearnTest::Strategies::Mocha.new(runner) }
21
22
 
22
- it "returns true if no node_modules directory" do
23
- expect(File).to receive(:exists?).with("node_modules") { false }
24
-
25
- expect(strategy.missing_dependencies?(package)).to eq(true)
23
+ context "node_modules/ does not exist" do
24
+ it "returns true" do
25
+ allow(File).to receive(:exist?).with("node_modules").and_return(false)
26
+ expect(strategy.missing_dependencies?).to eq(true)
27
+ end
26
28
  end
27
29
 
28
- context "node_modules exists" do
30
+
31
+ context "node_modules/ exists" do
29
32
  before(:each) do
30
- allow(File).to receive(:exists?) { true }
33
+ allow(File).to receive(:exist?).and_return(true)
34
+ allow(strategy).to receive(:js_package).and_return(package)
31
35
  end
32
36
 
33
37
  it "returns true if missing a dependency" do
34
- expect(File).to receive(:exists?).with("node_modules/dep1") { true }
35
- expect(File).to receive(:exists?).with("node_modules/dep2") { false }
36
- expect(strategy.missing_dependencies?(package)).to eq(true)
38
+ allow(File).to receive(:exist?).with("node_modules/dep2").and_return(false)
39
+ expect(strategy.missing_dependencies?).to eq(true)
37
40
  end
38
41
 
39
42
  it "returns true if missing a devDependency" do
40
- expect(File).to receive(:exists?).with("node_modules/devDep1") { true }
41
- expect(File).to receive(:exists?).with("node_modules/devDep2") { false }
42
- expect(strategy.missing_dependencies?(package)).to eq(true)
43
+ allow(File).to receive(:exist?).with("node_modules/devDep2").and_return(false)
44
+ expect(strategy.missing_dependencies?).to eq(true)
43
45
  end
44
46
 
45
47
  it "returns true if missing a peerDependency" do
46
- expect(File).to receive(:exists?).with("node_modules/peerDep1") { true }
47
- expect(File).to receive(:exists?).with("node_modules/peerDep2") { false }
48
- expect(strategy.missing_dependencies?(package)).to eq(true)
48
+ allow(File).to receive(:exist?).with("node_modules/peerDep2").and_return(false)
49
+ expect(strategy.missing_dependencies?).to eq(true)
49
50
  end
50
51
 
51
52
  it "returns false if missing no dependencies" do
52
- expect(strategy.missing_dependencies?(package)).to eq(false)
53
+ allow(File).to receive(:exist?).and_return(true)
54
+ expect(strategy.missing_dependencies?).to eq(false)
53
55
  end
54
56
 
55
57
  it "returns false if there are no dependencies" do
56
- expect(strategy.missing_dependencies?({})).to eq(false)
58
+ allow(strategy).to receive(:js_package).and_return({})
59
+ expect(strategy.missing_dependencies?).to eq(false)
57
60
  end
58
61
  end
59
62
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: learn-test
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.6
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Flatiron School
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-21 00:00:00.000000000 Z
11
+ date: 2018-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -289,9 +289,8 @@ files:
289
289
  - lib/learn_test/strategies/karma/karma.conf.js
290
290
  - lib/learn_test/strategies/mocha.rb
291
291
  - lib/learn_test/strategies/protractor.rb
292
- - lib/learn_test/strategies/python_unittest.rb
293
- - lib/learn_test/strategies/python_unittest/nose_installer.rb
294
- - lib/learn_test/strategies/python_unittest/requirements_checker.rb
292
+ - lib/learn_test/strategies/pytest.rb
293
+ - lib/learn_test/strategies/pytest/requirements_checker.rb
295
294
  - lib/learn_test/strategies/rspec.rb
296
295
  - lib/learn_test/strategy.rb
297
296
  - lib/learn_test/user_id_parser.rb
@@ -336,10 +335,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
336
335
  version: '0'
337
336
  requirements: []
338
337
  rubyforge_project:
339
- rubygems_version: 2.6.14
338
+ rubygems_version: 2.7.6
340
339
  signing_key:
341
340
  specification_version: 4
342
- summary: Runs RSpec, Jasmine, Karma, Mocha, and Python Unit Test builds and pushes
341
+ summary: Runs RSpec, Jasmine, Karma, Mocha, and Python Pytest Test builds and pushes
343
342
  JSON output to Learn.
344
343
  test_files:
345
344
  - spec/features/jasmine_jquery_fixtures_spec.rb
@@ -1,72 +0,0 @@
1
- require_relative 'python_unittest/requirements_checker'
2
- require_relative 'python_unittest/nose_installer'
3
-
4
- module LearnTest
5
- module Strategies
6
- class PythonUnittest < LearnTest::Strategy
7
- def service_endpoint
8
- '/e/flatiron_unittest'
9
- end
10
-
11
- def detect
12
- test_files.any? {|f| f.match(/.*\.py$/) }
13
- end
14
-
15
- def check_dependencies
16
- LearnTest::PythonUnittest::RequirementsChecker.check_installation
17
- LearnTest::PythonUnittest::NoseInstaller.install
18
- end
19
-
20
- def run
21
- system("nosetests #{options[:argv].join(' ')} --verbose --with-json --json-file='./.results.json'")
22
- end
23
-
24
- def output
25
- @output ||= Oj.load(File.read('.results.json'), symbol_keys: true)
26
- end
27
-
28
- def test_files
29
- @test_files ||= Dir.glob("**/*_test.py")
30
- end
31
-
32
- def results
33
- {
34
- username: username,
35
- github_user_id: user_id,
36
- learn_oauth_token: learn_oauth_token,
37
- repo_name: runner.repo,
38
- build: {
39
- test_suite: [{
40
- framework: 'unittest',
41
- formatted_output: output,
42
- duration: calculate_duration
43
- }]
44
- },
45
- examples: output[:stats][:total],
46
- passing_count: output[:stats][:passes],
47
- pending_count: output[:stats][:skipped],
48
- failure_count: output[:stats][:errors],
49
- failure_descriptions: concat_failure_descriptions
50
- }
51
- end
52
-
53
- def cleanup
54
- FileUtils.rm('.results.json')
55
- end
56
-
57
- private
58
-
59
- def calculate_duration
60
- output[:results].map do |example|
61
- example[:time]
62
- end.inject(:+)
63
- end
64
-
65
- def concat_failure_descriptions
66
- output[:results].select do |example|
67
- example[:type] == 'failure'
68
- end.map { |ex| ex[:tb] }.join(';')
69
- end
70
- end
71
- end
72
- end
@@ -1,35 +0,0 @@
1
- module LearnTest
2
- module PythonUnittest
3
- class NoseInstaller
4
- def self.install
5
- new.install
6
- end
7
-
8
- def install
9
- install_nose
10
- install_nose_json
11
- end
12
-
13
- def install_nose
14
- if !nose_installed?
15
- `easy_install nose`
16
- end
17
- end
18
-
19
- def nose_installed?
20
- !`which nosetests`.empty?
21
- end
22
-
23
- def install_nose_json
24
- if !nose_json_installed?
25
- `pip install nose-json`
26
- end
27
- end
28
-
29
- def nose_json_installed?
30
- !`pip show nose-json`.empty?
31
- end
32
- end
33
- end
34
- end
35
-