Skip to content

Commit

Permalink
Merge pull request #61 from gradescope/skaminsky/GSC-1318/update-exam…
Browse files Browse the repository at this point in the history
…ples-to-python-3

Upgrade GS Python Autograder Examples to Use Python 3
  • Loading branch information
ThaumicMekanism committed Oct 5, 2021
2 parents 8de191f + fa91745 commit b55e7f5
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 25 deletions.
2 changes: 1 addition & 1 deletion diff/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
gradescope-utils>=0.2.6
gradescope-utils>=0.3.1
subprocess32
2 changes: 1 addition & 1 deletion diff/run_autograder
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ cd /autograder/source

make fib

python run_tests.py > /autograder/results/results.json
python3 run_tests.py
3 changes: 2 additions & 1 deletion diff/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@

if __name__ == '__main__':
suite = unittest.defaultTestLoader.discover('tests')
JSONTestRunner(visibility='visible').run(suite)
with open('/autograder/results/results.json', 'w') as f:
JSONTestRunner(visibility='visible', stream=f).run(suite)
4 changes: 2 additions & 2 deletions diff/setup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash

apt-get install -y python python-pip python-dev
apt-get install -y python3 python3-pip python3-dev

pip install -r /autograder/source/requirements.txt
pip3 install -r /autograder/source/requirements.txt
2 changes: 1 addition & 1 deletion diff/tests/test_from_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_from_file(self):
"""10th Fibonacci number"""
fib = subprocess.Popen(["./fib", "10"], stdout=subprocess.PIPE)
output = fib.stdout.read().strip()
with open("reference/10", "r") as outputFile:
with open("reference/10", "rb") as outputFile:
referenceOutput = outputFile.read()

self.assertEqual(output, referenceOutput)
Expand Down
16 changes: 8 additions & 8 deletions diff/tests/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ def test_no_args(self):
"""Invalid Input (no argument)"""
fib = subprocess.Popen(["./fib"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = fib.stdout.read().strip()
self.assertEqual(output, "")
self.assertEqual(output, b"")
err = fib.stderr.read().strip()
referenceOutput = "Error: Insufficient arguments."
referenceOutput = b"Error: Insufficient arguments."
self.assertEqual(err, referenceOutput)
fib.terminate()

Expand All @@ -23,9 +23,9 @@ def test_fib0(self):
"""Invalid Input (0)"""
fib = subprocess.Popen(["./fib", "0"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = fib.stdout.read().strip()
self.assertEqual(output, "")
self.assertEqual(output, b"")
err = fib.stderr.read().strip()
referenceOutput = "Error: number must be greater than 0."
referenceOutput = b"Error: number must be greater than 0."
self.assertEqual(err, referenceOutput)
fib.terminate()

Expand All @@ -34,7 +34,7 @@ def test_fib1(self):
"""1st Fibonacci Number"""
fib = subprocess.Popen(["./fib", "1"], stdout=subprocess.PIPE)
output = fib.stdout.read().strip()
referenceOutput = "1"
referenceOutput = b"1"
self.assertEqual(output, referenceOutput)
fib.terminate()

Expand All @@ -43,7 +43,7 @@ def test_fib2(self):
"""2nd Fibonacci Number"""
fib = subprocess.Popen(["./fib", "2"], stdout=subprocess.PIPE)
output = fib.stdout.read().strip()
referenceOutput = "1"
referenceOutput = b"1"
self.assertEqual(output, referenceOutput)
fib.terminate()

Expand All @@ -52,7 +52,7 @@ def test_fib3(self):
"""3rd Fibonacci Number"""
fib = subprocess.Popen(["./fib", "3"], stdout=subprocess.PIPE)
output = fib.stdout.read().strip()
referenceOutput = "2"
referenceOutput = b"2"
self.assertEqual(output, referenceOutput)
fib.terminate()

Expand All @@ -61,6 +61,6 @@ def test_fib4(self):
"""4th Fibonacci number"""
fib = subprocess.Popen(["./fib", "4"], stdout=subprocess.PIPE)
output = fib.stdout.read().strip()
referenceOutput = "3"
referenceOutput = b"3"
self.assertEqual(output, referenceOutput)
fib.terminate()
2 changes: 1 addition & 1 deletion diff_general/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
gradescope-utils>=0.2.6
gradescope-utils>=0.3.1
subprocess32
pyyaml
2 changes: 1 addition & 1 deletion diff_general/run_autograder
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ cd /autograder/source

bash ./compile.sh

python run_tests.py > /autograder/results/results.json
python3 run_tests.py
3 changes: 2 additions & 1 deletion diff_general/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
klass = build_test_class(name)
suite.addTest(klass(TestMetaclass.test_name(name)))

JSONTestRunner(visibility='visible').run(suite)
with open('/autograder/results/results.json', 'w') as f:
JSONTestRunner(visibility='visible', stream=f).run(suite)
4 changes: 2 additions & 2 deletions diff_general/setup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash

apt-get install -y python python-pip python-dev
apt-get install -y python3 python3-pip python3-dev

pip install -r /autograder/source/requirements.txt
pip3 install -r /autograder/source/requirements.txt
2 changes: 1 addition & 1 deletion diff_general/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def generate_test(cls, dir_name):
def load_test_file(path):
full_path = os.path.join(BASE_DIR, dir_name, path)
if os.path.isfile(full_path):
with open(full_path) as f:
with open(full_path, 'rb') as f:
return f.read()
return None

Expand Down
Binary file modified mysql/autograder.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion mysql/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
gradescope-utils>=0.2.7
gradescope-utils>=0.3.1
subprocess32
mysql-connector-python
2 changes: 1 addition & 1 deletion mysql/run_autograder
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ cp /autograder/submission/queries.py /autograder/source/queries.py

cd /autograder/source

python run_tests.py > /autograder/results/results.json
python3 run_tests.py
3 changes: 2 additions & 1 deletion mysql/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@

if __name__ == '__main__':
suite = unittest.defaultTestLoader.discover('tests')
JSONTestRunner(visibility='visible').run(suite)
with open('/autograder/results/results.json', 'w') as f:
JSONTestRunner(visibility='visible', stream=f).run(suite)
4 changes: 2 additions & 2 deletions mysql/setup.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env bash

apt-get install -y python python-pip python-dev mysql-server
apt-get install -y python3 python3-pip python3-dev mysql-server

pip install -r /autograder/source/requirements.txt
pip3 install -r /autograder/source/requirements.txt

# Start MySQL server
# will need to start again in run_autograder (this is just for importing data)
Expand Down

0 comments on commit b55e7f5

Please sign in to comment.