How to Avoid Pylint Error For Not Passing Argument to Celery Bound Method? - python-3.x

The project is meant to serve a machine learning model via a REST API. Here is the celery task declaration, along with a unit test to check the function is running on a sample input.
#celery.task(bind=True)
def run_prediction(self, inpath: str) -> pandas.DataFrame:
'''
:param inpath File location of the input feature
'''
# Do a lot of stuffs
return output # type:pandas.DataFrame
if __name__=='__main__':
# Do a unit test with a sample inpath
pred:pandas.DataFrame=run_prediction(inpath=sample_inpath)
The run_prediction function can be triggered as a stand-alone normal function without caring about celery, and also as an asynchronous method with the apply_async provided by celery. (I did not expect it to have the functionality of a standalone function, so any explanation on that would be great.)
But the main issue is when I check the code via pylint (version 2.5.3), it throws an error and a warning, both saying the same thing.
model_utility.py:92:34: W0613: Unused argument 'self' (unused-argument)
model_utility.py:188:4: E1120: No value for argument 'self' in function call (no-value-for-parameter)
Does it mean somehow pylint is not aware of how to call the function? Can I update the code to have a 10/10 from pylint? Or should I change something about pylint itself?
For your information, using pylint as a package from my editor (Atom), if that is important to the discussion.

Related

Passing in responses to input() prompts in python through system arguments

I'm using a python library that has a configuration step which involves calling a function and providing the API key in the prompt response. It uses input(). This function creates the file necessary with all the configurations.
This is fine for humans to use the API, but I'm adding CI to my code and wish to unit tests calls to this API. As such, I need to complete the same step.
I simply want to do something like python -c '<PYTHON CODE>'.
Aside from altering the code to allow for an optional input of the API key (to skip the prompt), I wonder if there is an easier way to do this with sys.argv.
I did some googling and could not find a working example involving input() and argument inputs.
Thoughts appreciated.

How to suppress calling default argument function in python3?

I have a line of code like this:
subparser.add_argument('--user', type=str, default=getpass.getuser(), help='User to run the Batch jobs as'). When the command entered does not specify a --user, then the getpass.getuser() is called. However, calling getpass.getuser() could throw errors in testing mode, so the test fails before even reaching where it is supposed to test. Can anyone suggest how to suppress that default function from being called?
Thanks!

Executing a python script in snaplogic

I am trying to run a python script through script snap in snaplogic. I am facing some issues where it ask me to declare a script hook variable. Can you please help me on that.
With the script snap you should use the "Edit Script" button on the snap itself. This will open a script editor and generate a skeleton script in the language you've selected (Py in this case).
In the skeleton you can see the baseline methods and functions we define. In there you can see the usage and comments of the scripthook var. If you have an existing script I would recommend trying to write it into this skeleton's execute method than trying to implement scripthook in your existing code. You can also define your own methods and functions within the confines of the skeleton class and reference them with "this." notation.
For faster answers on SnapLogic related questions I'd recommend visiting the SnapLogic Community site.
As explained by #dwhite0101, within Script Snap when you click Edit Script you get an option to generate code template.
ScriptHook is an interface that is implemented as callback mechanism for Script Snap to call into the script.
It helps you to deal with input and output rows. The constructor below initializes the input, output, error and log variables.
self object is similar to this in c++ that holds the current row values.
class TransformScript(ScriptHook):
def __init__(self, input, output, error, log):
self.input = input
self.output = output
self.error = error
self.log = log
You can perform transformations in execute method:
def execute(self):
self.log.info("Executing Transform script")
while self.input.hasNext():
in_doc = self.input.next()
wrapper = java.util.HashMap()
for field in in_doc:
#your code
Next step is to store your results in an object and output it:
wrapper['original'] = result
self.output.write(result, wrapper)
Make sure to indent your code properly.

How do I see the full diff when using snapshottest?

I'm running unit tests with unittest in a Python 3.7 project where we are using the snapshottest library to keep track of changes in our endpoints. When a snapshot test fails, how do I see the full difference? Right now, the diff is truncated and I can not see what has changed.
Setting maxDiff = None in my test class does not work, since the assertion error is raised within the library and not from my test class.

Load Steps into Console?

Is it possible to load the step definitions I have defined into the calabash-android console?
I would like to be able to use them when navigating the app within the console.
Thanks
No from the console you can not run a single step definition.
But you can start execution of a test at a specific line appending parameter to the call to start your test
:<linenumber>
This will start execution of your feature file from that specific line and it will run from there to the end of the file.
So while it is not what you are looking for at least it is something.
Did you try step('<step_name>') method?
To be honest I'm not sure if this will work. I know it's working insinde Ruby methods and step definitions - I wanted to post a comment but I can't with 28 points of reputation ;)
You can also try making ruby methods with code from within the step definition:
Then /^I do something$/ do
some code
goes here
end
def do_something
some code
goes here
# same code as in step definition
end
or just use step method:
def do_something
step('I do something')
end
and then call it in a calabash console (I prefer using binding.pry inside some script rather than calling "pure" calabash-console - it makes me sure that I will have all needed methods included).

Resources