Skip to content

Commit e15b03b

Browse files
committed
fix quality problems
1 parent 6062498 commit e15b03b

File tree

3 files changed

+29
-23
lines changed

3 files changed

+29
-23
lines changed

coderunner/coderunner.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ def __readStatus(self, token: str):
8888
Check Submission status
8989
"""
9090
while True:
91-
req = urllib.request.urlopen(API_URL + token["token"] + FIELDS)
92-
req = req.read()
91+
req = urllib.request.Request(API_URL + token["token"] + FIELDS)
92+
with urllib.request.urlopen(req) as response:
93+
req = response.read()
9394

9495
self.__response = json.loads(req.decode("utf-8"))
9596
self.__memory = self.__response["memory"]
@@ -112,8 +113,9 @@ def __submit(self):
112113
api_params["source_code"] = self.source
113114

114115
post_data = urllib.parse.urlencode(api_params).encode("ascii")
115-
req = urllib.request.urlopen(API_URL, post_data)
116-
req = req.read()
116+
req = urllib.request.Request(API_URL, post_data)
117+
with urllib.request.urlopen(req) as response:
118+
req = response.read()
117119
token = json.loads(req.decode("utf-8"))
118120

119121
return token

testfiles/test_python.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
print("Hello, World!")
1+
print("Hello, World!")

tests.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,12 @@ def test_run(self):
127127
class TestRunI(unittest.TestCase):
128128

129129
def test_run(self):
130-
with self.assertRaises(ValueError): coderunner.code(
131-
"Hello World",
132-
"PHP",
133-
"Hello World",
134-
path = False
130+
with self.assertRaises(ValueError):
131+
coderunner.code(
132+
"Hello World",
133+
"PHP",
134+
"Hello World",
135+
path=False
135136
)
136137

137138

@@ -141,10 +142,11 @@ def test_run(self):
141142
class TestRunJ(unittest.TestCase):
142143

143144
def test_run(self):
144-
with self.assertRaises(OSError): coderunner.code(
145-
"Hello World",
146-
"C++",
147-
"Hello World"
145+
with self.assertRaises(OSError):
146+
coderunner.code(
147+
"Hello World",
148+
"C++",
149+
"Hello World"
148150
)
149151

150152

@@ -154,10 +156,11 @@ def test_run(self):
154156
class TestRunK(unittest.TestCase):
155157

156158
def test_run(self):
157-
with self.assertRaises(OSError): coderunner.code(
158-
"testfiles/" + "test_c++.cpp",
159-
"C++",
160-
"Hello World"
159+
with self.assertRaises(OSError):
160+
coderunner.code(
161+
"testfiles/" + "test_c++.cpp",
162+
"C++",
163+
"Hello World"
161164
)
162165

163166

@@ -167,11 +170,12 @@ def test_run(self):
167170
class TestRunL(unittest.TestCase):
168171

169172
def test_run(self):
170-
with self.assertRaises(OSError): coderunner.code(
171-
"testfiles/" + "test_c++.cpp",
172-
"C++",
173-
"testfiles/output/" + "output4.txt",
174-
"my_input"
173+
with self.assertRaises(OSError):
174+
coderunner.code(
175+
"testfiles/" + "test_c++.cpp",
176+
"C++",
177+
"testfiles/output/" + "output4.txt",
178+
"my_input"
175179
)
176180

177181

0 commit comments

Comments
 (0)