@@ -30,70 +30,70 @@ parser.add_argument('-modname', help='Module to generate a _test.go file to', re
30
30
31
31
32
32
template = textwrap .dedent ("""
33
- package %s
34
- import (
35
- "os"
36
- "grumpy"
37
- %s
38
- )
39
- func TestRunCode(t *testing.T) {
40
- grumpy .ImportModule(grumpy.NewRootFrame(), "traceback")
41
- if grumpy.RunMain(Code) != 0 {
42
- t .Fail()
43
- }
44
- }
33
+ package %s
34
+ import (
35
+ \t "os"
36
+ \t "grumpy"
37
+ \t %s
38
+ )
39
+ func TestRunCode(t *testing.T) {
40
+ \t grumpy .ImportModule(grumpy.NewRootFrame(), "traceback")
41
+ \t if grumpy.RunMain(Code) != 0 {
42
+ \t \t t .Fail()
43
+ \t }
44
+ }
45
45
""" )
46
46
47
47
48
48
def _package_name (modname ):
49
- if modname .startswith ('__go__/' ):
50
- return '__python__/' + modname
51
- return '__python__/' + modname .replace ('.' , '/' )
49
+ if modname .startswith ('__go__/' ):
50
+ return '__python__/' + modname
51
+ return '__python__/' + modname .replace ('.' , '/' )
52
52
53
53
54
54
def _get_gopath ():
55
- gopath = os .getenv ('GOPATH' , None )
56
- if not gopath :
57
- print >> sys .stderr , 'GOPATH not set'
58
- raise RuntimeError ('GOPATH not set' )
59
- return gopath
55
+ gopath = os .getenv ('GOPATH' , None )
56
+ if not gopath :
57
+ print >> sys .stderr , 'GOPATH not set'
58
+ raise RuntimeError ('GOPATH not set' )
59
+ return gopath
60
60
61
61
62
62
def main (args ):
63
- modname = args .modname
64
- gopath = _get_gopath ()
65
- workdir = 'build' # It is ok _right now_
66
- py_dir = os .path .join (workdir , 'src' , '__python__' )
67
- mod_dir = os .path .join (py_dir , modname )
63
+ modname = args .modname
64
+ gopath = _get_gopath ()
65
+ workdir = 'build' # It is ok _right now_
66
+ py_dir = os .path .join (workdir , 'src' , '__python__' )
67
+ mod_dir = os .path .join (py_dir , modname )
68
68
69
- script = os .path .join (py_dir , '%s.py' % modname )
70
- gopath = gopath + os .pathsep + workdir
71
- package = _package_name (modname )
69
+ script = os .path .join (py_dir , '%s.py' % modname )
70
+ gopath = gopath + os .pathsep + workdir
71
+ package = _package_name (modname )
72
72
73
- if not os .path .isfile (script ):
74
- return # The script does not exist. And is OK!
73
+ if not os .path .isfile (script ):
74
+ return # The script does not exist. And is OK!
75
75
76
- names = imputil .calculate_transitive_deps (modname , script , gopath )
76
+ names = imputil .calculate_transitive_deps (modname , script , gopath )
77
77
78
- # Find the script associated with the given module.
79
- for d in gopath .split (os .pathsep ):
80
- script = imputil .find_script (
81
- os .path .join (d , 'src' , '__python__' ), modname )
82
- if script :
83
- break
84
- else :
85
- raise RuntimeError ("can't find module %s" , modname )
78
+ # Find the script associated with the given module.
79
+ for d in gopath .split (os .pathsep ):
80
+ script = imputil .find_script (
81
+ os .path .join (d , 'src' , '__python__' ), modname )
82
+ if script :
83
+ break
84
+ else :
85
+ raise RuntimeError ("can't find module %s" , modname )
86
86
87
- names = imputil .calculate_transitive_deps (modname , script , gopath )
88
- # Make sure traceback is available in all Python binaries.
89
- names .add ('traceback' )
87
+ names = imputil .calculate_transitive_deps (modname , script , gopath )
88
+ # Make sure traceback is available in all Python binaries.
89
+ names .add ('traceback' )
90
90
91
- imports = '\n ' .join ('"%s"' % _package_name (name ) for name in names )
91
+ imports = '\n \t ' .join ('"%s"' % _package_name (name ) for name in names )
92
92
93
- testfile_contents = template % (modname , imports )
94
- with open (os .path .join (mod_dir , 'module_test.go' ), 'w' ) as go_testfile :
95
- go_testfile .write (testfile_contents )
93
+ testfile_contents = template % (modname , imports )
94
+ with open (os .path .join (mod_dir , 'module_test.go' ), 'w' ) as go_testfile :
95
+ go_testfile .write (testfile_contents )
96
96
97
97
98
98
if __name__ == '__main__' :
99
- sys .exit (main (parser .parse_args ()))
99
+ sys .exit (main (parser .parse_args ()))
0 commit comments