-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python tests does not count over make cover
#54
Comments
Comment by alanjds @trotterdylan had said that:
and
Then I am trying to make the |
Comment by alanjds 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 |
Comment by alanjds 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. |
Comment by trotterdylan 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? |
Comment by alanjds @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?) |
Comment by trotterdylan 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. |
Comment by alanjds 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. |
Comment by alanjds I see. You are suggesting to import the module and run it, instead of pasting all the code inside the test... |
Comment by trotterdylan Right. Except rather than importing it with ImportModule(), call RunMain() on it so that the module is treated as |
Comment by alanjds I am writing the new tool. Just realized that the Where does it came from? Is imported from the |
Comment by trotterdylan 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. |
Comment by alanjds On google#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 |
Closed in favor of #55, correctly imported with comments |
History:
As said in the discussion starting on google#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: