hw_checker 1.3.43

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzdmNjYxYjYyNmFiYmQzMWYyN2VhOWNjYzA2ZDc2MjZiMzliZTU1Mg==
5
+ data.tar.gz: !binary |-
6
+ ZDFkNDMyMmM4YzJiMjNlMzhjMmJmNzI2YzgwMDVjMzhmNjNiZGRkMA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ YjZhYTA4MmExMWJhNDNhOWFlM2E0ODE4NTBkMWJhYTBkZjhjZTEwNTY2NGI2
10
+ YjlkZjEwYmVmODk5OTljMWVkYTFiNjlkZjU4MWNkZmM1ZDI0NjhhYzdlNGIw
11
+ OTE2YmRiYjkwODVmYzAwOTg2YzU3MzJlYmY0Y2NlZjgxMzNlNzQ=
12
+ data.tar.gz: !binary |-
13
+ ZmJiZjhjMjRhZjQzOTYzMTk2ZTk5OWY1ZDE0YWU5ZTA2OWU0MThjMjhjOWIy
14
+ Mjg0MDg0ZmI3MDEwZTU5YjNiNmI4YjM2NjRlNjdkNmFjNTk4MGNhMTIzZjRl
15
+ ZDI3MTQzYjY1MzAzODczMjM5YjJlMmQ4ZGZhODFhYWUzZjk2ZmU=
data/bin/hw_checker ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'hw_checker'
4
+
5
+ HomeWorkChecker::FileScan.new(ARGV[0], '/tmp').each do |name, type|
6
+ HomeWorkChecker::Base.start(ARGV[0], '/tmp', name, type)
7
+ end
@@ -0,0 +1,29 @@
1
+ module HomeWorkChecker
2
+ class Base
3
+ def self.start(work_path, tmp_path, name, type)
4
+ `rm -r #{tmp_path}/#{name}` if Dir.exist?("#{tmp_path}/#{name}")
5
+ time_start, xml_content = Time.now, {}
6
+ Unarchive::Zip.new("#{work_path}/#{name+type}", tmp_path)
7
+ stat = TestRunStat::execute(work_path, tmp_path, name)
8
+ stat << (Time.now - time_start).round(2)
9
+
10
+ File.open("#{work_path}/#{name}-result.xml", 'w') do |file|
11
+ file.write(generate_xml_content(name, stat) )
12
+ end
13
+ end
14
+
15
+ private
16
+ def self.generate_xml_content(identity, info)
17
+ Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
18
+ xml.root {
19
+ xml.student identity.split('_').first # name
20
+ xml.homework identity.split('_').last # homework
21
+ xml.language info[0] # language
22
+ xml.ratio info[1] # ratio of passed and failed tests
23
+ xml.quality info[2] # code quality
24
+ xml.time info[3] # time of executing
25
+ }
26
+ end.to_xml
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,33 @@
1
+ module HomeWorkChecker
2
+ class FileScan
3
+ def initialize(work_path, tmp_path = '/tmp')
4
+ raise "Directory #{work_path} does not exist" unless Dir::exist?(work_path)
5
+ raise "Directory #{tmp_path} does not exist" unless Dir::exist?(tmp_path)
6
+ @work_path, @tmp_path, @files = work_path, tmp_path, []
7
+ Dir.foreach(@work_path) do |p|
8
+ if File.file?("#{@work_path}/#{p}") && FILE_TYPES.include?(File.extname p) && !exist_xml?(p)
9
+ @files << p
10
+ end
11
+ end
12
+ end
13
+
14
+ def each
15
+ if block_given?
16
+ i = 0
17
+ while i < @files.size
18
+ type = File.extname(@files[i])
19
+ name = @files[i].chomp(type)
20
+ yield(name, type)
21
+ i += 1
22
+ end
23
+ end
24
+ @files
25
+ end
26
+
27
+ private
28
+ def exist_xml?(archive_name)
29
+ temp = archive_name.chomp(File.extname archive_name)
30
+ File.exist? "#{@work_path}/#{temp}-result.xml"
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,24 @@
1
+ module HomeWorkChecker
2
+ module TestRunStat
3
+ class PythonStat
4
+ def initialize(tmp_path, dirname)
5
+ @tmp_path, @dirname= tmp_path, dirname
6
+ @lines_all = @lines_failed = 0
7
+ end
8
+
9
+ def perform
10
+ result = 0
11
+ Dir.foreach("#{@tmp_path}/#{@dirname}/tests/statistic") do |p|
12
+ next unless File.file?("#{@tmp_path}/#{@dirname}/tests/statistic/#{p}") && File.extname(p) == '.py' && p != '__init__.py'
13
+ `pylint #{@tmp_path}/#{@dirname}/tests/statistic/#{p} > #{@tmp_path}/#{@dirname}/tests/statistic/#{p}.tmp 2>&1`
14
+ result = calc_percent_quality("#{@tmp_path}/#{@dirname}/tests/statistic/#{p}.tmp")
15
+ end
16
+ result
17
+ end
18
+
19
+ def calc_percent_quality(filename)
20
+ ( (`tail -n 2 #{filename}`).scan(/\d{1,2}/).shift.to_f / 10 * 100).round(2)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,33 @@
1
+ module HomeWorkChecker
2
+ module TestRunStat
3
+ class PythonTestRun
4
+ def initialize(tmp_path, dirname)
5
+ @tmp_path, @dirname= tmp_path, dirname
6
+ @passed = @failed = 0
7
+ end
8
+
9
+ def perform
10
+ Dir.foreach("#{@tmp_path}/#{@dirname}/tests/application") do |p|
11
+ next unless File.file?("#{@tmp_path}/#{@dirname}/tests/application/#{p}") && File.extname(p) == '.py' && p != '__init__.py'
12
+ `python #{@tmp_path}/#{@dirname}/tests/application/#{p} > #{@tmp_path}/#{@dirname}/tests/application/#{p}.tmp 2>&1`
13
+ count_passed_failed("#{@tmp_path}/#{@dirname}/tests/application/#{p}.tmp")
14
+ end
15
+ calc_percent_passed
16
+ end
17
+
18
+ private
19
+ def count_passed_failed(filename)
20
+ report = File.open(filename).first.chomp
21
+ report.each_char do |value|
22
+ @passed += 1 if value == '.'
23
+ @failed += 1 if (value == 'F' || value == 'E')
24
+ end
25
+ end
26
+
27
+ def calc_percent_passed
28
+ return 0.00 if @passed.zero? && @failed.zero?
29
+ (@passed.to_f / (@passed + @failed) * 100).round(2)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,38 @@
1
+ module HomeWorkChecker
2
+ module TestRunStat
3
+ class RubyStat
4
+ def initialize(tmp_path, dirname)
5
+ @tmp_path, @dirname= tmp_path, dirname
6
+ @lines_all = @lines_failed = 0
7
+ end
8
+
9
+ def perform
10
+ Dir.foreach("#{@tmp_path}/#{@dirname}") do |p|
11
+ next unless File::file?("#{@tmp_path}/#{@dirname}/#{p}") && File.extname(p) == '.rb'
12
+ `rubocop #{@tmp_path}/#{@dirname}/#{p} > #{@tmp_path}/#{@dirname}/#{p}.tmp`
13
+ count_lines_failed("#{@tmp_path}/#{@dirname}/#{p}.tmp")
14
+ count_lines_all("#{@tmp_path}/#{@dirname}/#{p}")
15
+ end
16
+ calc_percent_quality
17
+ end
18
+
19
+ def count_lines_failed(filename)
20
+ temp = []
21
+ File.open(filename).each_line do |line|
22
+ next unless line.match(/[CW]:\s+\d+:\s+[\w\W]{4,}/)
23
+ temp << line.scan(/\d+/).first.to_i
24
+ end
25
+ @lines_failed += temp.uniq.size
26
+ end
27
+
28
+ def count_lines_all(filename)
29
+ File.open(filename).each_line { @lines_all += 1 }
30
+ end
31
+
32
+ def calc_percent_quality
33
+ return 0.00 if @lines_all.zero?
34
+ ( (1.0 - @lines_failed.to_f / @lines_all) * 100).round(2)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,34 @@
1
+ module HomeWorkChecker
2
+ module TestRunStat
3
+ class RubyTestRun
4
+ def initialize(tmp_path, dirname)
5
+ @tmp_path, @dirname= tmp_path, dirname
6
+ @passed = @failed = 0
7
+ end
8
+
9
+ def perform
10
+ Dir.foreach("#{@tmp_path}/#{@dirname}/test") do |p|
11
+ next unless File.file?("#{@tmp_path}/#{@dirname}/test/#{p}") && File.extname(p) == '.rb'
12
+ `rspec #{@tmp_path}/#{@dirname}/test/#{p} > #{@tmp_path}/#{@dirname}/test/#{p}.tmp`
13
+ count_passed_failed("#{@tmp_path}/#{@dirname}/test/#{p}.tmp")
14
+ end
15
+ calc_percent_passed
16
+ end
17
+
18
+ private
19
+ def count_passed_failed(filename)
20
+ report = File.open(filename).first.chomp
21
+ return if report == 'No examples found.'
22
+ report.each_char do |value|
23
+ @passed += 1 if value == '.'
24
+ @failed += 1 if value == 'F'
25
+ end
26
+ end
27
+
28
+ def calc_percent_passed
29
+ return 0.00 if @passed.zero? && @failed.zero?
30
+ (@passed.to_f / (@passed + @failed) * 100).round(2)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,25 @@
1
+ module HomeWorkChecker
2
+ module TestRunStat
3
+ def self.detect_language(path)
4
+ return '.py' unless Dir.exist?("#{path}/test")
5
+ Dir.foreach("#{path}/test") do |p|
6
+ if File.file?("#{path}/test/#{p}") && LANGUAGE_TYPES.include?(File.extname p)
7
+ return File.extname p
8
+ end
9
+ end
10
+ raise "Any .rb/.py file doesn't exist"
11
+ end
12
+
13
+ def self.execute(work_path, tmp_path, dirname)
14
+ lang_needed = TestRunStat::detect_language("#{tmp_path}/#{dirname}")
15
+ class_names = LANGUAGE_TYPES[lang_needed]
16
+ test_passed = class_names.first.new(tmp_path, dirname).perform
17
+ code_quality = class_names.last.new(tmp_path, dirname).perform
18
+ [name_language(lang_needed), test_passed, code_quality]
19
+ end
20
+
21
+ def self.name_language(extname)
22
+ extname == '.rb' ? 'ruby' : 'python'
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,4 @@
1
+ module HomeWorkChecker
2
+ module Unarchive
3
+ end
4
+ end
@@ -0,0 +1,10 @@
1
+ module HomeWorkChecker
2
+ module Unarchive
3
+ class Zip
4
+ def initialize(filename, tmp_path = '/tmp')
5
+ `7za t #{filename}`
6
+ `7z x #{filename} -o#{tmp_path}`
7
+ end
8
+ end
9
+ end
10
+ end
data/lib/hw_checker.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'nokogiri'
2
+ require 'hw_checker/base'
3
+ require 'hw_checker/file_scan'
4
+ require 'hw_checker/unarchive'
5
+ require 'hw_checker/zip'
6
+ require 'hw_checker/test_run_stat'
7
+ require 'hw_checker/python_stat'
8
+ require 'hw_checker/python_test_run'
9
+ require 'hw_checker/ruby_stat'
10
+ require 'hw_checker/ruby_test_run'
11
+
12
+
13
+ module HomeWorkChecker
14
+ FILE_TYPES = ['.7z', '.zip']
15
+ LANGUAGE_TYPES = {
16
+ '.rb' => [TestRunStat::RubyTestRun, TestRunStat::RubyStat],
17
+ '.py' => [TestRunStat::PythonTestRun, TestRunStat::PythonStat]
18
+ }
19
+ end
data/spec/base_spec.rb ADDED
@@ -0,0 +1,32 @@
1
+ require 'hw_checker'
2
+
3
+ module HomeWorkChecker
4
+ describe Base do
5
+ before(:each) do
6
+ @archives = ['aaa.zip', 'bbb.7z']
7
+ @work_path = './support/'
8
+ @tmp_path = './support/tmp'
9
+ #@baza = HomeWorkChecker::Base.new(@work_path)
10
+ end
11
+ context '#start' do
12
+ it 'extracting should execute 5 times' do
13
+ files_to = double("FileScan", :work_path => @work_path)
14
+ files_to.stub(:files).and_return(@archives)
15
+
16
+ szip_files = stub("HomeWorkChecker::Unarchive::Zip")
17
+ szip_files.should_receive(:new).with("aaa.zip", @tmp_path).once
18
+ szip_files.should_receive(:new).with("bbb.7z", @tmp_path).once
19
+
20
+ run_files = double("HomeWorkChecker::TestRunStat")
21
+ run_files.stub(:detect_language).with("#{@tmp_path}/task1").and_return(".rb")
22
+ rtr = stub(LANGUAGE_TYPES[run_files.detect_language "#{@tmp_path}/task1"])
23
+ rtr.should_receive(:new).with("#{@tmp_path}/task1").once
24
+
25
+ files_to.stub(:each).
26
+ and_yield(stub(szip_files.new(files_to.files[0], @tmp_path)),
27
+ stub(rtr.new("#{@tmp_path}/task1"))).
28
+ and_yield(stub(szip_files.new(files_to.files[1], @tmp_path)))
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,48 @@
1
+ require 'hw_checker'
2
+
3
+ module HomeWorkChecker
4
+ describe FileScan do
5
+ before(:each) do
6
+ @file_scan = FileScan.new('./support')
7
+ end
8
+
9
+ context '.new' do
10
+ def is_all_archives?
11
+ @file_scan.instance_variable_get(:@files).each do |item; ext_name|
12
+ ext_name = File::extname(item)
13
+ return false unless FILE_TYPES.include?(ext_name)
14
+ end
15
+ true
16
+ end
17
+ it 'should have exactly 6 items' do
18
+ @file_scan.instance_variable_get(:@files).should have(7).items
19
+ end
20
+ it 'should contain .zip/7z files only' do
21
+ is_all_archives?.should_not be_false
22
+ end
23
+ end
24
+
25
+ context '#each' do
26
+ before(:each) do
27
+ @file_scan.instance_variable_get(:@files).sort!
28
+ end
29
+ it 'should yield correct data' do
30
+ expect { |b| @file_scan.each(&b) }.to yield_successive_args(
31
+ ["julia.tymo_creational.patterns", ".7z"],
32
+ ["julia.tymo_iterators.in.ruby", ".zip"],
33
+ ["pavlo.petryk_creational.patterns", ".zip"],
34
+ ["pavlo.petryk_final.tasks", ".7z"],
35
+ ["roman.horobets_creational.patterns", ".7z"],
36
+ ["roman.horobets_final.tasks", ".zip"],
37
+ ["roman.horobets_iterators.in.ruby", ".zip"]
38
+ )
39
+ end
40
+ end
41
+
42
+ context '#exist_xml?' do
43
+ it 'xml-file should exist' do
44
+ @file_scan.should_not be_exist_xml('test.xml')
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,30 @@
1
+ require 'hw_checker'
2
+
3
+ module HomeWorkChecker
4
+ module TestRunStat
5
+ describe RubyStat do
6
+ before(:all) do
7
+ @ruby_stat = RubyStat.new('./support', 'julia.tymo_creational.patterns')
8
+ @ruby_stat.perform
9
+ end
10
+
11
+ context '#count_lines_failed' do
12
+ it 'should calculate failed lines correctly' do
13
+ @ruby_stat.instance_variable_get(:@lines_failed).should == 5
14
+ end
15
+ end
16
+
17
+ context '#count_lines_all' do
18
+ it 'should calculate failed lines count correctly' do
19
+ @ruby_stat.instance_variable_get(:@lines_all).should == 7
20
+ end
21
+ end
22
+
23
+ context '#calc_percent_quality' do
24
+ it 'should calculate percent correctly' do
25
+ @ruby_stat.send(:calc_percent_quality).should == 28.57
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,27 @@
1
+ require 'hw_checker'
2
+
3
+ module HomeWorkChecker
4
+ module TestRunStat
5
+ describe RubyTestRun do
6
+ before(:all) do
7
+ @ruby_test_run = RubyTestRun.new('./support', 'julia.tymo_creational.patterns')
8
+ @ruby_test_run.perform
9
+ end
10
+
11
+ context '#count_passed_failed' do
12
+ it 'should calculate passed tests correctly' do
13
+ @ruby_test_run.instance_variable_get(:@passed).should == 0
14
+ end
15
+ it 'should calculate failed tests correctly' do
16
+ @ruby_test_run.instance_variable_get(:@failed).should == 1
17
+ end
18
+ end
19
+
20
+ context '#calc_percent_passed' do
21
+ it 'should calculate percent passed tests correctly' do
22
+ @ruby_test_run.send(:calc_percent_passed).should == 0.00
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,14 @@
1
+ require 'hw_checker'
2
+
3
+ module HomeWorkChecker
4
+ describe HomeWorkChecker::TestRunStat do
5
+ context '.detect_language' do
6
+ before(:each) do
7
+ @detect_test = TestRunStat.detect_language('./support/julia.tymo_creational.patterns')
8
+ end
9
+ it 'should contain .rb/.py tests' do
10
+ @detect_test.should == '.rb'
11
+ end
12
+ end
13
+ end
14
+ end
data/spec/zip_spec.rb ADDED
@@ -0,0 +1,29 @@
1
+ require 'hw_checker'
2
+
3
+ describe HomeWorkChecker::Unarchive::Zip do
4
+ before(:each) do
5
+ @path_filename = './support/julia.tymo_creational.patterns.7z'
6
+ @filename = 'julia.tymo_creational.patterns.7z'
7
+ @tmp_path = '/tmp/support/'
8
+ end
9
+
10
+ after(:each) do
11
+ `rm -rf #{@tmp_path}/#{@filename.chomp(".7z") || filename.chomp(".zip")}`
12
+ end
13
+
14
+ it 'should exist in temp' do
15
+ @unarchive1 = HomeWorkChecker::Unarchive::Zip.new(@path_filename, @tmp_path)
16
+ Dir.exist?("#{@tmp_path}/#{@filename.chomp(".7z") || filename.chomp(".zip")}").should be_true
17
+ end
18
+
19
+ it 'authenticity archive' do
20
+ @authenticity = `7za t #{@path_filename}`
21
+ @authenticity = @authenticity.include? "Everything is Ok"
22
+ @authenticity.should be_true
23
+ end
24
+
25
+ it 'exit code' do
26
+ @unarchive1 = HomeWorkChecker::Unarchive::Zip.new(@path_filename, @tmp_path)
27
+ $?.to_s[-1].to_i.should equal(0)
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hw_checker
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.43
5
+ platform: ruby
6
+ authors:
7
+ - Lv-LAMP-085
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.7.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.7.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - lib/hw_checker/python_test_run.rb
62
+ - lib/hw_checker/ruby_test_run.rb
63
+ - lib/hw_checker/base.rb
64
+ - lib/hw_checker/file_scan.rb
65
+ - lib/hw_checker/unarchive.rb
66
+ - lib/hw_checker/python_stat.rb
67
+ - lib/hw_checker/test_run_stat.rb
68
+ - lib/hw_checker/zip.rb
69
+ - lib/hw_checker/ruby_stat.rb
70
+ - lib/hw_checker.rb
71
+ - bin/hw_checker
72
+ - spec/ruby_stat_spec.rb
73
+ - spec/test_run_stat_spec.rb
74
+ - spec/zip_spec.rb
75
+ - spec/base_spec.rb
76
+ - spec/ruby_test_run_spec.rb
77
+ - spec/file_scan_spec.rb
78
+ homepage:
79
+ licenses: []
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.0.3
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Ruby-based utility to calculate hometasks
101
+ test_files: []