bash_renamer.py 962 B

1234567891011121314151617181920212223242526272829303132333435
  1. from evaluator import *
  2. DESCRIPTION = "Test if the model can write a bash script that renames files with a specific pattern."
  3. TAGS = ['code', 'bash']
  4. question = """
  5. Write a bash script to rename all files of the form "merged_*" to "finished_*". I want to call it by running bash rename.sh /path/to/files.
  6. """
  7. def setup_fn():
  8. import os
  9. import time
  10. os.mkdir("./foo")
  11. time.sleep(.5)
  12. for i in range(10):
  13. with open("./foo/merged_{}".format(i), "w") as f:
  14. f.write("a"*i)
  15. with open("./foo/{}".format(i), "w") as f:
  16. f.write("a"*i)
  17. time.sleep(.5)
  18. def check_ok():
  19. import os
  20. return sorted(os.listdir("foo")) == sorted(["finished_{}".format(i) for i in range(10)] + [str(i) for i in range(10)])
  21. TestBashRenamer = Setup(setup_fn) >> question >> LLMRun() >> ExtractCode() >> BashRun(args=["foo/"]) >> PyEvaluator(check_ok)
  22. if __name__ == "__main__":
  23. print(run_test(TestBashRenamer))