Hi Apollon
Am 21. Dezember 2010 14:53 schrieb Apollon Oikonomopoulos
<[email protected]>:
> That was the test case I was thinking of too (see cover letter).
>
> Revised patch with unittest follows.
Thanks for the update and sorry for the delay.
> + def testNocloseFds(self):
> + """Test selective fd retention (noclose_fds)"""
> + temp = open(self.fname, "w")
> + temp.write("test")
> + temp.flush()
You should seek to the file's beginning here, no?
> + cmd = "cat /dev/fd/%d" % temp.fileno()
Could you please use the built-in “read”? "read -u %s </dev/null"
> + result = RunCmd(["/bin/bash", "-c", cmd])
> + self.assertEqual(result.exit_code, 1)
And seek again here.
> + result = RunCmd(["/bin/bash", "-c", cmd], noclose_fds=[temp.fileno()])
> + self.assertEqual(result.exit_code, 0)
> + self.assertEqual(result.stdout.strip(), "test")
> + temp.close()
Use:
temp = open(…)
try:
temp.write(…)
…
finally:
temp.close()
Rest looks good.
Michael