Skip to content

Commit

Permalink
test fixed:
Browse files Browse the repository at this point in the history
  • Loading branch information
jessekrubin committed Jan 18, 2024
1 parent fe10988 commit 1a800f5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 78 deletions.
74 changes: 0 additions & 74 deletions python/tests/test_fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<u8>> {
# 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<PyObject> {
# 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<String> {
# 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::<fspath::PyPath>()?;
#
# Ok(())
# }
15 changes: 11 additions & 4 deletions python/tests/test_which.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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 [
Expand All @@ -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)
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions requirements.dev.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pytest
pytest-asyncio

22 changes: 22 additions & 0 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1a800f5

Please sign in to comment.