diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e0b9938c3..032a75e77 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,4 +1,7 @@ -on: [push, pull_request] +on: + push: + branches: [master] + pull_request: name: CI diff --git a/tests/snippets/bytearray.py b/tests/snippets/bytearray.py index 889c34056..02331a598 100644 --- a/tests/snippets/bytearray.py +++ b/tests/snippets/bytearray.py @@ -352,11 +352,11 @@ assert bytearray(b"hjhtuyfjtyhuhjuyj").translate(None, delete=b"ht") == bytearra # strip lstrip rstrip -assert bytearray(b" spacious ").strip() == bytearray(b"spacious") +assert bytearray(b" \n spacious \n ").strip() == bytearray(b"spacious") assert bytearray(b"www.example.com").strip(b"cmowz.") == bytearray(b"example") -assert bytearray(b" spacious ").lstrip() == bytearray(b"spacious ") +assert bytearray(b" \n spacious ").lstrip() == bytearray(b"spacious ") assert bytearray(b"www.example.com").lstrip(b"cmowz.") == bytearray(b"example.com") -assert bytearray(b" spacious ").rstrip() == bytearray(b" spacious") +assert bytearray(b" spacious \n ").rstrip() == bytearray(b" spacious") assert bytearray(b"mississippi").rstrip(b"ipz") == bytearray(b"mississ") diff --git a/tests/snippets/bytes.py b/tests/snippets/bytes.py index 59fdb40b7..1f54c0454 100644 --- a/tests/snippets/bytes.py +++ b/tests/snippets/bytes.py @@ -341,11 +341,11 @@ assert b"hjhtuyfjtyhuhjuyj".translate(None, delete=b"ht") == b"juyfjyujuyj" # strip lstrip rstrip -assert b" spacious ".strip() == b"spacious" +assert b" \n spacious \n ".strip() == b"spacious" assert b"www.example.com".strip(b"cmowz.") == b"example" -assert b" spacious ".lstrip() == b"spacious " +assert b" \n spacious ".lstrip() == b"spacious " assert b"www.example.com".lstrip(b"cmowz.") == b"example.com" -assert b" spacious ".rstrip() == b" spacious" +assert b" spacious \n ".rstrip() == b" spacious" assert b"mississippi".rstrip(b"ipz") == b"mississ" diff --git a/tests/snippets/stdlib_subprocess.py b/tests/snippets/stdlib_subprocess.py index 7e9adaf7f..72bcb7b5e 100644 --- a/tests/snippets/stdlib_subprocess.py +++ b/tests/snippets/stdlib_subprocess.py @@ -30,14 +30,7 @@ p.wait() is_unix = "win" not in sys.platform or "darwin" in sys.platform -if is_unix: - # unix - test_output = b"test\n" -else: - # windows - test_output = b"test\r\n" - -assert p.stdout.read() == test_output +assert p.stdout.read().strip() == b"test" p = subprocess.Popen(["sleep", "2"]) p.terminate() @@ -57,4 +50,4 @@ else: p = subprocess.Popen(["echo", "test"], stdout=subprocess.PIPE) (stdout, stderr) = p.communicate() -assert stdout == test_output +assert stdout.strip() == b"test" diff --git a/tests/test_snippets.py b/tests/test_snippets.py index 6e5b4a915..8cc6f49c6 100644 --- a/tests/test_snippets.py +++ b/tests/test_snippets.py @@ -49,6 +49,7 @@ def run_via_cpython(filename): env = os.environ.copy() subprocess.check_call([sys.executable, filename], env=env) +RUST_TARGET = "debug" if os.environ.get("CODE_COVERAGE", "false") == "true" else "release" def run_via_rustpython(filename, test_type): env = os.environ.copy() @@ -56,10 +57,7 @@ def run_via_rustpython(filename, test_type): env['RUST_BACKTRACE'] = '1' env['PYTHONPATH'] = RUSTPYTHON_LIB_DIR - target = "release" - if env.get("CODE_COVERAGE", "false") == "true": - target = "debug" - binary = os.path.abspath(os.path.join(ROOT_DIR, "target", target, "rustpython")) + binary = os.path.abspath(os.path.join(ROOT_DIR, "target", RUST_TARGET, "rustpython")) subprocess.check_call([binary, filename], env=env) @@ -136,8 +134,7 @@ class SampleTestCase(unittest.TestCase): generate_slices(cls.slices_resource_path) # cargo stuff - subprocess.check_call(["cargo", "build"]) - subprocess.check_call(["cargo", "build", "--release"]) + subprocess.check_call(["cargo", "build", "--{}".format(RUST_TARGET)]) @classmethod def tearDownClass(cls): diff --git a/vm/src/obj/objbyteinner.rs b/vm/src/obj/objbyteinner.rs index 149d912c5..37c061661 100644 --- a/vm/src/obj/objbyteinner.rs +++ b/vm/src/obj/objbyteinner.rs @@ -952,28 +952,30 @@ impl PyByteInner { chars: OptionalArg, position: ByteInnerPosition, ) -> PyResult> { - let chars = if let OptionalArg::Present(bytes) = chars { - bytes.elements - } else { - vec![b' '] + let is_valid_char = |c| { + if let OptionalArg::Present(ref bytes) = chars { + bytes.elements.contains(c) + } else { + c.is_ascii_whitespace() + } }; let mut start = 0; let mut end = self.len(); if let ByteInnerPosition::Left | ByteInnerPosition::All = position { - for (n, i) in self.elements.iter().enumerate() { - if !chars.contains(i) { - start = n; + for (i, c) in self.elements.iter().enumerate() { + if !is_valid_char(c) { + start = i; break; } } } if let ByteInnerPosition::Right | ByteInnerPosition::All = position { - for (n, i) in self.elements.iter().rev().enumerate() { - if !chars.contains(i) { - end = self.len() - n; + for (i, c) in self.elements.iter().rev().enumerate() { + if !is_valid_char(c) { + end = self.len() - i; break; } }