Skip to content

Commit edfb33b

Browse files
committed
[PythonKit] Added testing for Python 2 and Python 3
1 parent d1ab250 commit edfb33b

2 files changed

Lines changed: 290 additions & 290 deletions

File tree

‎Tests/PythonKitTests/NumpyConversionTests.swift‎

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,31 @@ import XCTest
22
import PythonKit
33

44
class NumpyConversionTests: XCTestCase {
5-
static var numpyModule = try? Python.attemptImport("numpy")
6-
7-
func testArrayConversion() {
8-
guard let np = NumpyConversionTests.numpyModule else { return }
9-
10-
let numpyArrayEmpty = np.array([] as [Float], dtype: np.float32)
11-
XCTAssertEqual([], Array<Float>(numpy: numpyArrayEmpty))
12-
13-
let numpyArrayBool = np.array([true, false, false, true])
14-
XCTAssertEqual([true, false, false, true], Array<Bool>(numpy: numpyArrayBool))
15-
16-
let numpyArrayFloat = np.ones([6], dtype: np.float32)
17-
XCTAssertEqual(Array(repeating: 1, count: 6), Array<Float>(numpy: numpyArrayFloat))
18-
19-
let numpyArrayInt32 = np.array([-1, 4, 25, 2018], dtype: np.int32)
20-
XCTAssertEqual([-1, 4, 25, 2018], Array<Int32>(numpy: numpyArrayInt32))
21-
22-
let numpyArray2D = np.ones([2, 3])
23-
XCTAssertNil(Array<Float>(numpy: numpyArray2D))
24-
25-
let numpyArrayStrided = np.array([[1, 2], [1, 2]], dtype: np.int32)[
26-
Python.slice(Python.None), 1]
27-
// Assert that the array has a stride, so that we're certainly testing a
28-
// strided array.
29-
XCTAssertNotEqual(numpyArrayStrided.__array_interface__["strides"], Python.None)
30-
XCTAssertEqual([2, 2], Array<Int32>(numpy: numpyArrayStrided))
31-
}
5+
static var numpyModule = try? Python.attemptImport("numpy")
6+
7+
func testArrayConversion() {
8+
guard let np = NumpyConversionTests.numpyModule else { return }
9+
10+
let numpyArrayEmpty = np.array([] as [Float], dtype: np.float32)
11+
XCTAssertEqual([], Array<Float>(numpy: numpyArrayEmpty))
12+
13+
let numpyArrayBool = np.array([true, false, false, true])
14+
XCTAssertEqual([true, false, false, true], Array<Bool>(numpy: numpyArrayBool))
15+
16+
let numpyArrayFloat = np.ones([6], dtype: np.float32)
17+
XCTAssertEqual(Array(repeating: 1, count: 6), Array<Float>(numpy: numpyArrayFloat))
18+
19+
let numpyArrayInt32 = np.array([-1, 4, 25, 2018], dtype: np.int32)
20+
XCTAssertEqual([-1, 4, 25, 2018], Array<Int32>(numpy: numpyArrayInt32))
21+
22+
let numpyArray2D = np.ones([2, 3])
23+
XCTAssertNil(Array<Float>(numpy: numpyArray2D))
24+
25+
let numpyArrayStrided = np.array([[1, 2], [1, 2]], dtype: np.int32)[
26+
Python.slice(Python.None), 1]
27+
// Assert that the array has a stride, so that we're certainly testing a
28+
// strided array.
29+
XCTAssertNotEqual(numpyArrayStrided.__array_interface__["strides"], Python.None)
30+
XCTAssertEqual([2, 2], Array<Int32>(numpy: numpyArrayStrided))
31+
}
3232
}

0 commit comments

Comments
 (0)