vendredi 25 décembre 2020

Python Script for Running Hackerrank tests locally

I found this script for running Hackerrank tests locally. According to the instructions, I should "Just run it in the sample test cases folder that you downloaded from hackerrank."

I have not yet been able to get it to work. I'm not sure what arguments I should pass, and also whether I should unzip the test files first (the code uses rb mode so maybe the zipped ones?)

Can anyone please provide more detail about how to get this working?

# to use with a python3 tested on windows
import subprocess
import sys
cmd = [
    'python',
    sys.argv[1]
]
process = subprocess.Popen(
        cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
        stdin=subprocess.PIPE, shell=True)

input = open(sys.argv[2], "rb").read()
out_file = open(sys.argv[3], "rb").read()
out, err = process.communicate(input)

if err:
    print(err.decode("utf-8"))

out = out[:-1]
if out == out_file:
    print("WIN")
print(out.decode("utf-8"))

Aucun commentaire:

Enregistrer un commentaire