vendredi 8 mai 2015

How to test opened files in argparse using nose

So I'm trying to test my parser using nose. I have few arguments that are used for handling files using type=argparse.FileType().

When I print out my parser's parser_args() function, my filename argument is of course specified, looks like this:

Namespace(command_name='edit', filename=[<open file 'filename.p', mode 'r' at 0x108d4e1e0>])

Now I want to test this using nose testing framework, specifically checking if the correct filename was indeed opened but I don't know exactly how.

When I do this (test_sys_args is modified sys.argv list for testing purposes):

test_parser = test_parser_output(test_sys_args) assert_equal(test_parser.filename, "[<open file 'filename.p', mode 'r' at 0x108d4e1e0>]")

It doesn't work. I know I'm not doing this right because the memory address might be different each time the test is run and I'm also not sure if I can pass the filename object as a string like that.

Aucun commentaire:

Enregistrer un commentaire