Skip to content

Commit 5e7e4e4

Browse files
committed
stdlib/time: add simple tests
1 parent 8e22314 commit 5e7e4e4

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

stdlib/time/testdata/test.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright 2022 The go-python Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style
3+
# license that can be found in the LICENSE file.
4+
5+
import time
6+
7+
now = time.time()
8+
now = time.time_ns()
9+
now = time.clock()
10+
time.sleep(0.1)
11+
12+
print("OK")

stdlib/time/testdata/test_golden.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
OK

stdlib/time/time.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func time_sleep(self py.Object, args py.Tuple) (py.Object, error) {
150150
if secs < 0 {
151151
return nil, py.ExceptionNewf(py.ValueError, "sleep length must be non-negative")
152152
}
153-
time.Sleep(time.Duration(secs * 1e9))
153+
time.Sleep(time.Duration(secs * py.Float(time.Second)))
154154
return py.None, nil
155155
}
156156

@@ -1007,17 +1007,15 @@ func init() {
10071007
py.MustNewMethod("perf_counter", time_perf_counter, 0, perf_counter_doc),
10081008
py.MustNewMethod("get_clock_info", time_get_clock_info, 0, get_clock_info_doc),
10091009
}
1010-
1010+
10111011
py.RegisterModule(&py.ModuleImpl{
10121012
Info: py.ModuleInfo{
1013-
Name: "time",
1014-
Doc: module_doc,
1013+
Name: "time",
1014+
Doc: module_doc,
10151015
},
10161016
Methods: methods,
1017-
Globals: py.StringDict{
1018-
},
1017+
Globals: py.StringDict{},
10191018
})
1020-
10211019
}
10221020

10231021
const module_doc = `This module provides various functions to manipulate time values.

stdlib/time/time_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2022 The go-python Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package time_test
6+
7+
import (
8+
"testing"
9+
10+
"github.com/go-python/gpython/pytest"
11+
)
12+
13+
func TestTime(t *testing.T) {
14+
pytest.RunScript(t, "./testdata/test.py")
15+
}

0 commit comments

Comments
 (0)