Skip to content

Instantly share code, notes, and snippets.

View ramiroluz's full-sized avatar

Ramiro Batista da Luz ramiroluz

  • Câmara Municipal de Curitiba
  • Câmara Municipal de Curitiba
  • X @ramiroluz
View GitHub Profile
Patching and mocking Plone unittests with using mock
----------------------------------------------------
The python mock module was created by Michael Foord and it has been integrated in the unittest module since python version 3.3. It's license is BSD as it is possible to see in the official `homepage of the project`_.
.. _homepage of the project: http://www.voidspace.org.uk/python/mock/index.html
It allows you to replace parts of your system under test with mock objects and make assertions about how they have been used.
You can use it to replace methods or properties, as it will be shown in the following examples.
Patching and mocking Plone unittests with using mock
----------------------------------------------------
The python mock module was created by Michael Foord and it has been integrated in the unittest module since python version 3.3. It's license is BSD as it is possible to see in the official `homepage of the project`_.
.. _homepage of the project: http://www.voidspace.org.uk/python/mock/index.html
It allows you to replace parts of your system under test with mock objects and make assertions about how they have been used.
You can use it to replace methods or properties, as it will be shown in the following examples.
@ramiroluz
ramiroluz / gist:7153081
Created October 25, 2013 11:15
CSSLint usage example.
# csslint incorrect.css correct.css
csslint: There are 2 problems in incorrect.css.
incorrect.css
1: error at line 2, col 1
Unexpected token '{' at line 2, col 1.
{}
@ramiroluz
ramiroluz / gist:7220492
Created October 29, 2013 18:54
csslint error.
$ cat codeanalysis.cfg
[buildout]
extends =
buildout.cfg
auto-checkout = plone.recipe.codeanalysis
parts += code-analysis
[sources]
plone.recipe.codeanalysis = git https://github.com/plone/plone.recipe.codeanalysis.git
# Salvar arvore html da página de vídeos pythonbrasil no arquivo /tmp/dom.html
# http://www.youtube.com/user/pythonbrazil/videos?view=0&sort=dd&live_view=500&flow=list
# BeautifulSoup versão 3.2.1, o método para buscar a classe mudou na versão 4.
s = file('/tmp/dom.html').read()
from BeautifulSoup import BeautifulSoup as BS
soup = BS(s)
soup.findAll('li', { "class" : "yt-lockup clearfix channels-browse-content-list-item yt-lockup-video yt-lockup-tile vve-check context-data-item" })
items = soup.findAll('li', { "class" : "yt-lockup clearfix channels-browse-content-list-item yt-lockup-video yt-lockup-tile vve-check context-data-item" })
l = [x.attrMap['data-context-item-title'] for x in items]
@ramiroluz
ramiroluz / forms.py
Created September 26, 2016 00:38
Trecho do forms.py
class ContatoAgrupadoPorGrupoFilterSet(FilterSet):
search = MethodFilter()
municipio = MethodModelChoiceFilter(
required=False,
queryset=Municipio.objects.all())
grupo = MethodModelChoiceFilter(
required=False,
queryset=GrupoDeContatos.objects.all())
======================================================================
FAIL: test_docstrings (tests.modules.test_math.MathTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/ramiro/python/pybee/batavia-dev/batavia/tests/modules/test_math.py", line 165, in test_docstrings
""")
File "/home/ramiro/python/pybee/batavia-dev/batavia/tests/utils.py", line 504, in assertCodeExecution
self.assertEqual(js_out, py_out, context)
AssertionError: 'acos[76 chars] the inverse hyperbolic cosine of x.\nasin(x)\[3067 chars]d.\n' != 'acos[76 chars] the hyperbolic arc cosine (measured in radian[3121 chars]d.\n'
acos(x)
# -*- coding: utf-8 -*-
from zope.component import queryUtility
from plone.i18n.normalizer.interfaces import IIDNormalizer
from plone.dexterity.fti import DexterityFTI
from interlegis.portalmodelo.ombudsman.testing import create_ombudsoffice
from interlegis.portalmodelo.ombudsman.testing import INTEGRATION_TESTING
from interlegis.portalmodelo.ombudsman.browser.claims_by_tag import json_claims_by_tag
from interlegis.portalmodelo.ombudsman.browser.claims_by_tag import get_claim_tag
from interlegis.portalmodelo.ombudsman.browser.claims_by_tag import count_claims_by_tag
from interlegis.portalmodelo.ombudsman.browser.claims_by_tag import csv_claims_by_tag
diff --git a/src/interlegis/portalmodelo/ombudsman/content/claim.py b/src/interlegis/portalmodelo/ombudsman/content/claim.py
index 3278b84..71936a9 100644
--- a/src/interlegis/portalmodelo/ombudsman/content/claim.py
+++ b/src/interlegis/portalmodelo/ombudsman/content/claim.py
@@ -1,10 +1,12 @@
# -*- coding: utf-8 -*-
from interlegis.portalmodelo.ombudsman.interfaces import IClaim
-from five import grok
+# from five import grok
# https://github.com/philchalmers/mirtCAT/blob/master/R/extract.mirtCAT.R
set.seed(1234)
nitems <- 25
itemnames <- paste0('Item.', 1:nitems)
a <- matrix(rlnorm(nitems, .2, .3))
d <- matrix(rnorm(nitems))
dat <- simdata(a, d, 500, itemtype = 'dich')
colnames(dat) <- itemnames
mod <- mirt(dat, 1, verbose = FALSE, TOL = .01)