bash_convert_not_overwrite.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. from evaluator import *
  2. DESCRIPTION = "Test if a model can run an incremental update of a bash command without overwriting files that already exist"
  3. TAGS = ['bash']
  4. question = 'Run find . -name "*.pdf" -exec python3 process.py {} txt/{}.txt \; but don\'t rewrite files that already exist. Instead of .pdf.txt make it just .txt'
  5. def setup_fn():
  6. open("process.py", "w").write("import sys\nopen(sys.argv[2], 'w').write(open(sys.argv[1]).read())\n")
  7. open("a.pdf", "w").write("hello1")
  8. open("b.pdf", "w").write("hello2")
  9. open("c.pdf", "w").write("hello3")
  10. import os
  11. os.mkdir("txt")
  12. open("txt/a.txt", "w").write("done1")
  13. open("txt/c.txt", "w").write("done3")
  14. def check_ok():
  15. import os
  16. return open("txt/a.txt").read() == "done1" and open("txt/b.txt").read() == "hello2" and open("txt/c.txt").read() == "done3" and len(os.listdir("txt")) == 3
  17. TestBashIncrementalUpdate = Setup(setup_fn) >> question >> LLMRun() >> ExtractCode(keep_main=True) >> BashRun() >> PyEvaluator(check_ok)
  18. if __name__ == "__main__":
  19. print(run_test(TestBashIncrementalUpdate))