From 1a800f516e49903f57fe70760fe466a8afc986c3 Mon Sep 17 00:00:00 2001 From: jessekrubin Date: Thu, 18 Jan 2024 13:04:20 -0800 Subject: [PATCH] test fixed: --- python/tests/test_fs.py | 74 -------------------------------------- python/tests/test_which.py | 15 +++++--- requirements.dev.in | 3 ++ requirements.dev.txt | 22 ++++++++++++ 4 files changed, 36 insertions(+), 78 deletions(-) create mode 100644 requirements.dev.in create mode 100644 requirements.dev.txt diff --git a/python/tests/test_fs.py b/python/tests/test_fs.py index 8026242..f4b7aa4 100644 --- a/python/tests/test_fs.py +++ b/python/tests/test_fs.py @@ -47,77 +47,3 @@ def test_read_file_missing_pathlike(tmp_path): ry.read_bytes(p) with pytest.raises(FileNotFoundError): ry.read_text(p) - - -# use std::char::decode_utf16; -# use std::path::Path; -# -# use pyo3::exceptions::{PyFileNotFoundError, PyUnicodeDecodeError}; -# use pyo3::prelude::*; -# use pyo3::types::{PyBytes, PyModule, PyString}; -# use pyo3::{pyfunction, wrap_pyfunction, PyResult}; -# -# pub mod fspath; -# #[pyfunction] -# pub fn read_vec_u8(py: Python<'_>, s: &str) -> PyResult> { -# let p = Path::new(s); -# let b = std::fs::read(p); -# match b { -# Ok(b) => Ok(b), -# Err(e) => { -# Err( -# PyFileNotFoundError::new_err(format!("{}: {}", p.to_str().unwrap(), -# format!("{}: {:?}", e.to_string(), p.to_str().unwrap()) -# ))) -# } -# } -# } -# -# #[pyfunction] -# pub fn read_bytes(py: Python<'_>, s: &PyString) -> PyResult { -# let bvec = read_vec_u8(py, -# s.to_str().unwrap(), -# )?; -# Ok(PyBytes::new(py, &bvec).into()) -# // match bvec { -# // Ok(bvec) => -# // Err(e) => { -# // Err(e) -# // // let emsg = format!("{}: {:?}", e.to_string(), s.to_string()); -# // // let pye = PyFileNotFoundError::new_err(format!("read_bytes: {}", emsg)); -# // // panic!("{}", pye); -# // } -# // } -# } -# -# #[pyfunction] -# pub fn read_text(py: Python<'_>, s: &PyString) -> PyResult { -# let thingy = s.to_str().unwrap(); -# let bvec = read_vec_u8( -# py, -# thingy, -# )?; -# -# // read_vec_u8(py, s).unwrap(); -# // let s = String::from_utf8(bvec); -# let r = std::str::from_utf8(&*bvec); -# -# match r { -# Ok(s) => Ok(s.to_string()), -# Err(e) => { -# let decode_err = PyUnicodeDecodeError::new_utf8( -# py, &*bvec, e, -# ) -# .unwrap(); -# Err(decode_err.into()) -# } -# } -# } -# -# pub fn pymod(m: &PyModule) -> PyResult<()> { -# m.add_function(wrap_pyfunction!(read_text, m)?)?; -# m.add_function(wrap_pyfunction!(read_bytes, m)?)?; -# m.add_class::()?; -# -# Ok(()) -# } diff --git a/python/tests/test_which.py b/python/tests/test_which.py index ce8c42c..fdc5419 100644 --- a/python/tests/test_which.py +++ b/python/tests/test_which.py @@ -6,6 +6,8 @@ def _clean_path(path): + if path is None: + return None res = path for ext in (".EXE", ".BAT", ".CMD"): if res.endswith(ext): @@ -48,6 +50,12 @@ def _mk_test_bin_dirs(tmppath): str(tmppath_bin2), ] else: + script_str = "\n".join( + [ + "#!/usr/bin/env bash", + "echo $PATH", + ] + ) # make exes for exe in exe_names: with open(tmppath / exe, "w") as f: @@ -58,14 +66,14 @@ def _mk_test_bin_dirs(tmppath): tmppath_bin.mkdir() for exe in exe_names: with open(tmppath_bin / exe, "w") as f: - f.write("echo $PATH") + f.write(script_str) # make executable os.chmod(tmppath_bin / exe, 0o777) tmppath_bin2 = tmppath / "bin2" tmppath_bin2.mkdir() for exe in exe_names: with open(tmppath_bin2 / exe, "w") as f: - f.write("echo $PATH") + f.write(script_str) # make executable os.chmod(tmppath_bin2 / exe, 0o777) return [ @@ -79,6 +87,7 @@ def test_which_python(): print("py", py_which) ry_which = ry.which("python") print("ry", ry_which) + # clean path py_clean = _clean_path(py_which) ry_clean = _clean_path(ry_which) @@ -128,8 +137,6 @@ def test_which_path_cwd(tmpdir: Path): print("ry", ry_clean) assert py_clean == ry_clean - # assert False - def test_which_nada(): exe = "idontexist" diff --git a/requirements.dev.in b/requirements.dev.in new file mode 100644 index 0000000..c912ae3 --- /dev/null +++ b/requirements.dev.in @@ -0,0 +1,3 @@ +pytest +pytest-asyncio + diff --git a/requirements.dev.txt b/requirements.dev.txt new file mode 100644 index 0000000..f9192ad --- /dev/null +++ b/requirements.dev.txt @@ -0,0 +1,22 @@ +# +# This file is autogenerated by pip-compile with Python 3.10 +# by the following command: +# +# pip-compile requirements.dev.in +# +exceptiongroup==1.2.0 + # via pytest +iniconfig==2.0.0 + # via pytest +packaging==23.2 + # via pytest +pluggy==1.3.0 + # via pytest +pytest==7.4.4 + # via + # -r requirements.dev.in + # pytest-asyncio +pytest-asyncio==0.23.3 + # via -r requirements.dev.in +tomli==2.0.1 + # via pytest