How to ignore DeprecationWarning during testing in Pythons 2.7 - 3.5? - python-unittest

In 3.5 DeprecationWarning is explicitly set to show during testing.
My package is for 2.7 - 3.5 and uses functions present in 2.7 - 3.4 that were deprecated in 3.5. Using the replacement method would be a pain since it didn't exist before 3.5, plus it isn't going anywhere for years (2020 at the earliest).
How do I get the DeprecationWarning silenced during the 3.5 test?
I have tried setting PYTHONWARNING, warnings.filterwarning, creating my own TestCase with warnings.filterwarnings in __init__, all to no avail.

setUpClass was added in 2.7 and 3.2, and should be ignored in 3.1 and 2.6-. So the best option is to create your own subclass of unittest.TestCase and add the warnings.filterwarnings code to the setUpClass function*.
*Don't forget to use the classmethod decorator on setUpClass.

Related

How to import EF 3.0 method in Brightway2?

My colleague, after the recent update of Brightway2, can see EF3.0 method within the availeable.
I tried to do the same but it's not working (I have some new methods, but not EF3.0).
This is what I have done:
Conda update conda
Conda update brightway2
In Brightway
import brightway2 as bw
bw.Database('biosphere3').delete()
bw.Database('biosphere3').deregister()
bw.projects
bw.projects.delete_project('Name of my project',delete_dir=True)
bw.projects.report()
bw.databases
bw.databases.clear()
bw.bw2setup() #Import of biosphere3
# Import ecoinvent 3.7
ei37dir ="*my directory*"
if 'ecoinvent 3.7_cutoff' in bw.databases:
print("Database has already been imported")
else:
ei37 = bw.SingleOutputEcospold2Importer(ei37dir, 'ecoinvent 3.7_cutoff')
ei37.apply_strategies()
ei37.statistics()
ei37.drop_unlinked(True)
ei37.write_database()
list(bw.methods)
How can I implement EF3.0?
Thank you in advance
Kevin
The EF method was added in bw2io version 0.8.6. You would need to update to this library version, and then reinstall the LCIA methods (doesn't have anything to do with which version of ecoinvent you have, LCIA methods are separate).
In a new project, just calling bw2setup() should be fine. In an older project, you will need to rewrite both biosphere flow list and the LCIA methods:
import bw2io as bi
bi.create_default_biosphere3(overwrite=True)
bi.create_default_lcia_methods(overwrite=True)

Error in pyomo expression generation with sum using python 3.6

I am using pyomo Pyomo 5.1.1 (CPython 3.6.0 on Linux 3.16.0-4-amd64)
under Python 3.6, and I get an error message when I want to build an Expression in a model using a summation.
Here is a minimal example :
from pyomo.environ import *
from pyomo.opt import SolverFactory
model=ConcreteModel()
model.H=RangeSet(0,23)
model.x=Var(model.H)
E=summation(model.x)
I get the following error :
"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/b67777/anaconda3/lib/python3.6/site-packages/pyomo/core/base/util.py", line 86, in summation
ans += item
File "/home/b67777/anaconda3/lib/python3.6/site-packages/pyomo/core/base/numvalue.py", line 537, in __iadd__
return generate_expression(_iadd,self,other)
File "/home/b67777/anaconda3/lib/python3.6/site-packages/pyomo/core/base/expr_coopr3.py", line 977, in generate_expression
_self = _generate_expression__clone_if_needed(_self, 1)
File "/home/b67777/anaconda3/lib/python3.6/site-packages/pyomo/core/base/expr_coopr3.py", line 918, in _generate_expression__clone_if_needed
% ( getrefcount(obj) - UNREFERENCED_EXPR_COUNT, ))
RuntimeError: Expression entered generate_expression() with too few references (0<0); this is indicative of a SERIOUS ERROR in the expression reuse detection scheme.
"
I get the same error if I replaced the "summation" by a loop over h in model.H.
The bug has been noticed also here : https://github.com/Pyomo/pyomo/issues/103
Is there a simple way to fix this, other than stepping back to older version of Python ?
Thank you very much for your help,
Paulin
Pyomo only supports Python 2.6, 2.7, 3.3, 3.4, and 3.5.
Python 3.6 changed the internal call stack, which invalidated the internal "magic numbers" that Pyomo uses for detecting when an expression is being pointed to by extra variables (i.e., it is potentially being reused in multiple expressions - something that is not allowed by the Pyomo expression trees). The developers are working on a fix (in the pyomo4-expressions branch). Until that fix is merged back into master and released, the only alternative is to install one of the supported Python versions.
Update [3 April 17]: The fix was merged back into master on 7 March 2017. Pyomo should support Python 3.6 in the next patch release.
Update [14 May 17]: Pyomo 5.2 has been released, which provides full support for Python 3.6

crossfilter.all() not working as per the docs + cf.size works

as per the docs I cannot get cf.all() to work
I am using this as an example here in the console in the broswer.
This is what i see in the console.
cf
Object {}
cf.all()
VM1818:1 Uncaught TypeError: cf.all is not a function(…)(anonymous function) # VM1818:1
cf.size()
2692
I can get cf.size() to work but not cf.all()
crossfilter.all was added in the version 1.4 alphas. The page you are looking at uses version 1.3.12, so it doesn't include that method. I've updated the documentation to reflect this.

How to solve collective.js.jqueryui versioning for both Plone 4.2 and 4.3

I have an addon which I want to update to be compatible with Plone4.3, but which should remain functional when Plone4.2 users do an upgrade.
The readme says this:
For Plone 3 you need version 1.7.x of this package
Plone < 4.3 Use version < 1.9
How can I configure this kind of version-specific dependency in setup.py?
Actually it's c.js.jqueryui which should pin the Plone-versions in their tag-releases, IMHO.
So you should contact the authors probably.
To be consequent, you should add 'Products.CMFPlone' as a dependency, too, but I don't know what is best practice here.
Anyway, to answer your question, here is a possibilty to distinct, whether we have a Plone-3 or not:
In your setup.py add at the top
import glob
# BBB: Append Plone-3-specific version-pinnings
# to `install_requires`, in case third-party-eggs
# do not specify their requirement-versions.
# Assumes, Plone-eggs are in the same directory
# as this egg, which is given, if fetched of pypi.
# Otherwise assumes, you know how to tweak
# buildout and pin versions yourself.
# Collect P3-eggs in eggs-directory:
plone3_eggs = glob.glob('../Products.CMFPlone-3*')
# Found something?
if len(plone3_eggs) > 0:
# Expects `install_requires=[ ... ] + plone3_requires,`
# in setup-method below, to take effect:
plone3_requires = [
'collective.js.jqueryui<=1.7',
# Add more P3-pins here.
]
And install_requires in the setup-method, gets this:
install_requires= [
'setuptools',
'collective.js.jqueryui',
] + plone3_requires,

Plone 4.1 ConfigurationError - Unknown directive 'expressiontype'

After adding unweb.watermark to eggs, I get an endless series of starts in instance.log (Plone 4.1.2), but no service.
See buildout / fg at http://pastie.org/2776226
How can I investigate/fix this?
By adding that product in a vanilla Plone I've faced these two issues (depending on the versions of products used):
ConfigurationError: ('Unknown directive', u'http://namespaces.zope.org/tales', u'expressiontype')
or
AttributeError: type object 'DirectoryResource' has no attribute
'resource_factories'
In order to fix that issue you should extend your buildout like this:
[buildout]
...
extends =
...
http://svn.plone.org/svn/collective/unweb.watermark/trunk/versions.cfg
http://good-py.appspot.com/release/plone/4.1.2?dexterity=1.0
More info:
http://www.gossamer-threads.com/lists/zope/dev/230509
http://code.google.com/p/dexterity/issues/detail?id=165

Resources