Python??Mock?????????
???????????? ???????[ 2014/1/22 11:27:13 ] ????????Python ????
??????β??????????
??????????????д??????????????Щ???????“?????”?????????????????????????????????????????????????????????????????????????????????????????——????Щ??????????????????????????
???????磬????????????д????罻???????????????“??????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?С?????????????????????????????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11