git-contest 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- OTU4MGU4ZDMzZDI2YTg0NDZkM2YwYjI4MzRiNzY0MjIyZTExMGMyMQ==
5
- data.tar.gz: !binary |-
6
- OGE1NDk3ZTMxODExNWM0YzY1ZjEzNzViOWQ4YjhiNTljYjU4M2RjZQ==
2
+ SHA1:
3
+ metadata.gz: 8b2aca1112bbb292e1a81ae6df50ce2cd7cef637
4
+ data.tar.gz: c2cd797387cd5cc27240b372d0f8ab0671a368fd
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YmU5NGFlMDEwNTYzMTA4ZGZkM2Y1ZWUzOTkwNjc5YzdmMDlhMzU2ZTRjY2Jm
10
- MmI3MzYyNmRhNDI0N2FmZDliNzEwNjMzODJiYzA0MDlkZjllMjM2YzcwNTE5
11
- YzkzMjM0MDQzMmZmZDAxODk4MmU2ZTE1YTE2YWNiOWExNTg3ZDU=
12
- data.tar.gz: !binary |-
13
- YjgxYzc2NDc3YjUyNjVjZGU0ZDYxZTI0ZThmODk0ZGQ1MTVhZWVlOWU1ODdm
14
- YmIxZDZmZGIwODFiOGE0ZWY3MzY3Mzk1YzA3ZTA1MDdiYTAzYTM5ZDgyMTJl
15
- YjEyMjdmNzQ3ZDMzNzk2OTAwMzQ2MDA3MmQ5YzI2MjM0OTRjMmM=
6
+ metadata.gz: 202a71a7e921f2f88f0a1ac2ea5d9965d0c5bf1816fdfbffd588a5c32fd0b4747b22102f617ea8b8247aea63d2cf16560321cc13254ed25ccea4402c06b806b6
7
+ data.tar.gz: 90bf6681ee74840e455dc547ddc2423e880f5df4c309a1b30cbf48d4318b9911c82c085d8f170b41436b61de8403c80ccd5fdb23ead3bb6e46d69befa4e222b3
@@ -11,6 +11,12 @@ require 'rexml/document'
11
11
  module Contest
12
12
  module Driver
13
13
  class AizuOnlineJudge < DriverBase
14
+ def initialize_ext
15
+ @client = Mechanize.new {|agent|
16
+ agent.user_agent_alias = 'Windows IE 7'
17
+ }
18
+ end
19
+
14
20
  def get_opts_ext
15
21
  define_options do
16
22
  opt(
@@ -64,11 +70,7 @@ module Contest
64
70
  def submit_ext
65
71
  # start
66
72
  trigger 'start'
67
- problem_id = "%04d" % @options[:problem_id]
68
-
69
- @client = Mechanize.new {|agent|
70
- agent.user_agent_alias = 'Windows IE 7'
71
- }
73
+ problem_id = normalize_problem_id(@options[:problem_id])
72
74
 
73
75
  # submit
74
76
  trigger 'before_submit', @options
@@ -103,6 +105,12 @@ module Contest
103
105
  get_commit_message(status)
104
106
  end
105
107
 
108
+ private
109
+ # 180 -> 0180
110
+ def normalize_problem_id(problem_id)
111
+ "%04d" % problem_id.to_i
112
+ end
113
+
106
114
  def get_status_wait(user_id, submission_id)
107
115
  # wait result
108
116
  5.times do
@@ -144,16 +152,6 @@ module Contest
144
152
  doc = Nokogiri::HTML body
145
153
  doc.xpath('//table[@id="tableRanking"]//tr[@class="dat"]')[0].search('td')[0].text.strip
146
154
  end
147
-
148
- if is_test_mode?
149
- attr_writer :client
150
- else
151
- private :status_loop
152
- private :get_status_wait
153
- private :is_waiting
154
- private :get_status
155
- private :get_submission_id
156
- end
157
155
  end
158
156
  end
159
157
  end
@@ -25,6 +25,11 @@ module Contest
25
25
  @config["submit_rules"] ||= {}
26
26
  # call DriverEvent#initialize
27
27
  super
28
+ initialize_ext
29
+ end
30
+
31
+ def initialize_ext
32
+ nil
28
33
  end
29
34
 
30
35
  def get_opts_ext
@@ -9,7 +9,13 @@ require 'contest/driver/common'
9
9
 
10
10
  module Contest
11
11
  module Driver
12
- class Codeforces < DriverBase
12
+ class Codeforces < DriverBase
13
+ def initialize_ext
14
+ @client = Mechanize.new {|agent|
15
+ agent.user_agent_alias = 'Windows IE 7'
16
+ }
17
+ end
18
+
13
19
  def get_opts_ext
14
20
  define_options do
15
21
  opt(
@@ -86,10 +92,6 @@ module Contest
86
92
  contest_id = @options[:contest_id]
87
93
  problem_id = @options[:problem_id]
88
94
 
89
- @client = Mechanize.new {|agent|
90
- agent.user_agent_alias = 'Windows IE 7'
91
- }
92
-
93
95
  # login
94
96
  trigger 'before_login'
95
97
  login_page = @client.get 'http://codeforces.com/enter'
@@ -154,6 +156,7 @@ module Contest
154
156
  get_commit_message(status)
155
157
  end
156
158
 
159
+ private
157
160
  def get_status_wait(contest_id, submission_id)
158
161
  contest_id = contest_id.to_s
159
162
  submission_id = submission_id.to_s
@@ -188,15 +191,6 @@ module Contest
188
191
  elements = line.xpath('//td[contains(concat(" ",@class," "), " status-cell ")]')
189
192
  elements[0].attributes()["submissionid"].value.strip
190
193
  end
191
-
192
- if is_test_mode?
193
- attr_writer :client
194
- else
195
- private :get_status_wait
196
- private :is_waiting
197
- private :get_status
198
- private :get_submission_id
199
- end
200
194
  end
201
195
  end
202
196
  end
@@ -19,6 +19,12 @@ require 'contest/driver/common'
19
19
  module Contest
20
20
  module Driver
21
21
  class Kattis < DriverBase
22
+ def initialize_ext
23
+ @client = Mechanize.new {|agent|
24
+ agent.user_agent_alias = 'Windows IE 7'
25
+ }
26
+ end
27
+
22
28
  def get_opts_ext
23
29
  define_options do
24
30
  opt(
@@ -81,10 +87,6 @@ module Contest
81
87
  subdomain = 'open'
82
88
  end
83
89
 
84
- @client = Mechanize.new {|agent|
85
- agent.user_agent_alias = 'Windows IE 7'
86
- }
87
-
88
90
  # Login
89
91
  trigger 'before_login'
90
92
  login_page = @client.get "https://#{subdomain}.kattis.com/login?email_login=true"
@@ -158,11 +160,6 @@ module Contest
158
160
  doc = Nokogiri::HTML(body)
159
161
  return doc.xpath('//td[@class="status"]/span').inner_text().strip
160
162
  end
161
-
162
- if is_test_mode?
163
- attr_writer :client
164
- else
165
- end
166
163
  end
167
164
  end
168
165
  end
@@ -10,6 +10,12 @@ require 'contest/driver/common'
10
10
  module Contest
11
11
  module Driver
12
12
  class UvaOnlineJudge < DriverBase
13
+ def initialize_ext
14
+ @client = Mechanize.new {|agent|
15
+ agent.user_agent_alias = 'Windows IE 7'
16
+ }
17
+ end
18
+
13
19
  def get_opts_ext
14
20
  define_options do
15
21
  opt(
@@ -54,10 +60,6 @@ module Contest
54
60
  trigger 'start'
55
61
  problem_id = @options[:problem_id]
56
62
 
57
- @client = Mechanize.new {|agent|
58
- agent.user_agent_alias = 'Windows IE 7'
59
- }
60
-
61
63
  # submit
62
64
  trigger 'before_login'
63
65
  login_page = @client.get 'http://uva.onlinejudge.org/'
@@ -135,11 +137,6 @@ module Contest
135
137
  end
136
138
  'timeout'
137
139
  end
138
-
139
- if is_test_mode?
140
- attr_writer :client
141
- else
142
- end
143
140
  end
144
141
  end
145
142
  end
@@ -7,6 +7,6 @@
7
7
 
8
8
  module Git
9
9
  module Contest
10
- VERSION = "0.1.1"
10
+ VERSION = "0.1.2"
11
11
  end
12
12
  end
@@ -1,42 +1,50 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe "T004: git-contest-submit command" do
4
- before(:each) do
5
- init_env
6
- ENV['GIT_CONTEST_HOME'] = get_path('/mock/default_config')
7
- ENV['GIT_CONTEST_CONFIG'] = get_path('/mock/t004/config.yml')
8
- @test_dir = "#{ENV['GIT_CONTEST_TEMP_DIR']}/t004"
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
4
+ before do
5
+ ENV['GIT_CONTEST_CONFIG'] = "#{@temp_dir}/config.yml"
6
+ File.open "#{@temp_dir}/config.yml", 'w' do |file|
7
+ file.write <<EOF
8
+ sites:
9
+ test_dummy:
10
+ driver: dummy
11
+ user: dummy
12
+ password: dummy
13
+ test_11111:
14
+ driver: codeforces
15
+ user: dummy
16
+ password: dummy
17
+ test_22222:
18
+ driver: aizu_online_judge
19
+ user: dummy
20
+ password: dummy
21
+ test_33333:
22
+ driver: uva_online_judge
23
+ user: dummy
24
+ password: dummy
25
+ EOF
26
+ end
17
27
  end
18
28
 
19
29
  context "A001: --version" do
20
30
  it "git-contest-submit --version" do
21
31
  ret = `#{bin_path("git-contest-submit")} --version`
22
- ret.should match /git-contest [0-9]+\.[0-9]+\.[0-9]+/
32
+ expect(ret).to match /git-contest [0-9]+\.[0-9]+\.[0-9]+/
23
33
  end
24
34
 
25
35
  it "git-contest submit --version" do
26
36
  ret = `#{bin_path("git-contest submit")} --version`
27
- ret.should match /git-contest [0-9]+\.[0-9]+\.[0-9]+/
37
+ expect(ret).to match /git-contest [0-9]+\.[0-9]+\.[0-9]+/
28
38
  end
29
39
 
30
40
  it "git contest submit --version" do
31
41
  ret = `git contest submit --version`
32
- ret.should match /git-contest [0-9]+\.[0-9]+\.[0-9]+/
42
+ expect(ret).to match /git-contest [0-9]+\.[0-9]+\.[0-9]+/
33
43
  end
34
44
  end
35
45
 
36
46
  context "A002: --help" do
37
47
  before do
38
- Dir.mkdir '002'
39
- Dir.chdir '002'
40
48
  Dir.mkdir 'working'
41
49
  Dir.chdir 'working'
42
50
  File.open 'main.cpp', 'w' do |file|
@@ -47,18 +55,16 @@ describe "T004: git-contest-submit command" do
47
55
  context "B001: dummy driver available only test-mode" do
48
56
  it "git-contest-submit --help" do
49
57
  ret = `#{bin_path('git-contest-submit')} --help`
50
- ret.should include 'test_dummy'
51
- ret.should include 'test_11111'
52
- ret.should include 'test_22222'
53
- ret.should include 'test_33333'
58
+ expect(ret).to include 'test_dummy'
59
+ expect(ret).to include 'test_11111'
60
+ expect(ret).to include 'test_22222'
61
+ expect(ret).to include 'test_33333'
54
62
  end
55
63
  end
56
64
  end
57
65
 
58
66
  context "A003: after init git repo" do
59
67
  before do
60
- Dir.mkdir '003'
61
- Dir.chdir '003'
62
68
  Dir.mkdir 'working'
63
69
  Dir.chdir 'working'
64
70
  File.open 'main.cpp', 'w' do |file|
@@ -72,17 +78,17 @@ describe "T004: git-contest-submit command" do
72
78
 
73
79
  it "git-contest-submit test_dummy -c 100 -p A" do
74
80
  ret_submit = `#{bin_path("git-contest-submit")} test_dummy -c 100 -p A 2>&1`
75
- ret_submit.should include '99999'
76
- ret_submit.should include 'Accepted'
81
+ expect(ret_submit).to include '99999'
82
+ expect(ret_submit).to include 'Accepted'
77
83
  ret_git = `git log --oneline --decorate --graph`
78
- ret_git.should include "Dummy 100A: Accepted"
84
+ expect(ret_git).to include "Dummy 100A: Accepted"
79
85
  end
80
86
  end
81
87
 
82
88
  context "A004: with commit message" do
83
89
  before do
84
- Dir.mkdir '004'
85
- Dir.chdir '004'
90
+ Dir.mkdir 'working'
91
+ Dir.chdir 'working'
86
92
  File.open 'main.cpp', 'w' do |file|
87
93
  file.write 'ac-code'
88
94
  end
@@ -95,14 +101,14 @@ describe "T004: git-contest-submit command" do
95
101
  it "git contest submit test_dummy -c 100 -p A -m '...'" do
96
102
  bin_exec "submit test_dummy -c 100 -p A -m 'this is commit message'"
97
103
  ret = git_do "log --oneline"
98
- ret.should include "this is commit message"
104
+ expect(ret).to include "this is commit message"
99
105
  end
100
106
  end
101
107
 
102
108
  context 'A005: normal submit' do
103
109
  before do
104
- Dir.mkdir '005'
105
- Dir.chdir '005'
110
+ Dir.mkdir 'working'
111
+ Dir.chdir 'working'
106
112
  File.open 'main.cpp', 'w' do |file|
107
113
  file.write 'ac-code'
108
114
  end
@@ -110,25 +116,25 @@ describe "T004: git-contest-submit command" do
110
116
 
111
117
  it "git-contest-submit test_dummy" do
112
118
  ret = `#{bin_path('git-contest-submit')} test_dummy 2>&1`
113
- ret.should include 'Error'
119
+ expect(ret).to include 'Error'
114
120
  end
115
121
 
116
122
  it "git-contest-submit test_dummy -c 100" do
117
123
  ret = `#{bin_path('git-contest-submit')} test_dummy -c 100 2>&1`
118
- ret.should include 'Error'
124
+ expect(ret).to include 'Error'
119
125
  end
120
126
 
121
127
  it "git-contest-submit test_dummy -c 100 -p A" do
122
128
  ret = `#{bin_path('git-contest-submit')} test_dummy -c 100 -p A 2>&1`
123
- ret.should include '99999'
124
- ret.should include 'Accepted'
129
+ expect(ret).to include '99999'
130
+ expect(ret).to include 'Accepted'
125
131
  end
126
132
  end
127
133
 
128
134
  context 'A006: --source' do
129
135
  before do
130
- Dir.mkdir '006'
131
- Dir.chdir '006'
136
+ Dir.mkdir 'working'
137
+ Dir.chdir 'working'
132
138
  end
133
139
 
134
140
  context "B001: submit single file" do
@@ -143,26 +149,26 @@ describe "T004: git-contest-submit command" do
143
149
 
144
150
  it "git contest submit test_dummy -c 100 -p A --source ac.cpp" do
145
151
  ret = bin_exec "submit test_dummy -c 100 -p A --source ac.cpp"
146
- ret.should include '99999'
147
- ret.should include 'Accepted'
152
+ expect(ret).to include '99999'
153
+ expect(ret).to include 'Accepted'
148
154
  end
149
155
 
150
156
  it "git contest submit test_dummy -c 100 -p A -s ac.cpp" do
151
157
  ret = bin_exec "submit test_dummy -c 100 -p A -s ac.cpp"
152
- ret.should include '99999'
153
- ret.should include 'Accepted'
158
+ expect(ret).to include '99999'
159
+ expect(ret).to include 'Accepted'
154
160
  end
155
161
 
156
162
  it "git contest submit test_dummy -c 100 -p A --source wa.cpp" do
157
163
  ret = bin_exec "submit test_dummy -c 100 -p A --source wa.cpp"
158
- ret.should include '99999'
159
- ret.should include 'Wrong Answer'
164
+ expect(ret).to include '99999'
165
+ expect(ret).to include 'Wrong Answer'
160
166
  end
161
167
 
162
168
  it "git contest submit test_dummy -c 100 -p A -s wa.cpp" do
163
169
  ret = bin_exec "submit test_dummy -c 100 -p A -s wa.cpp"
164
- ret.should include '99999'
165
- ret.should include 'Wrong Answer'
170
+ expect(ret).to include '99999'
171
+ expect(ret).to include 'Wrong Answer'
166
172
  end
167
173
  end
168
174
 
@@ -178,38 +184,38 @@ describe "T004: git-contest-submit command" do
178
184
 
179
185
  it "git contest submit test_dummy -c 100 -p A --source 1.cpp,2.cpp" do
180
186
  ret = bin_exec "submit test_dummy -c 100 -p A --source 1.cpp,2.cpp"
181
- ret.should include '99999'
182
- ret.should include 'Wrong Answer'
187
+ expect(ret).to include '99999'
188
+ expect(ret).to include 'Wrong Answer'
183
189
  end
184
190
 
185
191
  it "git contest submit test_dummy -c 100 -p A --source 2.cpp,1.cpp" do
186
192
  ret = bin_exec "submit test_dummy -c 100 -p A --source 2.cpp,1.cpp"
187
- ret.should include '99999'
188
- ret.should include 'Accepted'
193
+ expect(ret).to include '99999'
194
+ expect(ret).to include 'Accepted'
189
195
  end
190
196
 
191
197
  it "git contest submit test_dummy -c 100 -p A -s 1.cpp,2.cpp" do
192
198
  ret = bin_exec "submit test_dummy -c 100 -p A -s 1.cpp,2.cpp"
193
- ret.should include '99999'
194
- ret.should include 'Wrong Answer'
199
+ expect(ret).to include '99999'
200
+ expect(ret).to include 'Wrong Answer'
195
201
  end
196
202
 
197
203
  it "git contest submit test_dummy -c 100 -p A -s 2.cpp,1.cpp" do
198
204
  ret = bin_exec "submit test_dummy -c 100 -p A -s 2.cpp,1.cpp"
199
- ret.should include '99999'
200
- ret.should include 'Accepted'
205
+ expect(ret).to include '99999'
206
+ expect(ret).to include 'Accepted'
201
207
  end
202
208
 
203
209
  it "git contest submit test_dummy -c 100 -p A -s 1.*,2.*" do
204
210
  ret = bin_exec "submit test_dummy -c 100 -p A -s 1.*,2.*"
205
- ret.should include '99999'
206
- ret.should include 'Wrong Answer'
211
+ expect(ret).to include '99999'
212
+ expect(ret).to include 'Wrong Answer'
207
213
  end
208
214
 
209
215
  it "git contest submit test_dummy -c 100 -p A -s 2.*,1.*" do
210
216
  ret = bin_exec "submit test_dummy -c 100 -p A -s 2.*,1.*"
211
- ret.should include '99999'
212
- ret.should include 'Accepted'
217
+ expect(ret).to include '99999'
218
+ expect(ret).to include 'Accepted'
213
219
  end
214
220
  end
215
221
  end