Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
test changes
Browse files Browse the repository at this point in the history
using a global repo called "PythonTestSuite" to enable python for tests
  • Loading branch information
psychowasp committed Sep 14, 2023
1 parent 4c8d529 commit a1c24f9
Show file tree
Hide file tree
Showing 634 changed files with 111 additions and 284,125 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>PythonSwiftCore-Package.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
<key>PythonSwiftCore.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>PythonSwiftCore</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>PythonSwiftCoreTests</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
13 changes: 9 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ let package = Package(
// .package(url: /* package url */, from: "1.0.0"),
//.package(path: "../PythonLib"),
.package(url: "https://github.com/PythonSwiftLink/PythonLib", from: "0.1.0"),
//.package(path: "../PythonLib")
.package(url: "https://github.com/PythonSwiftLink/PythonTestSuite", branch: "master"),
//.package(path: "../PythonTestSuite")
//.package(url: "https://github.com/PythonSwiftLink/PythonLib-iOS", branch: "main")
],

Expand All @@ -48,10 +49,14 @@ let package = Package(
// )
.testTarget(
name: "PythonSwiftCoreTests",
dependencies: ["PythonSwiftCore","PythonLib"],
resources: [
.copy("python_stdlib")
dependencies: [
"PythonSwiftCore",
"PythonLib",
"PythonTestSuite"
]
// resources: [
// .copy("python_stdlib")
// ]
),

]
Expand Down
139 changes: 70 additions & 69 deletions Tests/PythonSwiftCoreTests/PythonSwiftCoreTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import XCTest
@testable import PythonSwiftCore
@testable import PythonLib
@testable import PythonTestSuite
fileprivate extension PyPointer {

var refCount: Int { _Py_REFCNT(self) }
Expand All @@ -20,75 +21,75 @@ private func createPyTestFunction(name: String, _ code: String) throws -> PyPoin
result.decref()
return pyfunc
}
private var pythonIsRunning = false

var pystdlib: URL {
Bundle.module.url(forResource: "python_stdlib", withExtension: nil)!
}
private func initPython() {
if pythonIsRunning { return }
pythonIsRunning.toggle()
// let resourcePath = "/Users/musicmaker/Library/Mobile Documents/com~apple~CloudDocs/Projects/xcode_projects/touchBay_files/touchBay/touchBay"
let resourcePath: String
if #available(macOS 13, *) {
resourcePath = pystdlib.path()
} else {
resourcePath = pystdlib.path
}
print(resourcePath)
var config: PyConfig = .init()
print("Configuring isolated Python for Testing...")
PyConfig_InitIsolatedConfig(&config)

// Configure the Python interpreter:
// Run at optimization level 1
// (remove assertions, set __debug__ to False)
config.optimization_level = 1
// Don't buffer stdio. We want output to appears in the log immediately
config.buffered_stdio = 0
// Don't write bytecode; we can't modify the app bundle
// after it has been signed.
config.write_bytecode = 0
// Isolated apps need to set the full PYTHONPATH manually.
config.module_search_paths_set = 1

var status: PyStatus

let python_home = "\(resourcePath)"

var wtmp_str = Py_DecodeLocale(python_home, nil)

var config_home: UnsafeMutablePointer<wchar_t>!// = config.home

status = PyConfig_SetString(&config, &config_home, wtmp_str)

PyMem_RawFree(wtmp_str)

config.home = config_home

status = PyConfig_Read(&config)

print("PYTHONPATH:")

let path = "\(resourcePath)"
//let path = "\(resourcePath)/"

print("- \(path)")
wtmp_str = Py_DecodeLocale(path, nil)
status = PyWideStringList_Append(&config.module_search_paths, wtmp_str)

PyMem_RawFree(wtmp_str)


//PyImport_AppendInittab(makeCString(from: "fib"), PyInitFib)

//PyErr_Print()

//let new_obj = NewPyObject(name: "fib", cls: Int.self, _methods: FibMethods)
print("Initializing Python runtime...")
status = Py_InitializeFromConfig(&config)

}
//private var pythonIsRunning = false
//
//var pystdlib: URL {
// Bundle.module.url(forResource: "python_stdlib", withExtension: nil)!
//}
//private func initPython() {
// if pythonIsRunning { return }
// pythonIsRunning.toggle()
//// let resourcePath = "/Users/musicmaker/Library/Mobile Documents/com~apple~CloudDocs/Projects/xcode_projects/touchBay_files/touchBay/touchBay"
// let resourcePath: String
// if #available(macOS 13, *) {
// resourcePath = pystdlib.path()
// } else {
// resourcePath = pystdlib.path
// }
// print(resourcePath)
// var config: PyConfig = .init()
// print("Configuring isolated Python for Testing...")
// PyConfig_InitIsolatedConfig(&config)
//
// // Configure the Python interpreter:
// // Run at optimization level 1
// // (remove assertions, set __debug__ to False)
// config.optimization_level = 1
// // Don't buffer stdio. We want output to appears in the log immediately
// config.buffered_stdio = 0
// // Don't write bytecode; we can't modify the app bundle
// // after it has been signed.
// config.write_bytecode = 0
// // Isolated apps need to set the full PYTHONPATH manually.
// config.module_search_paths_set = 1
//
// var status: PyStatus
//
// let python_home = "\(resourcePath)"
//
// var wtmp_str = Py_DecodeLocale(python_home, nil)
//
// var config_home: UnsafeMutablePointer<wchar_t>!// = config.home
//
// status = PyConfig_SetString(&config, &config_home, wtmp_str)
//
// PyMem_RawFree(wtmp_str)
//
// config.home = config_home
//
// status = PyConfig_Read(&config)
//
// print("PYTHONPATH:")
//
// let path = "\(resourcePath)"
// //let path = "\(resourcePath)/"
//
// print("- \(path)")
// wtmp_str = Py_DecodeLocale(path, nil)
// status = PyWideStringList_Append(&config.module_search_paths, wtmp_str)
//
// PyMem_RawFree(wtmp_str)
//
//
// //PyImport_AppendInittab(makeCString(from: "fib"), PyInitFib)
//
// //PyErr_Print()
//
// //let new_obj = NewPyObject(name: "fib", cls: Int.self, _methods: FibMethods)
// print("Initializing Python runtime...")
// status = Py_InitializeFromConfig(&config)
//
//}
final class PythonSwiftCoreTests: XCTestCase {


Expand Down
Loading

0 comments on commit a1c24f9

Please sign in to comment.