nebius/SWE-bench-extra huggingface dataset:
Repository: sanic-org/sanic

Issue:
ASGI websocket must pass thru bytes as is


_Originally posted by @Tronic in https://github.com/sanic-org/sanic/pull/2640#discussion_r1058027028_
      

Comments:

Patch:
diff --git a/sanic/server/websockets/connection.py b/sanic/server/websockets/connection.py
index 87881b84..8ff19da6 100644
--- a/sanic/server/websockets/connection.py
+++ b/sanic/server/websockets/connection.py
@@ -45,7 +45,7 @@ class WebSocketConnection:
 
         await self._send(message)
 
-    async def recv(self, *args, **kwargs) -> Optional[str]:
+    async def recv(self, *args, **kwargs) -> Optional[Union[str, bytes]]:
         message = await self._receive()
 
         if message["type"] == "websocket.receive":
@@ -53,7 +53,7 @@ class WebSocketConnection:
                 return message["text"]
             except KeyError:
                 try:
-                    return message["bytes"].decode()
+                    return message["bytes"]
                 except KeyError:
                     raise InvalidUsage("Bad ASGI message received")
         elif message["type"] == "websocket.disconnect":


Test patch:
diff --git a/tests/test_asgi.py b/tests/test_asgi.py
index 0c76a67f..fe9ff306 100644
--- a/tests/test_asgi.py
+++ b/tests/test_asgi.py
@@ -342,7 +342,7 @@ async def test_websocket_send(send, receive, message_stack):
 
 
 @pytest.mark.asyncio
-async def test_websocket_receive(send, receive, message_stack):
+async def test_websocket_text_receive(send, receive, message_stack):
     msg = {"text": "hello", "type": "websocket.receive"}
     message_stack.append(msg)
 
@@ -351,6 +351,15 @@ async def test_websocket_receive(send, receive, message_stack):
 
     assert text == msg["text"]
 
+@pytest.mark.asyncio
+async def test_websocket_bytes_receive(send, receive, message_stack):
+    msg = {"bytes": b"hello", "type": "websocket.receive"}
+    message_stack.append(msg)
+
+    ws = WebSocketConnection(send, receive)
+    data = await ws.receive()
+
+    assert data == msg["bytes"]
 
 @pytest.mark.asyncio
 async def test_websocket_accept_with_no_subprotocols(
Repository: sanic-org/sanic

Issue:
JSONResponse defaults to None content-type
### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

```python
@app.get("/")
async def handler(request: Request):
    return JSONResponse({"message": "Hello World!"})
```
```sh
╰─▶ curl localhost:9999   
HTTP/1.1 200 OK
content-length: 26
connection: keep-alive
alt-svc: 
content-type: None

{"message":"Hello World!"}
```

### Code snippet

_No response_

### Expected Behavior

`content-type: application/json`

### How do you run Sanic?

Sanic CLI

### Operating System

all

### Sanic Version

LTS+

### Additional context

_No response_

Comments:

Patch:
diff --git a/sanic/response/types.py b/sanic/response/types.py
index 3f93855d..d3c8cdb6 100644
--- a/sanic/response/types.py
+++ b/sanic/response/types.py
@@ -345,7 +345,7 @@ class JSONResponse(HTTPResponse):
         body: Optional[Any] = None,
         status: int = 200,
         headers: Optional[Union[Header, Dict[str, str]]] = None,
-        content_type: Optional[str] = None,
+        content_type: str = "application/json",
         dumps: Optional[Callable[..., str]] = None,
         **kwargs: Any,
     ):


Test patch:
diff --git a/tests/test_response_json.py b/tests/test_response_json.py
index c89dba42..aa1c61dd 100644
--- a/tests/test_response_json.py
+++ b/tests/test_response_json.py
@@ -213,3 +213,12 @@ def test_pop_list(json_app: Sanic):
 
     _, resp = json_app.test_client.get("/json-pop")
     assert resp.body == json_dumps(["b"]).encode()
+
+
+def test_json_response_class_sets_proper_content_type(json_app: Sanic):
+    @json_app.get("/json-class")
+    async def handler(request: Request):
+        return JSONResponse(JSON_BODY)
+
+    _, resp = json_app.test_client.get("/json-class")
+    assert resp.headers["content-type"] == "application/json"
Repository: sayanarijit/expandvars

Issue:
Right Hand Side Variable Not Expanded with the '-' Operator
Take the example that I got from some random website

```
VAR1=1
VAR2=2
# var3 is unset.

echo ${VAR1-$VAR2}   # 1
echo ${VAR3-$VAR2}   # 2
```

This seems to be normal bash behaviour, but in the above example expandvars will output `1` and `$VAR2` respectively. Here is the Python code

```python

import os
from expandvars import expandvars

os.environ['VAR1'] = '1'
os.environ['VAR2'] = '2'

v = '${VAR1-$VAR2}'
print(f'{v} expands to "{expandvars(v)}"')    # ${VAR1-$VAR2} expands to "1"

v = '${VAR3-$VAR2}'
print(f'{v} expands to "{expandvars(v)}"')    # ${VAR3-$VAR2} expands to "$VAR2"
```

Comments:

Patch:
diff --git a/expandvars.py b/expandvars.py
index 0f3254a..ae1f4aa 100644
--- a/expandvars.py
+++ b/expandvars.py
@@ -392,7 +392,7 @@ def expand_default(var, vars_, set_, nounset, indirect, environ, var_symbol):
     for c in vars_:
         if c == "}":
             n = len(default) + 1
-            default_ = "".join(default)
+            default_ = expand("".join(default))
             if set_ and var not in environ:
                 environ.update({var: default_})
             return getenv(


Test patch:
diff --git a/tests/test_expandvars.py b/tests/test_expandvars.py
index 49f5e21..b95d639 100644
--- a/tests/test_expandvars.py
+++ b/tests/test_expandvars.py
@@ -62,7 +62,7 @@ def test_expandvars_pid():
     assert expandvars.expandvars("PID( $$ )") == "PID( {0} )".format(getpid())
 
 
-@patch.dict(env, {})
+@patch.dict(env, {"ALTERNATE": "Alternate"})
 def test_expandvars_get_default():
     importlib.reload(expandvars)
 
@@ -70,6 +70,7 @@ def test_expandvars_get_default():
     assert expandvars.expandvars("${FOO:-default}") == "default"
     assert expandvars.expandvars("${FOO:-}") == ""
     assert expandvars.expandvars("${FOO:-foo}:${FOO-bar}") == "foo:bar"
+    assert expandvars.expandvars("${FOO:-$ALTERNATE}") == "Alternate"
 
 
 @patch.dict(env, {})
Repository: scalableminds/cluster_tools

Issue:
map_to_futures with empty list crashes, should return empty list
The resumable executor of voxelytics checks what needs to be re-run. If that list becomes empty, map_to_futures crashes

Comments:

Patch:
diff --git a/cluster_tools/schedulers/cluster_executor.py b/cluster_tools/schedulers/cluster_executor.py
index 68d4cd1..304588a 100644
--- a/cluster_tools/schedulers/cluster_executor.py
+++ b/cluster_tools/schedulers/cluster_executor.py
@@ -10,9 +10,7 @@ import time
 from abc import abstractmethod
 import logging
 from typing import Union
-from ..util import local_filename
 from cluster_tools.tailf import Tail
-from logging import getLogger
 
 class RemoteException(Exception):
     def __init__(self, error, job_id):
@@ -249,6 +247,9 @@ class ClusterExecutor(futures.Executor):
     def map_to_futures(self, fun, allArgs, output_pickle_path_getter=None):
         self.ensure_not_shutdown()
         allArgs = list(allArgs)
+        if len(allArgs) == 0:
+            return []
+
         should_keep_output = output_pickle_path_getter is not None
 
         futs_with_output_paths = []


Test patch:
diff --git a/test.py b/test.py
index 0eb4662..05c00d3 100644
--- a/test.py
+++ b/test.py
@@ -1,8 +1,6 @@
 import cluster_tools
-import subprocess
 import concurrent.futures
 import time
-import sys
 import logging
 from enum import Enum
 from functools import partial
@@ -163,6 +161,12 @@ def test_map_to_futures():
             for duration, result in zip(durations, results):
                 assert result == duration
 
+def test_empty_map_to_futures():
+    for exc in get_executors():
+        with exc:
+            futures = exc.map_to_futures(sleep, [])
+            results = [f.result() for f in futures]
+            assert len(results) == 0
 
 def output_pickle_path_getter(tmp_dir, chunk):
 
@@ -170,8 +174,6 @@ def output_pickle_path_getter(tmp_dir, chunk):
 
 def test_map_to_futures_with_pickle_paths():
 
-    dir_path = Path("").resolve()
-
     for exc in get_executors():
         with tempfile.TemporaryDirectory(dir=".") as tmp_dir:
             with exc:
Repository: scanapi/scanapi

Issue:
Change HTML report to default
Change HTML report to default. Current it is markdown, but HTML is way more popular and our html report is [beautiful](https://github.com/scanapi/scanapi/pull/157) now

Here is where we need to change it: https://github.com/scanapi/scanapi/blob/master/scanapi/settings.py#L11

Comments:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ceb2670..1414143 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Changed
 - Unified keys validation in a single method [#151](https://github.com/scanapi/scanapi/pull/151)
+- Change default template to html [#173](https://github.com/scanapi/scanapi/pull/173)
 
 ## [0.1.0] - 2020-05-14
 ### Added
diff --git a/scanapi/settings.py b/scanapi/settings.py
index 115ac2b..c5d77ab 100644
--- a/scanapi/settings.py
+++ b/scanapi/settings.py
@@ -8,7 +8,7 @@ DEFAULT_CONFIG_PATH = ".scanapi.yaml"
 class Settings(dict):
     def __init__(self):
         self["spec_path"] = "api.yaml"
-        self["reporter"] = "markdown"
+        self["reporter"] = "html"
         self["output_path"] = None
         self["template"] = None
 


Test patch:
diff --git a/tests/unit/test_settings.py b/tests/unit/test_settings.py
index a8f2554..d52a58e 100644
--- a/tests/unit/test_settings.py
+++ b/tests/unit/test_settings.py
@@ -8,7 +8,7 @@ class TestSettings:
     class TestInit:
         def test_should_init_with_default_values(self):
             assert settings["spec_path"] == "api.yaml"
-            assert settings["reporter"] == "markdown"
+            assert settings["reporter"] == "html"
             assert settings["output_path"] is None
             assert settings["template"] is None
 
@@ -53,7 +53,7 @@ class TestSettings:
 
             assert settings == {
                 "spec_path": "path/spec-path",
-                "reporter": "markdown",
+                "reporter": "html",
                 "output_path": "path/output-path",
                 "template": None,
                 "config_path": "path/config-path",
Repository: scanapi/scanapi

Issue:
Duplicated row `status code` on Report
Duplicated row `status code` on Report

![image](https://user-images.githubusercontent.com/2728804/84925248-0302ea00-b0a0-11ea-9ad3-2030fbbe396a.png)


Comments:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a7f7c20..2cf3de0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 - Entry point to `scanapi:main` [#172](https://github.com/scanapi/scanapi/pull/172)
 - `--spec-path` option to argument [#172](https://github.com/scanapi/scanapi/pull/172)
 
+### Fixed
+- Duplicated status code row from report [#183](https://github.com/scanapi/scanapi/pull/183)
+- Sensitive information render on report [#183](https://github.com/scanapi/scanapi/pull/183)
+
 ### Removed
 - Console Report [#175](https://github.com/scanapi/scanapi/pull/175)
 - Markdown Report [#179](https://github.com/scanapi/scanapi/pull/179)
diff --git a/scanapi/templates/html.jinja b/scanapi/templates/html.jinja
index 4ba5dc6..ce6ace4 100644
--- a/scanapi/templates/html.jinja
+++ b/scanapi/templates/html.jinja
@@ -311,17 +311,6 @@
                     <section class="endpoint__response">
                         <h3>Response</h3>
                         <table>
-                            <thead>
-                                <tr>
-                                    <td>
-                                        status code
-                                    </td>
-                                    <td>
-                                        {{ response.status_code }}
-                                    </td>
-                                </tr>
-                            </thead>
-
                             <tbody>
                                 <tr>
                                     <td>
diff --git a/scanapi/utils.py b/scanapi/utils.py
index de284e2..67b5e95 100644
--- a/scanapi/utils.py
+++ b/scanapi/utils.py
@@ -56,4 +56,4 @@ def _override_info(http_msg, http_attr, secret_field):
         secret_field in getattr(http_msg, http_attr)
         and http_attr in ALLOWED_ATTRS_TO_HIDE
     ):
-        getattr(http_msg, http_attr)[secret_field] = "<sensitive_information>"
+        getattr(http_msg, http_attr)[secret_field] = "SENSITIVE_INFORMATION"


Test patch:
diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py
index 103328b..c7c7e05 100644
--- a/tests/unit/test_utils.py
+++ b/tests/unit/test_utils.py
@@ -163,7 +163,7 @@ class TestOverrideInfo:
 
         _override_info(response, http_attr, secret_field)
 
-        assert response.headers["abc"] == "<sensitive_information>"
+        assert response.headers["abc"] == "SENSITIVE_INFORMATION"
 
     def test_when_http_attr_is_not_allowed(self, response, mocker):
         mocker.patch("scanapi.utils.ALLOWED_ATTRS_TO_HIDE", ["body"])