Jul 22, 2016 15:21
Jul 22, 2016 15:12
Understood. I just edited the question to include my file_count method code.
Jul 22, 2016 15:09
Seriously, post this stuff as an answer. I'll edit the question to include the info about ZipFile and namelist.
Jul 22, 2016 15:08
tyvm, I'll finish the article I'm reading, and look at one or two more, and then try diving back into the code.
Jul 22, 2016 15:07
the epiphany has arrived (I hope)
Jul 22, 2016 15:07
Right, I'd only need to mock the namelist method of ZipFile.
Jul 22, 2016 15:06
If so, I think I'm starting to understand. :)
Jul 22, 2016 15:06
OK, so the current file_count method depends on the zipfile library, the ZipFile class, and its namelist method. You're saying I would mock that?
Jul 22, 2016 15:04
Hold on, launching MacVim, thought it was already open. Want to reference some of the source code for a moment...
Jul 22, 2016 15:02
It's supposed to be. If it turns out it isn't, an exception should be raised.
Jul 22, 2016 15:01
OK, let me turn it around, given an ArchiveFile class that has a file_count method that depends on a file attribute, what would you say should be the "at least one unit test" for it?
Jul 22, 2016 15:00
I apologize, but this is testing only one object (I think). I'm only testing whether one method in one object is working correctly. Aren't I?
Jul 22, 2016 14:59
?
Jul 22, 2016 14:59
What would you call testing the algorithms then
Jul 22, 2016 14:58
By multiple levels, do you mean unit tests to test the interface and other tests to test the actual algorithms?
Jul 22, 2016 14:57
Jul 22, 2016 14:57
Hey there. Thank you very much for your time on this.
Jul 22, 2016 14:55
@Oasiscircle I'll do that, but I'm at the point in ignorance of not knowing that what I'm looking for is mocking (well, until you suggested it :) ). If I understand mocking and its implementation in Python, does that solve my problem? I don't yet know what I don't know.
Jul 22, 2016 14:55
@Oasiscircle I'm reading some articles on Python mocking now, but it sounds like that might not test what I want it to. In testing this particular method, I want to ensure that given an archive, it returns the right number of contained files. Another test I'd want would be, given a non-existent file or a non-archive file, it returns an error. It sounds like mocking would by pass both of those because the objects are virtual? I might be misunderstanding this, of course, and perhaps reading these articles will help.
Jul 22, 2016 14:55
@Oasiscircle, that's the "I'm trying to take the opportunity to learn unit testing" idea. I don't understand mocking, or fixtures. Python tutorials on unit testing seem to assume that I understand these concepts, while unit testing tutorials tend to concentrate on a specific language, such as Java, which I'm not very conversant in. I guess I'm hoping someone can give me an example using Python's unittest module and whatever other built-in Python features I would need for mocking and fixtures.