check_result.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import sys
  2. def have_string(filename, text):
  3. data = open(filename, "rb").read()
  4. if data.find(text) > 0:
  5. return True
  6. else:
  7. return False
  8. def mark(case_number, result, description):
  9. if result:
  10. f = open(case_number+"_PASS.txt", "wb")
  11. f.close()
  12. print("\n\n"+case_number+" PASS\n\n")
  13. else:
  14. f = open(case_number+"_FAIL.txt", "wb")
  15. f.write(description)
  16. f.close()
  17. print("\n\n"+case_number+" FAIL\n\n")
  18. def parse_condition(condition):
  19. if condition.find("==") > 0:
  20. r = condition.split("==")
  21. return r[0], r[1], True
  22. elif condition.find("!=") > 0:
  23. r = condition.split("!=")
  24. return r[0], r[1], False
  25. else:
  26. print("\ncondition syntax error\n\n\n")
  27. sys.exit("condition syntax error")
  28. def main():
  29. case_number = sys.argv[1]
  30. description = ""
  31. conclustion = True
  32. for condition in sys.argv[2:]:
  33. filename, text, result = parse_condition(condition)
  34. if have_string(filename, text) == result:
  35. pass
  36. else:
  37. conclustion = False
  38. description = description + "\n" + condition + " failed\n"
  39. mark(case_number, conclustion, description)
  40. if __name__ == "__main__":
  41. main()