Wrong coverage report with WebTest - code-coverage

I have a pyramid application that I am testing using WebTest with the following code:
class FunctionalTests(unittest.TestCase):
def setUp(self):
from test_app import main
app = main({})
from webtest import TestApp
self.testapp = TestApp(app)
def test_not_found(self):
self.testapp.get("/not_found", status=404)
The view for not found is defined as follow:
#notfound_view_config(renderer="../templates/404.jinja2")
def notfound_view(request):
request.response.status = 404 # This is line 6
return {} # This is line 7
The coverage for the no found view is:
Name Stmts Miss Branch BrPart Cover Missing
test_app/views/notfound.py 4 2 0 0 50% 6-7
But there is no way that those line were skipped in the test so why coverage missed them?
This is my .coveragerc
[run]
branch = True
source = test_app
# omit = bad_file.py
[paths]
source =
test_app/
*/site-packages/
[report]
show_missing = True
I run the test with:
pytest --cov=formshare

Related

Issues with building a package with Rstan and RcppArmadillo

I have experienced the following problem during the process of building my package. I tried to search for a solution but was unsuccessful. In order to make the error reproducible, I present a minimal package that could generate the same error.
I started a package with the name mypkg, then I use usethis::use_rcpp and usethis::use_rcpp_armadillo. After that I add the following script in \src folder (which is copied from internet)
#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::export]]
arma::vec getEigenValues(arma::mat M) {
return arma::eig_sym(M);
}
After that, I add an R shell to export the function using Roxygen. So far the package can be successfully documented and built.
Then I continue to add features of Rstan by using rstantools::use_rstan, and follow the steps on Step by step guide for creating a package that depends on RStan, and create lm.stan and lm_stan.R as instructed. Then I built the package again but it throws out an error. Here are the results of executing
.Last.error.trace
1. devtools:::document()
2. withr::with_envvar(r_env_vars(), roxygen2::roxygenise(pkg$path, ...
3. base:::force(code)
4. roxygen2::roxygenise(pkg$path, roclets, load_code = load_code)
5. roxygen2:::load_code(base_path)
6. pkgload::load_all(path, helpers = FALSE, attach_testthat = FALSE)
7. pkgbuild::compile_dll(path, quiet = quiet)
8. pkgbuild:::install_min(path, dest = install_dir, components = "libs", ...
9. pkgbuild:::rcmd_build_tools("INSTALL", c(path, paste("--library=", ...
10. pkgbuild:::with_build_tools(callr::rcmd_safe(..., env = env, ...
11. withr::with_path(rtools_path(), code)
12. base:::force(code)
13. callr::rcmd_safe(..., env = env, spinner = FALSE, show = FALSE, ...
14. callr:::run_r(options)
15. base:::with(options, with_envvar(env, do.call(processx::run, ...
16. base:::with.default(options, with_envvar(env, do.call(processx::run, ...
17. base:::eval(substitute(expr), data, enclos = parent.frame())
18. base:::eval(substitute(expr), data, enclos = parent.frame())
19. callr:::with_envvar(env, do.call(processx::run, c(list(bin, args = real_cmdargs, ...
20. base:::force(code)
21. base:::do.call(processx::run, c(list(bin, args = real_cmdargs, ...
22. (function (command = NULL, args = character(), error_on_status = TRUE, ...
23. throw(new_process_error(res, call = sys.call(), echo = echo, ...
x System command 'Rcmd.exe' failed, exit status: 1, stdout + stderr (last 10 lines):
E> In file included from C:/Users/Jasper/Documents/R/win-library/3.6/rstan/include/rstan/rstaninc.hpp:3:0,
E> from stanExports_lm.h:20,
E> from stanExports_lm.cc:5:
E> C:/Users/Jasper/Documents/R/win-library/3.6/rstan/include/rstan/stan_fit.hpp:11:28: fatal error: stan/version.hpp: No such file or directory
E> #include <stan/version.hpp>
E> ^
E> compilation terminated.
E> make: *** [C:/PROGRA~1/R/R-36~1.2/etc/x64/Makeconf:213: stanExports_lm.o] Error 1
E> ERROR: compilation failed for package 'mypkg'
E> * removing 'C:/Users/Jasper/AppData/Local/Temp/RtmpwXHySZ/devtools_install_1d18454066b0/mypkg'
Could anyone suggest what the problem is? Here is my makevars file
CXX_STD = CXX11
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
However, when I follow the steps of the guide to create a package just with Rstan, it could be successfully built, but not when I also want to use RcppArmadillo.
Thank you very much for your kind help!!

Add --all option to wscript

I have several targets defined in my top wscript, let's call them build_a, build_b and build_c.
How do I add a function all to my wscript, that builds all these targets (doesn't matter if sequential or in parallel).
So in dummy python code, I expect something like this:
def all():
tar = ['configure', 'build_a', 'build_b', 'build_c']
It's simple to compose commands:
from waflib import Options
def all(bld):
commands_after = Options.commands
Options.commands = ['configure', 'build_a', 'build_b', 'build_c']
Options.commands += commands_after
See https://waf.io/book/#_custom_commands (ยง7.1.2 Command composition)
waf consume Options.commands while processing it. So you can use:
waf all test
# equivalent to waf configure build_a build_b build_c test

Buildbot nightly build is failing to checkout the branch

I am using buildbot for building and testing chromium source. We have a local repo maintained for chromium source. We are using Gerrit for maintaining the repository. The buildbot gets successfully triggered when some change is checked in.
I am facing problem with Nightly builds. I want the buildbot to get the source and build, even when there is no change. But, it fails with the following error:
===Running git checkout --force origin/ ===
error: pathspec 'origin/' did not match any file(s) know to git.
===Failed in 0.0. mins===
Can somebody tell me how to get this working?
My master.cfg is as below:
from master import master_utils
from master import slaves_list
from buildbot.schedulers import timed
from buildbot.changes import filter
import config
import master_site_config
ActiveMaster = master_site_config.Chromium
c = BuildmasterConfig = {}
c['change_source'] = []
c['schedulers'] = []
c['status'] = [] pendingRequests = {}
c['builders'] = []
import master_source_cfg
import master_full_cfg
master_source_cfg.Update(config, ActiveMaster, c)
master_full_cfg.Update(config, ActiveMaster, c)
c['logCompressionLimit'] = False
c['projectName'] = ActiveMaster.project_name
c['projectURL'] = config.Master.project_url
c['buildbotURL'] = 'build.chromium.org/p/chromium/';
slaves = slaves_list.SlavesList('slaves.cfg', 'Chromium')
# Trying to find the location of adding factories to the builder
from twisted.python import log
for builder in c['builders']:
log.msg('My BUILDER',builder)
log.msg(dir(builder['factory']))
builder['slavenames'] = slaves.GetSlavesName(builder=builder['name'])
c['slaves'] = master_utils.AutoSetupSlaves(
c['builders'],
config.Master.GetBotPassword(),
missing_recipients=['buildbot#chromium-build-health.appspotmail.com'])
master_utils.VerifySetup(c, slaves)
master_utils.AutoSetupMaster(c, ActiveMaster, enable_http_status_push=ActiveMaster.is_production_host)
c['buildHorizon'] = 3000
c['logHorizon'] = 3000
c['eventHorizon'] = 200
I had missed to add the last part of the master.cfg which contains the configuration for nightly:
c['schedulers'].append(
timed.Nightly(name='nightly',
branch='src',
change_filter=filter.ChangeFilter(project_re='pj/Sample/chromium.*', branch=['buildbot-testing1']),
builderNames=['Linux x64'],
hour=8,
minute=15))
With the above configuration, the nightly gets triggered at the correct time.
But, it is not checking out the 'buildbot-testing1' branch as needed.
Instead, it exits with the following error:
===Running git checkout --force origin/ ===
error: pathspec 'origin/' did not match any file(s) know to git.
===Failed in 0.0. mins===

grails 2.3: tests not recognized by test-app

I am playing with the recently released grails 2.3.0. Unfortunately, test-app is not recognizing tests. Here is what I did to produce the problem.
First, make a new app and create a controller:
$ grails create-app firstApp
$ cd firstApp/
$ grails create-controller foo
I got the following files from creating the controller foo:
| Created file grails-app/controllers/firstapp/FooController.groovy
| Created file grails-app/views/foo
| Created file test/unit/firstapp/FooControllerSpec.groovy
Then, I edited the file FooControllerSpec.groovy by adding assert 1 == 2 in the auto-generated method void "test something"(). Here is the full content of FooControllerSpec.groovy after my editing:
package firstapp
import grails.test.mixin.TestFor
import spock.lang.Specification
/**
* See the API for {#link grails.test.mixin.web.ControllerUnitTestMixin} for usage instructions
*/
#TestFor(FooController)
class FooControllerSpec extends Specification {
def setup() {
}
def cleanup() {
}
void "test something"() {
assert 1 == 2
}
}
Then I ran the following command:
$ grails test-app
However, no tests were run. Here is the output from that command:
| Completed 0 unit test, 0 failed in 0m 0s
| Tests PASSED - view reports in /Users/jianbao.tao/projects/grails/firstApp/target/test-reports
My platform is OS X 10.8.5 + grails 2.3.0 + Java 1.6.0_51 + groovy 2.1.6. Can anyone tell me what's going on here, please? Thank you in advance.
Grails 2.3.0 ships with spock test framework by default. So, the test should look like:
void "test something"() {
expect:
1 == 2
}
For details on spockframework, visit docs.

How to configure Jenkins Cobertura plugin to monitor specific packages?

My project has a number of packages ("models", "controllers", etc.). I've set up Jenkins with the Cobertura plugin to generate coverage reports, which is great. I'd like to mark a build as unstable if coverage drops below a certain threshold, but only on certain packages (e.g., "controllers", but not "models"). I don't see an obvious way to do this in the configuration UI, however -- it looks like the thresholds are global.
Is there a way to do this?
(Answering my own question here)
As far as I can tell, this isn't possible -- I haven't seen anything after a couple days of looking. I wrote a simple script that would do what I want -- take the coverage output, parse it, and fail the build if coverage of specific packages didn't meet certain thresholds. It's dirty and can be cleaned up/expanded, but the basic idea is here. Comments are welcome.
#!/usr/bin/env python
'''
Jenkins' Cobertura plugin doesn't allow marking a build as successful or
failed based on coverage of individual packages -- only the project as a
whole. This script will parse the coverage.xml file and fail if the coverage of
specified packages doesn't meet the thresholds given
'''
import sys
from lxml import etree
PACKAGES_XPATH = etree.XPath('/coverage/packages/package')
def main(argv):
filename = argv[0]
package_args = argv[1:] if len(argv) > 1 else []
# format is package_name:coverage_threshold
package_coverage = {package: int(coverage) for
package, coverage in [x.split(':') for x in package_args]}
xml = open(filename, 'r').read()
root = etree.fromstring(xml)
packages = PACKAGES_XPATH(root)
failed = False
for package in packages:
name = package.get('name')
if name in package_coverage:
# We care about this one
print 'Checking package {} -- need {}% coverage'.format(
name, package_coverage[name])
coverage = float(package.get('line-rate', '0.0')) * 100
if coverage < package_coverage[name]:
print ('FAILED - Coverage for package {} is {}% -- '
'minimum is {}%'.format(
name, coverage, package_coverage[name]))
failed = True
else:
print "PASS"
if failed:
sys.exit(1)
if __name__ == '__main__':
main(sys.argv[1:])

Resources