pep8 compliance testing is failing - python-3.x

I've followed Head First Python 2nd Edition and a pep8 compliance testing is demonstrated in chapter 4.
When running py.test --pep8 searchV.py gives error
appdata\local\programs\python\python38\lib\site-packages\pep8.py:110: FutureWarning: Possible nested set at position 1
EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]')
===============test session starts =========================================
platform win32 -- Python 3.8.6, pytest-6.2.1, py-1.10.0, pluggy-0.13.1
rootdir: D:\work\py-modules
plugins: pep8-1.0.6
collected 0 items / 1 error
=============== ERRORS =======================================================
_______________ERROR collecting test session ____
Direct construction of Pep8Item has been deprecated, please use Pep8Item.from_parent.
See https://docs.pytest.org/en/stable/deprecations.html#node-construction-changed-to-node-from-parent for more details.
==========short test summary info ===============
ERROR
!!!!!!!!!!!!!!!!!!!!Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!
Here's the code in serachV.py
def search_letter(phrase: str , letter:str='aeiou')->set:
""" Serach for letter in phrase"""
return set(letter).intersection(set(phrase))
Not sure why no items are collected ?

Tried pep8 searchV.py instead of Instead of py.test --pep8 searchV.py and it worked.
But pep8 has been renamed to pycodestyle (GitHub issue #466) . Use of the pep8 tool will be removed in a future release.
So , I used pycodestyle and it worked !
pycodestyle searchV.py

Related

Hiding DeprecationWarning from pytest

I'm writing some tests for code that calls TensorFlow 2.0.1. This library imports the imp module, which triggers a deprecation warning when I run pytest. I'm trying to muffle this warning, but without success.
This is my testing module:
import pytest
import warnings
from fclib.models.dilated_cnn import create_dcnn_model
def test_create_dcnn_model():
with pytest.deprecated_call():
create_dcnn_model(seq_len=1, max_cat_id=[30, 120]) # calls tensorflow.keras code
The output from pytest test_dcnn.py is
[...]
======================================== FAILURES ========================================
_________________________________ test_create_dcnn_model _________________________________
def test_create_dcnn_model():
with pytest.deprecated_call():
> create_dcnn_model(seq_len=1, max_cat_id=[30, 120])
E Failed: DID NOT WARN. No warnings of type (<class 'DeprecationWarning'>, <class 'PendingDeprecationWarning'>) was emitted. The list of emitted warnings is: [].
fclib/tests/test_dcnn.py:11: Failed
---------------------------------- Captured stderr call ----------------------------------
2020-07-07 03:15:03.162833: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 AVX512F FMA
2020-07-07 03:15:03.174538: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2095190000 Hz
2020-07-07 03:15:03.177318: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x55ef3370ff20 executing computations on platform Host. Devices:
2020-07-07 03:15:03.177351: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): Host, Default Version
==================================== warnings summary ====================================
/data/anaconda3/envs/forecasting_env/lib/python3.6/site-packages/tensorflow_core/python/pywrap_tensorflow_internal.py:15
/data/anaconda3/envs/forecasting_env/lib/python3.6/site-packages/tensorflow_core/python/pywrap_tensorflow_internal.py:15: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
-- Docs: https://docs.pytest.org/en/latest/warnings.html
================================ short test summary info =================================
FAILED fclib/tests/test_dcnn.py::test_create_dcnn_model - Failed: DID NOT WARN. No warn...
============================== 1 failed, 1 warning in 2.39s ==============================
So it complains that there was no warning, and yet the printed output says that there was a warning. What's happening here?
If I remove the with pytest.deprecated_call() line, I get:
def test_create_dcnn_model():
# with pytest.deprecated_call():
create_dcnn_model(seq_len=1, max_cat_id=[30, 120])
================================== test session starts ===================================
platform linux -- Python 3.6.10, pytest-5.4.3, py-1.9.0, pluggy-0.13.1
rootdir: /data/forecasting/fclib
collected 1 item
fclib/tests/test_dcnn.py . [100%]
==================================== warnings summary ====================================
/data/anaconda3/envs/forecasting_env/lib/python3.6/site-packages/tensorflow_core/python/pywrap_tensorflow_internal.py:15
/data/anaconda3/envs/forecasting_env/lib/python3.6/site-packages/tensorflow_core/python/pywrap_tensorflow_internal.py:15: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
-- Docs: https://docs.pytest.org/en/latest/warnings.html
============================== 1 passed, 1 warning in 2.00s ==============================
So it passes, but the warning message is still present. How can I get rid of that message completely?

RuntimeError: Unable to start JVM because of Deprecated: convertStrings

I run an automated python job on an EMR cluster that updates Amazon Athena Tables.
It was running well until few days ago (on python 2.7 and 3.7). Here is the script:
from pyathenajdbc import connect
import yaml
config = yaml.load(open('athena-config.yaml', 'r'))
statements = config['statements']
staging_dir = config['staging_dir']
conn = connect(s3_staging_dir=staging_dir, region_name='eu-west-1')
try:
with conn.cursor() as cursor:
for statement in statements:
cursor.execute(statement)
finally:
conn.close()
The athena-config.yaml has a staging directory and few Athena Statements.
Here is the Error:
You are using pip version 9.0.3, however version 19.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Unrecognized option: -server
create_tables.py:5: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
config = yaml.load(open('athena-config.yaml', 'r'))
/mnt/conda/lib/python3.7/site-packages/jpype/_core.py:210: UserWarning:
-------------------------------------------------------------------------------
Deprecated: convertStrings was not specified when starting the JVM. The default
behavior in JPype will be False starting in JPype 0.8. The recommended setting
for new code is convertStrings=False. The legacy value of True was assumed for
this session. If you are a user of an application that reported this warning,
please file a ticket with the developer.
-------------------------------------------------------------------------------
""")
Traceback (most recent call last):
File "create_tables.py", line 10, in <module>
region_name='eu-west-1')
File "/mnt/conda/lib/python3.7/site-packages/pyathenajdbc/__init__.py", line 69, in connect
driver_path, log4j_conf, **kwargs)
File "/mnt/conda/lib/python3.7/site-packages/pyathenajdbc/connection.py", line 68, in __init__
self._start_jvm(jvm_path, jvm_options, driver_path, log4j_conf)
File "/mnt/conda/lib/python3.7/site-packages/pyathenajdbc/util.py", line 25, in _wrapper
return wrapped(*args, **kwargs)
File "/mnt/conda/lib/python3.7/site-packages/pyathenajdbc/connection.py", line 97, in _start_jvm
jpype.startJVM(jvm_path, *args)
File "/mnt/conda/lib/python3.7/site-packages/jpype/_core.py", line 219, in startJVM
_jpype.startup(jvmpath, tuple(args), ignoreUnrecognized, convertStrings)
RuntimeError: Unable to start JVM
at loadJVM(native/common/jp_env.cpp:169)
at loadJVM(native/common/jp_env.cpp:179)
at startup(native/python/pyjp_module.cpp:159)
As far as I understand the issue in convertStrings being deprecated. Can anyone help me resolve that? I cannot understand why this """) comes before the traceback, and what changed in past days to break the code. Thanks!
Got the same issue today. Try to downgrade JPype1 to 0.6.3. JPype1 released 0.7.0 today, which is not compatible with old interfaces.
The issue appears to be that the package is calling the JVM with an unrecognized argument -server. The previous version was ignoring those sort of errors allowing things to proceed. To get the same behavior with 0.7.0, the flag ignoreUnrecognized would need to be set to True. Likely this needs to be send to pyathenajdbc to correct the defect which placed the bogus argument into the startJVM in the first place.
Looking at the source the -server is hardcoded into the module.
if not jpype.isJVMStarted():
_logger.debug('JVM path: %s', jvm_path)
args = [
'-server',
'-Djava.class.path={0}'.format(driver_path),
'-Dlog4j.configuration=file:{0}'.format(log4j_conf)
]
if jvm_options:
args.extend(jvm_options)
_logger.debug('JVM args: %s', args)
jpype.startJVM(jvm_path, *args)
cls.class_loader = jpype.java.lang.Thread.currentThread().getContextClassLoader()
It is assuming a particular JVM which accepts -server as an argument.

RobotFramework (python 3): AppiumLibrary : Open application > InsecureRequestWarning

I'm trying (successfuly) to connect to a remote server where my device is connected.
But, despite my effort and researchs, I always have InsecureRequestWarning warning showing up...
The code :
*** Settings ***
Library AppiumLibrary
*** Test Cases ***
First run wizard - Connect to Remote
[Setup] Install and open app
[Teardown] Close all applications
Log Hello World WARN
Sleep 10
*** Keywords ***
Install and open app
open application ${Grid} &{MyDevice} &{UserCredential} &{Android_app}
*** Variables ***
${Grid} http://xxx/appium
&{Huawei_P20_Pro} uuid=xxx relaxed-security=True
&{UserCredential} Username=xx ApiKey=xxxx
&{Android_app} appPackage=xxx appActivity=xxx appWaitActivity=xxx
The output :
First run wizard - Connect to Remote
C:\Users\xxx\AppData\Local\Programs\Python37-32\Lib\site-packages\urllib3\connectionpool.py:847: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning)
[ WARN ] Hello World
C:\Users\xxx\AppData\Local\Programs\Python37-32\Lib\site-packages\urllib3\connectionpool.py:847: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
| PASS |
------------------------------------------------------------------------------
InsecureRequestWarning)
test :: Android template to connect to Remote | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Output: C:\Projects\RF\test\output.xml
Log: C:\Projects\RF\test\log.html
Report: C:\Projects\RF\test\report.html
Process finished with exit code 0
I've tried to put the capability relaxed-security it didn't work.
I've found some similar case with Create Session Keyword and the parameter verify=True, but it doesn't work on Open Application either.
Currently, I'm about to modify the source code of the urllib3 library to prevent this anoying warning, but this is not a proper solution.
Thus I was wondering if someone could have a clue arround here !
(using http or https makes no difference in the output)
[Partial answere here Suppress InsecureRequestWarning: Unverified HTTPS request is being made in Python2.6 :
It's just a workaround, it shows how to disable the warning, not how to prevent it (== make the things right) such as enable the certificate verification]

Openstack TripleO undercloud installation "could not find class ::ironic::drivers::deploy"

My host is:
cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
The host setup was done as described here: http://docs.openstack.org/developer/tripleo-docs/environments/environments.html#virtual-environment up to the "Continue with Undercloud ..." step
The result:
sudo virsh list --all
Id Name State
----------------------------------------------------
3 baremetalbrbm_0 running
4 instack running
- baremetalbrbm_1 shut off
The undercloud setup was done as described here: http://docs.openstack.org/developer/tripleo-docs/installation/installation.html
The installation was attempted on the instack VM. Did the SSL setup as well.
Running
openstack undercloud install
fails with
+ puppet apply --detailed-exitcodes /etc/puppet/manifests/puppet-stack-config.pp Notice: Scope(Class[Tripleo::Firewall::Post]): At this stage, all network traffic is blocked. Warning: Scope(Class[Swift]): swift_hash_suffix has been deprecated and should be replaced with swift_hash_path_suffix, this will be removed Warning: Scope(Class[Nova::Keystone::Auth]): Note that service_name parameter default value will be changed to "Compute Service" (according future release. In case you use different value, please update your manifests accordingly. Warning: Scope(Class[Nova::Keystone::Auth]): Note that service_name_v3 parameter default value will be changed to "Compute Service v3" (acco in a future release. In case you use different value, please update your manifests accordingly. Warning: Scope(Class[Glance::Api]): The known_stores parameter is deprecated, use stores instead Warning: Scope(Class[Glance::Api]): default_store not provided, it will be automatically set to glance.store.filesystem.Store Warning: Scope(Class[Nova::Api]): In N cycle, enabled_apis will have to be an array of APIs to enable. Warning: Scope(Class[Neutron::Server]): identity_uri, auth_tenant, auth_user, auth_password, auth_region configuration options are deprecateted options Warning: Scope(Class[Neutron::Agents::Dhcp]): The dhcp_domain parameter is deprecated and will be removed in future releases Warning: Scope(Class[Heat]): Default value for rabbit_heartbeat_timeout_threshold parameter is different from OpenStack project defaults Warning: Scope(Class[Heat]): "admin_user", "admin_password", "admin_tenant_name" configuration options are deprecated in favor of auth_plugi Warning: Scope(Class[Nova::Network::Neutron]): neutron_auth_plugin parameter is deprecated and will be removed in a future release, use neut Error: Could not find class ::ironic::drivers::deploy for instack on node instack Error: Could not find class ::ironic::drivers::deploy for instack on node instack
+ rc=1
+ set -e
+ echo 'puppet apply exited with exit code 1' puppet apply exited with exit code 1
+ '[' 1 '!=' 2 -a 1 '!=' 0 ']'
+ exit 1 [2016-05-19 15:32:29,361] (os-refresh-config) [ERROR] during configure phase. [Command '['dib-run-parts', '/usr/libexec/os-refresh-config/cot status 1]
[2016-05-19 15:32:29,362] (os-refresh-config) [ERROR] Aborting... Traceback (most recent call last): File "<string>", line 1, in <module> File "/usr/lib/python2.7/site-packages/instack_undercloud/undercloud.py", line 987, in install
_run_orc(instack_env) File "/usr/lib/python2.7/site-packages/instack_undercloud/undercloud.py", line 866, in _run_orc
_run_live_command(args, instack_env, 'os-refresh-config') File "/usr/lib/python2.7/site-packages/instack_undercloud/undercloud.py", line 444, in _run_live_command
raise RuntimeError('%s failed. See log for details.' % name) RuntimeError: os-refresh-config failed. See log for details. Command 'instack-install-undercloud' returned non-zero exit status 1
Tried to install the ironic api as described here http://docs.openstack.org/developer/ironic/deploy/install-guide.html although to my understanding, this should not be necessary, since the undercloud was not installed on a baremetal machine.
Same result.
Some hours of Puppet readings later, I went into the /etc/puppet/modules/ironic/manifests/drivers folder and found, to no surprise, that the deploy class was not there. Perhaps it should not have been needed? I copied it from https://github.com/openstack/puppet-ironic/blob/master/manifests/drivers/deploy.pp and it seems to have got past the error originally reported. Fingers crossed.

preverify:ERROR: floating-point constants should not appear, while running the code in j2me using netbeans 6.9

all I am making a new project in J2ME-Polish2.1.4 and when I create a new project using J2ME-Polish2.1.4, the build is successful but when i run this code then I see the error about floating-point constants with more details below.
How to recover from this issue?
`J2ME Polish 2.1.4 (2010-01-18) (GPL License)
Loading device database...
Last build was interrupted or failed, now clearing work directory...
using locale [en_US]...
assembling resources for device [Nokia/7610].
preprocessing for device [Nokia/7610].
processing locale code...
compiling for device [Nokia/7610].
warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
Compiling 428 source files to D:\Faraz\development\J2ME-Polish-Projectaaaa\build\test\Nokia\7610\en_US\classes
preverifying for device [Nokia/7610].
preverify:ERROR: floating-point constants should not appear
preverify:Error preverifying class de.enough.polish.ui.screenanimations.CubeScreenChangeAnimation
Preverify call failed: 1
C:\WTK2.5.1\bin\preverify.exe -classpath d:\J2ME-Polish2.1.4\import\mmapi.jar;d:\J2ME-Polish2.1.4\import\cldc-1.0.jar;d:\J2ME-Polish2.1.4\import\midp-2.0.jar;d:\J2ME-Polish2.1.4\import\nokia-ui.jar;d:\J2ME-Polish2.1.4\import\wmapi-2.0.jar;d:\J2ME-Polish2.1.4\import\wmapi.jar;d:\J2ME-Polish2.1.4\import\btapi.jar;d:\J2ME-Polish2.1.4\import\m3g.jar;d:\J2ME-Polish2.1.4\import\jsr172.jar;d:\J2ME-Polish2.1.4\import\fileconnection.jar;d:\J2ME-Polish2.1.4\import\pim.jar;d:\J2ME-Polish2.1.4\import\m2g.jar -d D:\Faraz\development\J2ME-Polish-Projectaaaa\build\test\Nokia\7610\en_US\classes -nofp -nofinalize -nonative D:\Faraz\development\J2ME-Polish-Projectaaaa\build\test\Nokia\7610\en_US\classes
D:\Faraz\development\J2ME-Polish-Projectaaaa\build.xml:87: Unable to preverify for device [Nokia/7610] - preverify returned result 1
BUILD FAILED (total time: 9 seconds)
`
If you look deeper into preferify classpath, there is an indication of what caused the error.
C:\WTK2.5.1\bin\preverify.exe -classpath d:\J2ME-Polish2.1.4\import\mmapi.jar;d:\J2ME-Polish2.1.4\import\cldc-1.0.jar;d:\J2ME-Polish2.1.4\import\midp-2.0.jar;d:\J2ME-Polish2.1.4\import\nokia-ui.jar;d:\J2ME-Polish2.1.4\import\wmapi-2.0.jar;d:\J2ME-Polish2.1.4\import\wmapi.jar;d:\J2ME-Polish2.1.4\import\btapi.jar;d:\J2ME-Polish2.1.4\import\m3g.jar;d:\J2ME-Polish2.1.4\import\jsr172.jar;d:\J2ME-Polish2.1.4\import\fileconnection.jar;d:\J2ME-Polish2.1.4\import\pim.jar;d:\J2ME-Polish2.1.4\import\m2g.jar -d D:\Faraz\development\J2ME-Polish-Projectaaaa\build\test\Nokia\7610\en_US\classes -nofp -nofinalize -nonative D:\Faraz\development\J2ME-Polish-Projectaaaa\build\test\Nokia\7610\en_US\classes
Above refers to cldc-1.0.jar meaning that your build is configured for CLDC 1.0 where floating point is not supported indeed. That's why your build fails.
To get it fixed, either get rid of floating point code in your application or use CLDC 1.1 that allows for float and double.

Resources