unit testing - Mocking Directory Structure in Python -


I have some code under which I input the files to open and process and then to output some data I am using. I have got working functionality and I am testing this unit now, is an example of the code given below

  def foo (dir):. Path_to_search = join dir ( "/ baz / foo") isdir (path_to_search) if: (path_to_search #path exists when things fname in listdir ...): do_stuff () else: print "The path does not exist "I am able to prepare a test where the past is not adequately present, but as you can see above, I claim that the directory structure" / Baz / foo "part is present (in the directory structure the output should be in the file, in some cases It will not and we will not have to process it.)  

I have to create a temporary directory structure using TempDir and try to join, but the code is always said that the path does not exist < / P>

Is it possible to duplicate the output of oslistdir that I will not need to create a temporary directory structure which follows the required / falcon / ef conferencing?

You do not need to create a duplicate directory structure, all you need to do is duplicate and listdir () functions

(or external, which is the same version of python versions, 3.3). : # Python & gt; = 3.3 Imports, except import, are the only impersonation importer: #Python & lt; mock.patch ( 'yourmodule.isdir') mocked_isdir, \ mock.patch ( 'mocked_listdir as 3.3 import fake with as yourmodule.listdir'): mocked_isdir.return_value = true mocked_listdir.return_value = [ 'filename1', 'filename2'] yourmodule .foo ( '/ Spam / eggs') mocked_isdir.assert_called_with ( '/ Spam / eggs / baz / foo') mocked_listdir.assert_called_with ( '/ Spam / eggs / baz / foo') < / Pre>


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -