Fix subprocess test and byte{s,array}.{,l,r}strip

This commit is contained in:
coolreader18 authored and Noah committed 2020-01-28 11:33:11 -06:00
1 parent 3a8f2aa25b
commit ff97ac5133
4 files changed
+20 -25

No files matched your search

+3 -3
View File
@@ -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")
+3 -3
View File
@@ -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"
+2 -9
View File
@@ -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"
+12 -10
View File
@@ -952,28 +952,30 @@ impl PyByteInner {
chars: OptionalArg<PyByteInner>,
position: ByteInnerPosition,
) -> PyResult<Vec<u8>> {
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;
}
}