git-contest 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +13 -5
  2. data/.travis.yml +1 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +22 -25
  5. data/bin/git-contest +2 -2
  6. data/bin/git-contest-finish +2 -2
  7. data/bin/git-contest-init +2 -2
  8. data/bin/git-contest-rebase +2 -2
  9. data/bin/git-contest-start +2 -2
  10. data/bin/git-contest-submit +34 -17
  11. data/git-contest.gemspec +2 -2
  12. data/lib/contest/driver.rb +3 -0
  13. data/lib/contest/driver/aizu_online_judge.rb +12 -12
  14. data/lib/contest/driver/base.rb +44 -19
  15. data/lib/contest/driver/codeforces.rb +21 -15
  16. data/lib/contest/driver/common.rb +21 -5
  17. data/lib/contest/driver/driver_event.rb +1 -1
  18. data/lib/contest/driver/kattis.rb +168 -0
  19. data/lib/contest/driver/uva_online_judge.rb +14 -11
  20. data/lib/git/contest/version.rb +2 -2
  21. data/spec/bin/t004_git_contest_submit_spec.rb +143 -69
  22. data/spec/lib/contest/driver/t001_aizu_online_judge_spec.rb +46 -29
  23. data/spec/lib/contest/driver/t002_codeforces_spec.rb +185 -20
  24. data/spec/lib/contest/driver/t003_uva_online_judge_spec.rb +157 -10
  25. data/spec/lib/contest/driver/t010_kattis_spec.rb +207 -0
  26. data/spec/mock/default_config/plugins/driver_dummy.rb +31 -11
  27. data/spec/mock/t002/codeforces_after_submit.html +45 -0
  28. data/spec/mock/t002/codeforces_enter.html +67 -0
  29. data/spec/mock/t002/codeforces_submit.html +110 -0
  30. data/spec/mock/t002/codeforces_wait_result.html +58 -0
  31. data/spec/mock/t003/uva_after_quick_submit.html +17 -0
  32. data/spec/mock/t003/uva_home.html +39 -0
  33. data/spec/mock/t003/uva_my_submissions.html +111 -0
  34. data/spec/mock/t003/uva_quick_submit.html +67 -0
  35. data/spec/mock/t010/open_kattis_com_login.html +20 -0
  36. data/spec/mock/t010/open_kattis_com_submit.html +54 -0
  37. data/spec/mock/t010/open_kattis_com_user_submissions.html +28 -0
  38. data/spec/mock/t010/user_submission_111111.html +30 -0
  39. data/spec/mock/t010/user_submission_222222.html +79 -0
  40. data/spec/mock/t010/user_submissions.html +39 -0
  41. metadata +58 -27
@@ -3,31 +3,178 @@ require 'spec_helper'
3
3
  require 'contest/driver/codeforces'
4
4
  require 'mechanize'
5
5
 
6
- describe "T003: Contest::Driver::UvaOnlineJudge" do
7
- before do
6
+ describe "T003: UvaOnlineJudge Driver" do
7
+ before :each do
8
+ @test_dir = "#{ENV['GIT_CONTEST_TEMP_DIR']}/t003"
9
+ Dir.mkdir @test_dir
10
+ Dir.chdir @test_dir
11
+ end
12
+
13
+ after :each do
14
+ Dir.chdir @test_dir
15
+ Dir.chdir '..'
16
+ FileUtils.remove_dir @test_dir, :force => true
17
+ end
18
+
19
+ before(:each) do
8
20
  @driver = Contest::Driver::UvaOnlineJudge.new
9
21
  @driver.stub(:sleep).and_return(0)
10
- @driver.client = Mechanize.new {|agent|
11
- agent.user_agent_alias = 'Windows IE 7'
12
- }
13
22
  end
14
23
 
15
- describe '001: #get_submission_id' do
16
- it '001' do
24
+ context "A001: #get_submission_id" do
25
+ it "should return last submission id" do
17
26
  ret = @driver.get_submission_id(read_file('/mock/t003/after_submit.html'))
18
27
  ret.should eq '99999'
19
28
  end
20
29
  end
21
30
 
22
- describe '002: #get_submission_status' do
23
- it '001: Sent to Judge' do
31
+ context "A002: #get_submission_status" do
32
+ it "Sent to judge" do
24
33
  ret = @driver.get_submission_status('99999', read_file('/mock/t003/my_submissions.sent_to_judge.html'))
25
34
  ret.should eq 'Sent to judge'
26
35
  end
27
- it '002: Compile Error' do
36
+
37
+ it "Compilation error" do
28
38
  ret = @driver.get_submission_status('99999', read_file('/mock/t003/my_submissions.compile_error.html'))
29
39
  ret.should eq 'Compilation error'
30
40
  end
31
41
  end
42
+
43
+ context "A003: #submit" do
44
+ before do
45
+ FileUtils.touch 'test_source.java'
46
+ end
47
+
48
+ before do
49
+ # index.html
50
+ WebMock
51
+ .stub_request(
52
+ :get,
53
+ /^http:\/\/uva\.onlinejudge\.org\/$/,
54
+ )
55
+ .to_return(
56
+ :status => 200,
57
+ :body => read_file('/mock/t003/uva_home.html'),
58
+ :headers => {
59
+ 'Content-Type' => 'text/html',
60
+ },
61
+ )
62
+
63
+ # login
64
+ WebMock
65
+ .stub_request(
66
+ :post,
67
+ /^http:\/\/uva\.onlinejudge\.org\/index\.php\?option=com_comprofiler&task=login$/,
68
+ )
69
+ .to_return(
70
+ :status => 200,
71
+ :headers => {
72
+ 'Content-Type' => 'text/html',
73
+ },
74
+ )
75
+
76
+ # quick submit page
77
+ WebMock
78
+ .stub_request(
79
+ :get,
80
+ /^http:\/\/uva\.onlinejudge\.org\/index\.php\?Itemid=25&option=com_onlinejudge$/,
81
+ )
82
+ .to_return(
83
+ :status => 200,
84
+ :body => read_file('/mock/t003/uva_quick_submit.html'),
85
+ :headers => {
86
+ 'Content-Type' => 'text/html',
87
+ },
88
+ )
89
+
90
+ # quick submit
91
+ WebMock
92
+ .stub_request(
93
+ :post,
94
+ /^http:\/\/uva\.onlinejudge\.org\/index\.php\?Itemid=25&option=com_onlinejudge&page=save_submission$/,
95
+ )
96
+ .to_return(
97
+ :status => 200,
98
+ :body => read_file('/mock/t003/uva_after_quick_submit.html'),
99
+ :headers => {
100
+ 'Content-Type' => 'text/html',
101
+ },
102
+ )
103
+
104
+ # status
105
+ WebMock
106
+ .stub_request(
107
+ :get,
108
+ /^http:\/\/uva\.onlinejudge\.org\/index\.php\?Itemid=9&option=com_onlinejudge$/
109
+ )
110
+ .to_return(
111
+ :status => 200,
112
+ :body => read_file('/mock/t003/uva_my_submissions.html'),
113
+ :headers => {
114
+ 'Content-Type' => 'text/html',
115
+ },
116
+ )
117
+ end
118
+
119
+ it "should return commit message" do
120
+ @driver.config.merge!(
121
+ "user" => "test_user",
122
+ "password" => "password",
123
+ )
124
+ @driver.options.merge!(
125
+ :problem_id => '333333',
126
+ :source => 'test_source.java',
127
+ )
128
+ @driver.submit.should include "UVa 333333: Wrong answer"
129
+ end
130
+
131
+ it "Check events" do
132
+ @flag_start = false
133
+ @flag_before_submit = false
134
+ @flag_after_submit = false
135
+ @flag_before_wait = false
136
+ @flag_after_wait = false
137
+ @flag_finish = false
138
+
139
+ proc_start = Proc.new do
140
+ @flag_start = true
141
+ end
142
+ proc_before_submit = Proc.new do |info|
143
+ @flag_before_submit = true
144
+ end
145
+ proc_after_submit = Proc.new do
146
+ @flag_after_submit = true
147
+ end
148
+ proc_before_wait = Proc.new do
149
+ @flag_before_wait = true
150
+ end
151
+ proc_after_wait = Proc.new do
152
+ @flag_after_wait = true
153
+ end
154
+ proc_finish = Proc.new do
155
+ @flag_finish = true
156
+ end
157
+
158
+ @driver.on 'start', proc_start
159
+ @driver.on 'before_submit', proc_before_submit
160
+ @driver.on 'after_submit', proc_after_submit
161
+ @driver.on 'before_wait', proc_before_wait
162
+ @driver.on 'after_wait', proc_after_wait
163
+ @driver.on 'finish', proc_finish
164
+
165
+ @driver.config.merge!(
166
+ "user" => "test_user",
167
+ "password" => "password",
168
+ )
169
+ @driver.options.merge!(
170
+ :problem_id => '333333',
171
+ :source => 'test_source.java',
172
+ )
173
+ @driver.submit()
174
+
175
+ @flag = @flag_start && @flag_before_submit && @flag_after_submit && @flag_before_wait && @flag_after_wait && @flag_finish
176
+ @flag.should === true
177
+ end
178
+ end
32
179
  end
33
180
 
@@ -0,0 +1,207 @@
1
+ require "spec_helper"
2
+ require "contest/driver/kattis"
3
+
4
+ describe "T010: Kattis Driver" do
5
+ before :each do
6
+ @test_dir = "#{ENV['GIT_CONTEST_TEMP_DIR']}/t010"
7
+ Dir.mkdir @test_dir
8
+ Dir.chdir @test_dir
9
+ end
10
+
11
+ after :each do
12
+ Dir.chdir @test_dir
13
+ Dir.chdir '..'
14
+ FileUtils.remove_dir @test_dir, :force => true
15
+ end
16
+
17
+ before do
18
+ @driver = Contest::Driver::Kattis.new
19
+ @driver.stub(:sleep).and_return(0)
20
+ end
21
+
22
+ context "A001: #get_submission_id" do
23
+ subject do
24
+ dummy_html = read_file('/mock/t010/user_submissions.html')
25
+ @driver.get_submission_id dummy_html
26
+ end
27
+ it "must return last submission id" do
28
+ should eq "111111"
29
+ end
30
+ end
31
+
32
+ context "A002: #get_submissions_status" do
33
+ context "111111" do
34
+ subject do
35
+ dummy_html = read_file('/mock/t010/user_submission_111111.html')
36
+ @driver.get_submission_status "111111", dummy_html
37
+ end
38
+ it "must return the status of specified submission" do
39
+ should eq "Accepted"
40
+ end
41
+ end
42
+ context "222222" do
43
+ subject do
44
+ dummy_html = read_file('/mock/t010/user_submission_222222.html')
45
+ @driver.get_submission_status "222222", dummy_html
46
+ end
47
+ it "must return the status of specified submission" do
48
+ should eq "Wrong Answer"
49
+ end
50
+ end
51
+ end
52
+
53
+ context "A003: #submit" do
54
+ before do
55
+ FileUtils.touch 'test_source.go'
56
+ end
57
+
58
+ before do
59
+ # login page
60
+ WebMock.stub_request(
61
+ :get,
62
+ /^https:\/\/open\.kattis\.com\/login\?email_login=true$/
63
+ )
64
+ .to_return(
65
+ :status => 200,
66
+ :body => read_file('/mock/t010/open_kattis_com_login.html'),
67
+ :headers => {
68
+ 'Content-Type' => 'text/html',
69
+ },
70
+ )
71
+
72
+ # login
73
+ WebMock.stub_request(
74
+ :post,
75
+ /^https:\/\/open\.kattis\.com\/login\?email_login=true$/
76
+ )
77
+ .to_return(
78
+ :status => 200,
79
+ :headers => {
80
+ 'Content-Type' => 'text/html',
81
+ },
82
+ )
83
+
84
+ # submit page
85
+ WebMock.stub_request(
86
+ :get,
87
+ /^https:\/\/open\.kattis\.com\/submit$/,
88
+ )
89
+ .to_return(
90
+ :status => 200,
91
+ :body => read_file('/mock/t010/open_kattis_com_submit.html'),
92
+ :headers => {
93
+ 'Content-Type' => 'text/html',
94
+ },
95
+ )
96
+
97
+ # submit
98
+ WebMock.stub_request(
99
+ :post,
100
+ /^https:\/\/open\.kattis\.com\/submit$/,
101
+ )
102
+ .to_return(
103
+ :status => 200,
104
+ :headers => {
105
+ 'Content-Type' => 'text/html',
106
+ },
107
+ )
108
+
109
+ # user submissions
110
+ WebMock.stub_request(
111
+ :get,
112
+ /^https:\/\/open\.kattis\.com\/users\/test_user\?show=submissions$/
113
+ )
114
+ .to_return(
115
+ :status => 200,
116
+ :body => read_file('/mock/t010/open_kattis_com_user_submissions.html'),
117
+ :headers => {
118
+ 'Content-Type' => 'text/html',
119
+ },
120
+ )
121
+
122
+ # submission 999999
123
+ WebMock.stub_request(
124
+ :get,
125
+ /^https:\/\/open\.kattis\.com\/submission\?id=999999$/
126
+ )
127
+ .to_return(
128
+ :status => 200,
129
+ :body => read_file('/mock/t010/open_kattis_com_user_submissions.html'),
130
+ :headers => {
131
+ 'Content-Type' => 'text/html',
132
+ },
133
+ )
134
+ end
135
+
136
+ it "should return commit message" do
137
+ @driver.config.merge!(
138
+ "user" => "test_user",
139
+ "password" => "password",
140
+ )
141
+ @driver.options.merge!(
142
+ :problem_id => '333333',
143
+ :source => 'test_source.go',
144
+ )
145
+ @driver.submit.should include "Kattis 333333: Wrong Answer"
146
+ end
147
+
148
+ it "check events" do
149
+ @flag_start = false
150
+ @flag_before_login = false
151
+ @flag_after_login = false
152
+ @flag_before_submit = false
153
+ @flag_after_submit = false
154
+ @flag_before_wait = false
155
+ @flag_after_wait = false
156
+ @flag_finish = false
157
+
158
+ proc_start = Proc.new do
159
+ @flag_start = true
160
+ end
161
+ proc_before_login = Proc.new do |info|
162
+ @flag_before_login = true
163
+ end
164
+ proc_after_login = Proc.new do
165
+ @flag_after_login = true
166
+ end
167
+ proc_before_submit = Proc.new do |info|
168
+ @flag_before_submit = true
169
+ end
170
+ proc_after_submit = Proc.new do
171
+ @flag_after_submit = true
172
+ end
173
+ proc_before_wait = Proc.new do
174
+ @flag_before_wait = true
175
+ end
176
+ proc_after_wait = Proc.new do
177
+ @flag_after_wait = true
178
+ end
179
+ proc_finish = Proc.new do
180
+ @flag_finish = true
181
+ end
182
+
183
+ @driver.on 'start', proc_start
184
+ @driver.on 'before_login', proc_before_login
185
+ @driver.on 'after_login', proc_after_login
186
+ @driver.on 'before_submit', proc_before_submit
187
+ @driver.on 'after_submit', proc_after_submit
188
+ @driver.on 'before_wait', proc_before_wait
189
+ @driver.on 'after_wait', proc_after_wait
190
+ @driver.on 'finish', proc_finish
191
+
192
+ @driver.config.merge!(
193
+ "user" => "test_user",
194
+ "password" => "password",
195
+ )
196
+ @driver.options.merge!(
197
+ :problem_id => '333333',
198
+ :source => 'test_source.go',
199
+ )
200
+ @driver.submit
201
+
202
+ @flag = @flag_start && @flag_before_login && @flag_after_login && @flag_before_submit && @flag_after_submit && @flag_before_wait && @flag_after_wait && @flag_finish
203
+ @flag.should === true
204
+ end
205
+ end
206
+ end
207
+
@@ -64,15 +64,20 @@ module Contest
64
64
  end
65
65
  end
66
66
 
67
- def submit_ext(config, source_path, options)
67
+ def submit_ext
68
68
  # start
69
69
  trigger 'start'
70
70
 
71
71
  # submit
72
+ if @options[:source].is_a? Array
73
+ source_text = @options[:source].join(", ")
74
+ else
75
+ source_text = @options[:source]
76
+ end
72
77
  trigger(
73
78
  'before_submit',
74
79
  {
75
- :source => source_path
80
+ :source => source_text
76
81
  },
77
82
  )
78
83
  trigger 'after_submit'
@@ -82,22 +87,37 @@ module Contest
82
87
 
83
88
  # wait result
84
89
  status = ''
85
- File.open source_path, 'r' do |file|
86
- line = file.read
87
- if line == 'wa-code'
88
- status = 'Wrong Answer'
89
- elsif line == 'ac-code'
90
- status = 'Accepted'
91
- elsif line == 'tle-code'
92
- status = 'Time Limit Exceeded'
90
+
91
+ if @options[:source].is_a? Array
92
+ File.open @options[:source][0], 'r' do |file|
93
+ line = file.read
94
+ if line == 'wa-code'
95
+ status = 'Wrong Answer'
96
+ elsif line == 'ac-code'
97
+ status = 'Accepted'
98
+ elsif line == 'tle-code'
99
+ status = 'Time Limit Exceeded'
100
+ end
101
+ end
102
+ elsif @options[:source].is_a? String
103
+ File.open @options[:source], 'r' do |file|
104
+ line = file.read
105
+ if line == 'wa-code'
106
+ status = 'Wrong Answer'
107
+ elsif line == 'ac-code'
108
+ status = 'Accepted'
109
+ elsif line == 'tle-code'
110
+ status = 'Time Limit Exceeded'
111
+ end
93
112
  end
94
113
  end
114
+
95
115
  trigger(
96
116
  'after_wait',
97
117
  {
98
118
  :submission_id => '99999',
99
119
  :status => status,
100
- :result => get_commit_message($config["submit_rules"]["message"], status, options),
120
+ :result => get_commit_message(status),
101
121
  }
102
122
  )
103
123
  trigger 'finish'