test_testutils.py 969 B

12345678910111213141516171819202122232425262728293031323334353637
  1. from testutils import test_run_context, cleandir
  2. import unittest
  3. class lstest(test_run_context):
  4. def __init__(self, path, args=[]):
  5. real_args = ["/bin/ls"]
  6. real_args.extend(args)
  7. real_args.append(path)
  8. test_run_context.__init__(self, "/bin/ls", real_args)
  9. self.set_check_std_handles(1, 1, 1)
  10. self.set_expected_exit_code(0)
  11. self.correct_path = path
  12. def check_stdout_valid(self, fullpath):
  13. data = open(fullpath).read().strip()
  14. assert data == self.correct_path, "Expected '%s', got '%s'" % (self.correct_path, data)
  15. class TestLs(unittest.TestCase):
  16. def testfile(self):
  17. l1 = lstest("/etc/passwd")
  18. l1.invoke("./test")
  19. def testdir(self):
  20. l2 = lstest("/tmp", ["-1d"])
  21. l2.invoke("./test")
  22. def testnoexist(self):
  23. l3 = lstest("/etc/scrofulous")
  24. l3.set_check_std_handles(1, 0, 0)
  25. l3.set_expected_exit_code(2)
  26. l3.invoke("./test")
  27. if __name__ == "__main__":
  28. cleandir("./test")
  29. unittest.main()