-
Notifications
You must be signed in to change notification settings - Fork 646
Python tests does not count over make cover
#383
Comments
@trotterdylan had said that:
and
Then I am trying to make the |
From a Python file containing package __main__
import πg "grumpy"
var Code *πg.Code
func init() {
Code = πg.NewCode("<module>", "print_hello.py", nil, 0, func(πF *πg.Frame, _ []*πg.Object) (*πg.Object, *πg.BaseException) {
var πR *πg.Object; _ = πR
var πE *πg.BaseException; _ = πE
var πTemp001 []*πg.Object
_ = πTemp001
for ; πF.State() >= 0; πF.PopCheckpoint() {
switch πF.State() {
case 0:
default: panic("unexpected function state")
}
// line 1: print 'Hello World!'
πF.SetLineno(1)
πTemp001 = make([]*πg.Object, 1)
πTemp001[0] = πg.NewStr("Hello World!").ToObject()
if πE = πg.Print(πF, πTemp001, true); πE != nil {
continue
}
}
return nil, πE
})
πg.RegisterModule("__main__", Code)
} I managed to add a flag to package __main__
import πg "grumpy"
import πt "testing"
var Code *πg.Code
func init() {
Code = πg.NewCode("<module>", "print_hello.py", nil, 0, func(πF *πg.Frame, _ []*πg.Object) (*πg.Object, *πg.BaseException) {
var πR *πg.Object; _ = πR
var πE *πg.BaseException; _ = πE
var πTemp001 []*πg.Object
_ = πTemp001
for ; πF.State() >= 0; πF.PopCheckpoint() {
switch πF.State() {
case 0:
default: panic("unexpected function state")
}
// line 1: print 'Hello World!'
πF.SetLineno(1)
πTemp001 = make([]*πg.Object, 1)
πTemp001[0] = πg.NewStr("Hello World!").ToObject()
if πE = πg.Print(πF, πTemp001, true); πE != nil {
continue
}
}
return nil, πE
})
πg.RegisterModule("__main__", Code)
}
func TestRunCode(t *testing.T) {
init()
πg.ImportModule(grumpy.NewRootFrame(), "traceback")
//πg.ImportModule(grumpy.NewRootFrame(), "__main__")
πg.RunMain(Code)
} to be saved as |
Question: Is this an appropriate Go test to count for coverage, or should something be changed on the output yet? The plan is to, after producing a reasonable output file, figure where should it be placed and how to put it there. |
I think it's reasonable to use the Python files in testing/ count toward coverage. Rather than adding complexity to grumpc, could we make this a standalone utility that takes a module name and generates a _test.go file that can be run for this purpose? |
@trotterdylan Can this new tool be made later, before the merge? In fact, I am biased towards refactor Anyway,
(am I making the right questions, or got totally clueless?) |
Thinking about it a little more, what you really want is to do something similar to grumprun, except instead of generating a main() function, you will generate a TestRunCode() function. Unfortunately the logic is a bit different, because you really want to generate the _test.go file, not build and run a binary. I would write a new tool based on what's in grumprun (except much simpler, because it doesn't need invoke grumpc or the Go toolchain) that outputs something like this:
This file would be called foo_test.go and would sit alongside the code generated by grumpc for module foo. This would mean you could run the test like: The second part of this is to merge coverage data for all the different sources. In particular, the coverage generated for the grumpy package with the coverage generated by each of the tests in testing/. This will require some work to coverparse to pull all that data together into a single coverage report. |
Thanks for pointing to a direction and for saying where the test file will end and how to run it. I will take a look at the grumpyrun later. Maybe this week, maybe next one. |
I see. You are suggesting to import the module and run it, instead of pasting all the code inside the test... |
Right. Except rather than importing it with ImportModule(), call RunMain() on it so that the module is treated as |
I am writing the new tool. Just realized that the Where does it came from? Is imported from the |
In the example I wrote above, Code would come from the foo package that's being tested. In Go, the tests are part of the package under test and can access members of that package. |
On #389, the new tool Aside from formatting and this kind of details, do the tool is producing the right If so, the next step would be |
On #389, I did not understand what caused this: https://travis-ci.org/google/grumpy/jobs/316438956#L938
What had I made wrong? |
Gone ahead w/ the proposed test generator. Results for Chosen the The result _test.go generated is: package functools
import (
"testing"
"grumpy"
_ "__python__/_functools"
_ "__python__/traceback"
)
func TestRunCode(t *testing.T) {
grumpy.ImportModule(grumpy.NewRootFrame(), "traceback")
if grumpy.RunMain(Code) != 0 {
t.Fail()
}
}
However, I started to think that this transitive imports should be on the |
Something strange is failing:
But both files are of the pack
(there is no Now I am stuck. |
The package declaration in the _test.go file should just be |
On the file named |
It worked after changed |
Yay! Test passed!! Now, how to count the coverage over? |
I took a look on the Makefile and on the -coverprofile flag. Got the impression that all the tests should be about a package. If it is true, all the tests of TestRunCode stuff should be of So should I generate every test on the same single folder to fulfil the Go desired directory structure? |
Yeah I guess you're right that we're interested in the coverage against the grumpy package. The problem with putting all the generated tests together in the same directory is that they have symbols that will collide (e.g. Looks like this issue is relevant: golang/go#6909 It looks like in Go 1.10 you can specify multiple packages to test with -coverprofile and the coverage for each package will be a union of the coverage data generated for all the tests being run. Maybe you could try running against the 1.10 beta to see if that works? Apparently it will be released in January. |
I see. Will take a look on the 1.10 tool. Thanks for pointing. |
History:
As said in the discussion starting on #243 (comment), the Python tests does not count over
make cover
report.Personally, this hinders the development speed by forcing people to write tests twice: one for Python (what we want working) and one for Golang (what we need to count on
make cover
).The hypothesis is: Lowering the work needed to push code, more code will be pushed by more people.
Lets fix it to speed up the development!
Plan:
grumpc
to be able to producemodule_test.go
output from Python test filesmake test
to producemodule_test.go
files fromgrumpy/testing/*.py
filesmodule_test.go
files to be in such place that counts for coverage.go
file. Write a test the for the change in a.py
make cover
counts the.py
covering the.go
changedThe text was updated successfully, but these errors were encountered: