Skip to content

Commit 7fc337b

Browse files
committed
add more globals, add more tests
1 parent c5905e8 commit 7fc337b

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

os/os.module.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,25 @@ import (
1515
"github.com/go-python/gpython/py"
1616
)
1717

18+
// getsep returns the common path seperator: '/' for anything but windows, '\' for windows
19+
func getsep() py.String {
20+
if runtime.GOOS != "windows" {
21+
return py.String("/")
22+
}
23+
return py.String("\\")
24+
}
25+
26+
// getname returns the operating system name: posix/nt/java
27+
func getname() py.String {
28+
if runtime.GOOS == "windows" {
29+
return py.String("nt")
30+
}
31+
if runtime.GOOS == "android" {
32+
return py.String("java")
33+
}
34+
return py.String("posix")
35+
}
36+
1837
func init() {
1938
methods := []*py.Method{
2039
py.MustNewMethod("getcwd", getCwd, 0, "Get the current working directory"),
@@ -27,10 +46,11 @@ func init() {
2746
py.MustNewMethod("_exit", _exit, 0, "Immediate program termination."),
2847
py.MustNewMethod("system", system, 0, "Run shell commands, prints stdout directly to deault"),
2948
}
30-
3149
globals := py.StringDict{
3250
"error": py.OSError,
3351
"environ": getEnvVariables(),
52+
"sep": getsep(),
53+
"name": getname(),
3454
}
3555

3656
py.RegisterModule(&py.ModuleImpl{

os/os.test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@ def _fail(test_name):
168168
_fail('bytes(os.getcwd(), "utf-8") == os.getcwdb()')
169169
failed+=1
170170

171+
if os.sep == "/" and os.name == "posix":
172+
_pass('os.sep == "/" and os.name == "posix"')
173+
passed_tests+=1
174+
elif os.sep == "\\" and os.name == "nt":
175+
_pass('os.sep == "\\" and os.name == "windows"')
176+
passed_tests+=1
177+
else:
178+
_fail("os.sep corresponding with os.name")
179+
failed+=1
180+
171181
print()
172182
print(bcolors.ENDC+bcolors.BOLD+bcolors.HEADER+"Please check if $HOME will be outputted...")
173183
print(bcolors.ENDC)

0 commit comments

Comments
 (0)