??????β??????????
??????????????д??????????????Щ???????“?????”?????????????????????????????????????????????????????????????????????????????????????????——????Щ??????????????????????????
???????磬????????????д????罻???????????????“??????Facebook?????”????????????????????в???????????????Facebook???
????Python??unittest??????????????unittest.mock——???????????????????????????mock——??????????????????????????????????????????????????Щ???????????????檔
???????mock????????Python 3.3??????е??????????汾??????? PyPI????Mock??
?????????????
????????????????????????????????????μ??????????????????????????Щ?????????????????????????д?????????????CD???????????????web???????????/tmp???μ??????????????????socket???????????TCP??????Щ???????????????????????????????????檔
????????????????????????????????????????????????????????CD??????????????β???????CD?????????
???????????????????????????????????????????????????????CD???????????????????????????????β???????CD???????????????????Σ????????????????е????????????漰?????????????
???????????????????????Ч?????????ζ???????????Щ?????????????“????????”??????????????????????
??????????????????????????????????????????mock????????Python?????????????????????????mockд???????????????????????????????????????????????????????????????
??????????????????
????????????????????????????????????????????д???????????????Python?У??????????????????????????????????????顣
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
def rm(filename):
os.remove(filename)
????????????????????????????rm?????????????os.remove???????????????????????????????????????????????????????????
??????????д????????????????????????????????
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from mymodule import rm
import os.path
import tempfile
import unittestclass
RmTestCase(unittest.TestCase):
tmpfilepath = os.path.join(tempfile.gettempdir()?? "tmp-testfile")    def setUp(self):
with open(self.tmpfilepath?? "wb") as f:
f.write("Delete me!")
def test_rm(self):
# remove the file
rm(self.tmpfilepath)        # test that it was actually removed
self.assertFalse(os.path.isfile(self.tempfile)?? "Failed to remove the file.")
??????????????????????????????????????????????????????????????????????????а???????????rm??????????????os.remove?С?????????????????????????????????????????????