Skip to content

Commit d8ec9fb

Browse files
committed
minor updates
- wrote more tests - fix how exceptions are raised - wrote docs for api()
1 parent 80cf4b9 commit d8ec9fb

File tree

8 files changed

+88
-29
lines changed

8 files changed

+88
-29
lines changed

.readthedocs.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
version: 2
77

88
# Build documentation with MkDocs
9-
#mkdocs:
10-
# configuration: mkdocs.yml
119
mkdocs:
1210
configuration: mkdocs.yml
1311
fail_on_warning: false

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ python:
66

77
install:
88
- pip install -r requirements.txt
9-
- pip install isort black flake8 pylint
109
- pip install codecov
1110
script:
1211
- python tests.py

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
All notable changes to this project will be documented in this file.
44

55
## [1.0] - June , 2020
6-
⚠ Major Update (Breaking Changes)
6+
**Major Update (Breaking Changes)**
77

88
### Added
99
- Add API key authorizations

coderunner/coderunner.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ class ValueTooLargeError(Exception):
6464
class InvalidURL(Exception):
6565
"""Raise when api_url is invalid"""
6666

67-
def __init__(self, message):
68-
super().__init__(message)
69-
7067

7168
class code:
7269
"""
@@ -221,21 +218,15 @@ def getTime(self):
221218

222219
def setFlags(self, options: str):
223220
"""Options for the compiler (i.e. compiler flags)"""
224-
try:
225-
if len(options) > 128:
226-
raise ValueTooLargeError
227-
api_params["compiler_options"] = options
228-
except ValueTooLargeError:
229-
print("Maximum 128 characters allowed")
221+
if len(options) > 128:
222+
raise ValueTooLargeError("Maximum 128 characters allowed")
223+
api_params["compiler_options"] = options
230224

231225
def setArguments(self, arguments: str):
232226
"""Command line arguments for the program"""
233-
try:
234-
if len(arguments) > 128:
235-
raise ValueTooLargeError
236-
api_params["command_line_arguments"] = arguments
237-
except ValueTooLargeError:
238-
print("Maximum 128 characters allowed")
227+
if len(arguments) > 128:
228+
raise ValueTooLargeError("Maximum 128 characters allowed")
229+
api_params["command_line_arguments"] = arguments
239230

240231
def run(self, number_of_runs: int = 1):
241232
"""Submit the source code on judge0's server & return status"""

docs/changelog.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
All notable changes to this project will be documented in this file.
4+
5+
## [1.0] - June , 2020
6+
**Major Update (Breaking Changes)**
7+
8+
### Added
9+
- Add API key authorizations
10+
- Custom API URL support
11+
12+
### Changed
13+
- Due to Judge0 API going [freemium](https://github.com/judge0/api/issues/171), the default API URL, [https://api.judge0.com] is no longer available. To use the API signup for a plan on [RapidAPI](https://rapidapi.com/hermanzdosilovic/api/judge0/pricing)
314

415

516
## [0.8] - May 27, 2020
@@ -8,14 +19,20 @@
819
- Fixed bug where compiling a Java program resulted in Compilation Error.
920

1021

22+
## [0.7] - Jan 19, 2020
23+
24+
### Changed
25+
- `code()` class now ignores `output`. i.e you can just provide source code & language to run a program.
26+
27+
1128
## [0.6] - Jan 5, 2020
1229

1330
### Added
1431

1532
- New optional argument, `number_of_runs` in `run()` method, use this to specify no.of times you want to run the code. Default is set to 1.
1633
- Ported NEW Languages. CodeRunner now supports all languages provided by Judge0.
17-
- [`setFlags(options)`](/usage/#9-setflagsoptions) for setting options for the compiler (i.e. compiler flags).
18-
- [`setArguments(arguments)`](/usage/#10-setargumentsarguments) for setting Command line arguments for the program.
34+
- `setFlags(options)` for setting options for the compiler (i.e. compiler flags).
35+
- `setArguments(arguments)` for setting Command line arguments for the program.
1936

2037
### Changed
2138
- Minor internal improvemets.
@@ -67,7 +84,4 @@ This is effect fixes [#2](https://github.com/codeclassroom/CodeRunner/issues/2).
6784

6885

6986
## [0.1] - Oct 30, 2019
70-
- Initial Release
71-
72-
# Releases
73-
See releases on [PyPi](https://pypi.org/project/coderunner/#history)
87+
- Initial Release

docs/usage.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Usage
22

3-
coderunner provides the following class constructors
3+
coderunner provides the following class.
44

55
### code(source, lang, output, inp, path)
66

@@ -52,6 +52,41 @@ print(r.languages)
5252

5353
Methods available in class `code()`.
5454

55+
### api()
56+
57+
Since v1.0, you need to provide a API Key & URL for using Judge0 through coderunner.
58+
59+
Here is an example on how to do this.
60+
61+
```python
62+
from coderunner import coderunner
63+
import os
64+
from dotenv import load_dotenv
65+
66+
load_dotenv()
67+
68+
source_code = "testfiles/" + "test_python_input.py"
69+
language = "Python3"
70+
output = "testfiles/output/" + "output2.txt"
71+
Input = "testfiles/input/" + "input.txt"
72+
73+
74+
API_KEY = os.environ["API_KEY"]
75+
76+
r = coderunner.code(source_code, language, output, Input)
77+
78+
# Necessary step to initialize API keys & URL
79+
r.api(key=API_KEY)
80+
81+
r.run()
82+
83+
print("Run r :")
84+
print("Status : " + r.getStatus())
85+
print("Output : " + r.getOutput())
86+
````
87+
88+
The default API URL is [https://judge0.p.rapidapi.com/]()
89+
5590
### 1. run()
5691
**Parameters(type)** : Number Of Runs (`int`), optional<br>
5792
**Return Type** : None <br>

mkdocs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ site_name: CodeRunner
22
site_url: https://codeclassroom.github.io/CodeRunner/
33
repo_url: https://github.com/codeclassroom/CodeRunner
44
site_author: Bhupesh Varshney
5-
site_description: CodeRunner v0.5 Documentation
6-
copyright: © 2019, Bhupesh Varshney
5+
site_description: CodeRunner v1.0 Documentation
6+
copyright: © 2020, Bhupesh Varshney
77
nav:
88
- Documentation: index.md
99
- Installation: installation.md

tests.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import unittest
22
from coderunner import coderunner
3-
from coderunner.coderunner import InvalidURL
3+
from coderunner.coderunner import InvalidURL, ValueTooLargeError
44
# # test for Java program
55

66

@@ -174,5 +174,27 @@ def test_run(self):
174174
r.api(key="ABCHE", url="ghthth")
175175

176176

177+
# test to check ValueTooLargeError for Flags
178+
class TestRunP(unittest.TestCase):
179+
def test_run(self):
180+
source_code = 'print("This will return Wrong Answer")'
181+
language = "Python3"
182+
output = "Wrong Answer"
183+
r = coderunner.code(source_code, language, output, path=False)
184+
with self.assertRaises(ValueTooLargeError):
185+
r.setFlags("qw"*70)
186+
187+
188+
# test to check ValueTooLargeError for Arguments
189+
class TestRunQ(unittest.TestCase):
190+
def test_run(self):
191+
source_code = 'print("This will return Wrong Answer")'
192+
language = "Python3"
193+
output = "Wrong Answer"
194+
r = coderunner.code(source_code, language, output, path=False)
195+
with self.assertRaises(ValueTooLargeError):
196+
r.setArguments("qw"*70)
197+
198+
177199
if __name__ == "__main__":
178200
unittest.main()

0 commit comments

Comments
 (0)