So here is how to mock argparse's Namespace behaviour. it can be used at two places at the time of testing or what if argparse module is not there, but the user of your application is not aware of it and you don't want to disappoint him,
I have been thinking from a while that I will write on mox testing, a well written code is only perfect if its logic/ behaviour is tested under different possible scenarios, In simple word, we can put the system under test and testify the result with the expected output but in some cases we do not want to execute a dependent method/function. So just to test the actual method only we can mock the dependent method.
We can also mock in case when there is a UI involved and input comes from the user(though it is better to keep the UI code separate from the actual logic) or some URL that may or may not be live , so we can mock a URL.
Startting off with a basic example I will be posting in future post of more things we can do with mox.
in the above code, I have mocked method name stringList,(that may not be the best case but I just wanted to focus on testing part) as an example that means I do not have to execute the method stringList() to test the method filterList().
Mox uses Record Replay approach, so the method that needs to be tested is put in replay mode and result can be checked using assertEquals(expected, result).
The above testing module tests this python module.
Here is a simplest way to check the input connections in nuke node
I have Bucky’s python tutorial that I was thinking to give to some of my friends who are interested in learning python. I liked his tutorial, and for beginners it’s a perfect to start. However before they can download this video tutorial collection I wanted to give them an idea what’s inside, so instead of copy the names of each file and building an index or using sublime or Editext to do a multiline selection, I am going to do this pythonic way. See this image here, notice that each name has a pattern so I am going to take advantage of splitting the name for each all at once using a for loop and slicing the list of names.
in the first line is the for loop which is used to iterate inside the list, and enumerate is a python builtin that can be used to get the index of what’s being iterated.
In the second line, I have used If condition to test if index is not 0 then print else do nothing. So it just print after 0.
And in the third final line we print the index i.e. the number followed by each.split(..) btw what is it ? ok lets get into detail. When we were iterating the list of files each file name is stored as a string inside the list and I know strings have a function called split that takes by whatever you want to split and it returns a list . So what I am doing is taking a list getting each item as string and splitting that string to a new list and then from the new list I am getting the filename, since it has an extension prefixed I am getting rid of it by again splitting that file name to a list and getting rid of the extension. So this is how I end up with just the name that has index number before it.
Now lets write the above index to a text file.
(I will create a file at the same location where the other files were located)
how we managed to write all the lines into one file is by creating the fobj in w+ mode i.e. write + append, I will will use only “w” as second argument or parameter to the open method then in the for loop it will overwrite each time and will leave us with only the last index and name as the whole content of the file.
In the above for loop I have used str(index) to typecast integer to string variable so I can concatenate it to a string followed by space in double inverted commas and \n to insert a new line.
Thanks for reading, I will come up with something more useful in future whenever I get time to write.
This script will delete all unused read nodes from the comp.
In Nuke you can only move one node up or down using CTRL+ up arrow or down arrow either in up or down the nuke tree , to move multiple nodes selected you can used the the script below:
Move the selected nodes up in tree calling the function below.
to access these function from within nuke you can add menu to nuke like shown below:
Download the whole script here.
So I worked out a solution to find a read node in the group, extract it and paste it outside the group and with still connected to original connection
So as a part of my learning experience I implemented a simple file Explorer that uses QCompleter to complete folder path in the address bar and QTableWidget as well as QTableview to show how different is the implementation and how we can take advantage of Model View programming while implementing using QAbstractTableModel with QTableView.
Click read more to see code.
To get file owner in windows I have used ctypes module, see winfileOwner.py
Other Blogs & Pages
Animation & VFX SitesA MUST READ for Ani/VFX Artists
awakened by thoughts,