nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: GoogleCloudPlatform/functions-framework-python
Pull request #259 (2023-07-10 22:03:45)

fix: reduce gunicorn concurrency to at most 4 * maximum available cor…
Updates gunicorn's multithreading logic to derive the maximum concurrency the container can handle from the number of cores available to the functon. 4 invocations per core (given that memory additionally scales with cores) will be a good default concurrency limit that most functions will support without running into resource problems.


Patch:
diff --git a/src/functions_framework/_http/gunicorn.py b/src/functions_framework/_http/gunicorn.py
index f522b67..3a9c545 100644
--- a/src/functions_framework/_http/gunicorn.py
+++ b/src/functions_framework/_http/gunicorn.py
@@ -12,6 +12,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import os
+
 import gunicorn.app.base
 
 
@@ -20,7 +22,7 @@ class GunicornApplication(gunicorn.app.base.BaseApplication):
         self.options = {
             "bind": "%s:%s" % (host, port),
             "workers": 1,
-            "threads": 1024,
+            "threads": (os.cpu_count() or 1) * 4,
             "timeout": 0,
             "loglevel": "error",
             "limit_request_line": 0,


Test patch:
diff --git a/tests/test_http.py b/tests/test_http.py
index 3414aaf..fbfac9d 100644
--- a/tests/test_http.py
+++ b/tests/test_http.py
@@ -12,6 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import os
 import platform
 import sys
 
@@ -97,7 +98,7 @@ def test_gunicorn_application(debug):
     assert gunicorn_app.options == {
         "bind": "%s:%s" % (host, port),
         "workers": 1,
-        "threads": 1024,
+        "threads": os.cpu_count() * 4,
         "timeout": 0,
         "loglevel": "error",
         "limit_request_line": 0,
@@ -105,7 +106,7 @@ def test_gunicorn_application(debug):
 
     assert gunicorn_app.cfg.bind == ["1.2.3.4:1234"]
     assert gunicorn_app.cfg.workers == 1
-    assert gunicorn_app.cfg.threads == 1024
+    assert gunicorn_app.cfg.threads == os.cpu_count() * 4
     assert gunicorn_app.cfg.timeout == 0
     assert gunicorn_app.load() == app
Repository: GoogleCloudPlatform/functions-framework-python
Pull request #326 (2024-05-16 14:58:10)

feat: restore gunicorn worker default configs from 3.5.0
<!--

Before submitting a pull request:

Contributions to this project must be accompanied by a Contributor License Agreement. You (or your employer) retain the copyright to your contribution; this simply gives us permission to use and redistribute your contributions as part of the project.

Head over to https://cla.developers.google.com/ to see your current agreements on file or to sign a new one.

You generally only need to submit a CLA once, so if you've already submitted one (even if it was for a different project), you probably don't need to do it again.

-->



Patch:
diff --git a/src/functions_framework/_http/gunicorn.py b/src/functions_framework/_http/gunicorn.py
index 009a06b..050f766 100644
--- a/src/functions_framework/_http/gunicorn.py
+++ b/src/functions_framework/_http/gunicorn.py
@@ -21,9 +21,9 @@ class GunicornApplication(gunicorn.app.base.BaseApplication):
     def __init__(self, app, host, port, debug, **options):
         self.options = {
             "bind": "%s:%s" % (host, port),
-            "workers": os.environ.get("WORKERS", (os.cpu_count() or 1) * 4),
-            "threads": os.environ.get("THREADS", 1),
-            "timeout": os.environ.get("CLOUD_RUN_TIMEOUT_SECONDS", 300),
+            "workers": os.environ.get("WORKERS", 1),
+            "threads": os.environ.get("THREADS", (os.cpu_count() or 1) * 4),
+            "timeout": os.environ.get("CLOUD_RUN_TIMEOUT_SECONDS", 0),
             "loglevel": "error",
             "limit_request_line": 0,
         }


Test patch:
diff --git a/tests/test_http.py b/tests/test_http.py
index 0a46fbe..fbfac9d 100644
--- a/tests/test_http.py
+++ b/tests/test_http.py
@@ -97,17 +97,17 @@ def test_gunicorn_application(debug):
     assert gunicorn_app.app == app
     assert gunicorn_app.options == {
         "bind": "%s:%s" % (host, port),
-        "workers": os.cpu_count() * 4,
-        "threads": 1,
-        "timeout": 300,
+        "workers": 1,
+        "threads": os.cpu_count() * 4,
+        "timeout": 0,
         "loglevel": "error",
         "limit_request_line": 0,
     }
 
     assert gunicorn_app.cfg.bind == ["1.2.3.4:1234"]
-    assert gunicorn_app.cfg.workers == os.cpu_count() * 4
-    assert gunicorn_app.cfg.threads == 1
-    assert gunicorn_app.cfg.timeout == 300
+    assert gunicorn_app.cfg.workers == 1
+    assert gunicorn_app.cfg.threads == os.cpu_count() * 4
+    assert gunicorn_app.cfg.timeout == 0
     assert gunicorn_app.load() == app
Repository: CTFd/CTFd
Pull request #271 (2017-06-05 06:36:15)

Give ip2long and long2ip ipv6 support
And has tests


Patch:
diff --git a/CTFd/models.py b/CTFd/models.py
index 4befa17c..daab74f2 100644
--- a/CTFd/models.py
+++ b/CTFd/models.py
@@ -1,7 +1,7 @@
 import datetime
 import hashlib
 import json
-from socket import inet_aton, inet_ntoa
+from socket import inet_pton, inet_ntop, AF_INET, AF_INET6
 from struct import unpack, pack, error as struct_error
 
 from flask_sqlalchemy import SQLAlchemy
@@ -14,15 +14,24 @@ def sha512(string):
 
 
 def ip2long(ip):
-    return unpack('!i', inet_aton(ip))[0]
+    '''Converts a user's IP address into an integer/long'''
+    if '.' in ip:
+        # ipv4
+        return unpack('!i', inet_pton(AF_INET, ip))[0]
+    else:
+        # ipv6
+        hi, lo = unpack('!QQ', inet_pton(AF_INET6, ip))
+        return (hi << 64) | lo
 
 
 def long2ip(ip_int):
-    try:
-        return inet_ntoa(pack('!i', ip_int))
-    except struct_error:
-        # Backwards compatibility with old CTFd databases
-        return inet_ntoa(pack('!I', ip_int))
+    '''Converts a saved IP address back into an integer/long'''
+    if ip_int < 4294967296:
+        # ipv4
+        return inet_ntop(AF_INET, pack('!i', ip_int))
+    else:
+        # ipv6
+        return inet_ntop(AF_INET6, pack('!QQ', ip_int >> 64, ip_int & 0xffffffffffffffff))
 
 
 db = SQLAlchemy()


Test patch:
diff --git a/tests/test_utils.py b/tests/test_utils.py
index e69de29b..dd2e5407 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+from tests.helpers import *
+from CTFd.models import ip2long, long2ip
+import json
+
+
+def test_ip2long_ipv4():
+    """Does ip2long work properly for ipv4 addresses"""
+    assert ip2long('127.0.0.1') == 2130706433
+
+
+def test_long2ip_ipv4():
+    """Does long2ip work properly for ipv4 addresses"""
+    assert long2ip(2130706433) == '127.0.0.1'
+
+
+def test_ip2long_ipv6():
+    """Does ip2long work properly for ipv6 addresses"""
+    assert ip2long('2001:0db8:85a3:0000:0000:8a2e:0370:7334') == 42540766452641154071740215577757643572
+    assert ip2long('2001:658:22a:cafe:200::1') == 42540616829182469433547762482097946625
+
+
+def test_long2ip_ipv6():
+    """Does long2ip work properly for ipv6 addresses"""
+    assert long2ip(42540766452641154071740215577757643572) == '2001:db8:85a3::8a2e:370:7334'
+    assert long2ip(42540616829182469433547762482097946625) == '2001:658:22a:cafe:200::1'
Repository: CTFd/CTFd
Pull request #413 (2017-10-15 19:10:51)

Create a private team endpoint
Creates a private team endpoint that doesn't disclose IDs 


Patch:
diff --git a/CTFd/themes/original/static/js/team.js b/CTFd/themes/original/static/js/team.js
index 0087bd70..5e531ef6 100644
--- a/CTFd/themes/original/static/js/team.js
+++ b/CTFd/themes/original/static/js/team.js
@@ -1,6 +1,5 @@
 function teamid (){
-    loc = window.location.pathname
-    return loc.substring(loc.lastIndexOf('/')+1, loc.length);
+    return $('#team-id').attr('team-id');
 }
 
 function colorhash (x) {
diff --git a/CTFd/themes/original/templates/team.html b/CTFd/themes/original/templates/team.html
index 92f3da4a..28d278a4 100644
--- a/CTFd/themes/original/templates/team.html
+++ b/CTFd/themes/original/templates/team.html
@@ -6,7 +6,7 @@
 {% block content %}
 <div class="jumbotron home">
 	<div class="container">
-		<h1 id="team-id">{{ team.name }}</h1>
+		<h1 id="team-id" team-id="{{ team.id }}">{{ team.name }}</h1>
 	</div>
 </div>
 <div class="container main-container">
diff --git a/CTFd/views.py b/CTFd/views.py
index 915dc728..5f8bb91c 100644
--- a/CTFd/views.py
+++ b/CTFd/views.py
@@ -135,6 +135,33 @@ def teams(page):
     return render_template('teams.html', teams=teams, team_pages=pages, curr_page=page)
 
 
+@views.route('/team', methods=['GET'])
+def private_team():
+    if utils.authed():
+        teamid = session['id']
+
+        freeze = utils.get_config('freeze')
+        user = Teams.query.filter_by(id=teamid).first_or_404()
+        solves = Solves.query.filter_by(teamid=teamid)
+        awards = Awards.query.filter_by(teamid=teamid)
+
+        place = user.place()
+        score = user.score()
+
+        if freeze:
+            freeze = utils.unix_time_to_utc(freeze)
+            if teamid != session.get('id'):
+                solves = solves.filter(Solves.date < freeze)
+                awards = awards.filter(Awards.date < freeze)
+
+        solves = solves.all()
+        awards = awards.all()
+
+        return render_template('team.html', solves=solves, awards=awards, team=user, score=score, place=place, score_frozen=utils.is_scoreboard_frozen())
+    else:
+        return redirect(url_for('auth.login'))
+
+
 @views.route('/team/<int:teamid>', methods=['GET', 'POST'])
 def team(teamid):
     if utils.get_config('view_scoreboard_if_utils.authed') and not utils.authed():


Test patch:
diff --git a/tests/user/test_user_facing.py b/tests/user/test_user_facing.py
index f352e00b..3fc9171d 100644
--- a/tests/user/test_user_facing.py
+++ b/tests/user/test_user_facing.py
@@ -174,6 +174,17 @@ def test_user_get_team_page():
     destroy_ctfd(app)
 
 
+def test_user_get_private_team_page():
+    """Can a registered user load their private team page (/team)"""
+    app = create_ctfd()
+    with app.app_context():
+        register_user(app)
+        client = login_as_user(app)
+        r = client.get('/team')
+        assert r.status_code == 200
+    destroy_ctfd(app)
+
+
 def test_user_get_profile():
     """Can a registered user load their private profile (/profile)"""
     app = create_ctfd()
Repository: CTFd/CTFd
Pull request #538 (2017-12-22 20:05:52)

Guarantee ctf version
Make sure that `ctf_version` is set in the config values. 

codecov[bot]: # [Codecov](https://codecov.io/gh/CTFd/CTFd/pull/538?src=pr&el=h1) Report
> Merging [#538](https://codecov.io/gh/CTFd/CTFd/pull/538?src=pr&el=desc) into [master](https://codecov.io/gh/CTFd/CTFd/commit/7e5e18fd6e4bc241daf42a67a2941dec68b441b5?src=pr&el=desc) will **increase** coverage by `0.02%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/CTFd/CTFd/pull/538/graphs/tree.svg?token=IfPqkWkt9A&src=pr&height=150&width=650)](https://codecov.io/gh/CTFd/CTFd/pull/538?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #538      +/-   ##
==========================================
+ Coverage   72.32%   72.34%   +0.02%     
==========================================
  Files          18       18              
  Lines        2670     2672       +2     
==========================================
+ Hits         1931     1933       +2     
  Misses        739      739
```


| [Impacted Files](https://codecov.io/gh/CTFd/CTFd/pull/538?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [CTFd/\_\_init\_\_.py](https://codecov.io/gh/CTFd/CTFd/pull/538/diff?src=pr&el=tree#diff-Q1RGZC9fX2luaXRfXy5weQ==) | `84.87% <100%> (+0.25%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/CTFd/CTFd/pull/538?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/CTFd/CTFd/pull/538?src=pr&el=footer). Last update [7e5e18f...9d2987f](https://codecov.io/gh/CTFd/CTFd/pull/538?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c445ab44..38a5af81 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,4 @@
-1.1.0 / TBD
+1.1.0 / 2017-12-22
 ==================
 
 **Themes**
diff --git a/CTFd/__init__.py b/CTFd/__init__.py
index bc29e5b4..e0ee3c68 100644
--- a/CTFd/__init__.py
+++ b/CTFd/__init__.py
@@ -150,6 +150,9 @@ def create_app(config='CTFd.config.Config'):
             else:
                 exit()
 
+        if not version:
+            utils.set_config('ctf_version', __version__)
+
         if not utils.get_config('ctf_theme'):
             utils.set_config('ctf_theme', 'core')
 


Test patch:
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 6425085a..ee263612 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -17,6 +17,14 @@ import requests
 import six
 
 
+def test_ctf_version_is_set():
+    """Does ctf_version get set correctly"""
+    app = create_ctfd()
+    with app.app_context():
+        assert get_config('ctf_version') == app.VERSION
+    destroy_ctfd(app)
+
+
 def test_get_config_and_set_config():
     """Does get_config and set_config work properly"""
     app = create_ctfd()
Repository: GoogleCloudPlatform/google-auth-library-python
Pull request #23 (2016-10-14 21:40:45)

Add copy_docstring helper


Patch:
diff --git a/google/auth/_helpers.py b/google/auth/_helpers.py
index 9c49e06..9fe2caa 100644
--- a/google/auth/_helpers.py
+++ b/google/auth/_helpers.py
@@ -21,6 +21,20 @@ import six
 from six.moves import urllib
 
 
+def copy_docstring(source_class):
+    """Decorator that copies a method's docstring from another class."""
+    def decorator(method):
+        """Decorator implementation."""
+        if method.__doc__:
+            raise ValueError('Method already has a docstring.')
+
+        source_method = getattr(source_class, method.__name__)
+        method.__doc__ = source_method.__doc__
+
+        return method
+    return decorator
+
+
 def utcnow():
     """Returns the current UTC datetime.
 


Test patch:
diff --git a/tests/test__helpers.py b/tests/test__helpers.py
index 86cacef..35c16d4 100644
--- a/tests/test__helpers.py
+++ b/tests/test__helpers.py
@@ -20,6 +20,38 @@ from six.moves import urllib
 from google.auth import _helpers
 
 
+class SourceClass(object):
+    def func(self):  # pragma: NO COVER
+        """example docstring"""
+        pass
+
+
+def test_copy_docstring_success():
+    def func():  # pragma: NO COVER
+        pass
+
+    _helpers.copy_docstring(SourceClass)(func)
+
+    assert func.__doc__ == SourceClass.func.__doc__
+
+
+def test_copy_docstring_conflict():
+    def func():  # pragma: NO COVER
+        """existing docstring"""
+        pass
+
+    with pytest.raises(ValueError):
+        _helpers.copy_docstring(SourceClass)(func)
+
+
+def test_copy_docstring_non_existing():
+    def func2():  # pragma: NO COVER
+        pass
+
+    with pytest.raises(AttributeError):
+        _helpers.copy_docstring(SourceClass)(func2)
+
+
 def test_utcnow():
     assert isinstance(_helpers.utcnow(), datetime.datetime)
Repository: GoogleCloudPlatform/google-auth-library-python
Pull request #65 (2016-10-31 17:40:53)

Add with_scopes_if_required helper
This will make it easy to remove some code / branches in google-cloud-python.


Patch:
diff --git a/google/auth/credentials.py b/google/auth/credentials.py
index ef28bd7..59d4ffe 100644
--- a/google/auth/credentials.py
+++ b/google/auth/credentials.py
@@ -186,6 +186,30 @@ class Scoped(object):
         return set(scopes).issubset(set(self._scopes or []))
 
 
+def with_scopes_if_required(credentials, scopes):
+    """Creates a copy of the credentials with scopes if scoping is required.
+
+    This helper function is useful when you do not know (or care to know) the
+    specific type of credentials you are using (such as when you use
+    :func:`google.auth.default`). This function will call
+    :meth:`Scoped.with_scopes` if the credentials are scoped credentials and if
+    the credentials require scoping. Otherwise, it will return the credentials
+    as-is.
+
+    Args:
+        credentials (Credentials): The credentials to scope if necessary.
+        scopes (Sequence[str]): The list of scopes to use.
+
+    Returns:
+        Credentials: Either a new set of scoped credentials, or the passed in
+            credentials instance if no scoping was required.
+    """
+    if isinstance(credentials, Scoped) and credentials.requires_scopes:
+        return credentials.with_scopes(scopes)
+    else:
+        return credentials
+
+
 @six.add_metaclass(abc.ABCMeta)
 class Signing(object):
     """Interface for credentials that can cryptographically sign messages."""


Test patch:
diff --git a/tests/test_credentials.py b/tests/test_credentials.py
index d78c554..814369e 100644
--- a/tests/test_credentials.py
+++ b/tests/test_credentials.py
@@ -92,3 +92,34 @@ def test_scoped_credentials_scopes():
 def test_scoped_credentials_requires_scopes():
     credentials = ScopedCredentialsImpl()
     assert not credentials.requires_scopes
+
+
+class RequiresScopedCredentialsImpl(credentials.Scoped, CredentialsImpl):
+    def __init__(self, scopes=None):
+        super(RequiresScopedCredentialsImpl, self).__init__()
+        self._scopes = scopes
+
+    @property
+    def requires_scopes(self):
+        return not self.scopes
+
+    def with_scopes(self, scopes):
+        return RequiresScopedCredentialsImpl(scopes=scopes)
+
+
+def test_create_scoped_if_required_scoped():
+    unscoped_credentials = RequiresScopedCredentialsImpl()
+    scoped_credentials = credentials.with_scopes_if_required(
+        unscoped_credentials, ['one', 'two'])
+
+    assert scoped_credentials is not unscoped_credentials
+    assert not scoped_credentials.requires_scopes
+    assert scoped_credentials.has_scopes(['one', 'two'])
+
+
+def test_create_scoped_if_required_not_scopes():
+    unscoped_credentials = CredentialsImpl()
+    scoped_credentials = credentials.with_scopes_if_required(
+        unscoped_credentials, ['one', 'two'])
+
+    assert scoped_credentials is unscoped_credentials
Repository: GoogleCloudPlatform/google-auth-library-python
Pull request #124 (2017-03-01 03:56:11)

Add public properties to google.oauth2.credentials.Credentials
Resolves #124 


Patch:
diff --git a/google/oauth2/credentials.py b/google/oauth2/credentials.py
index 9727e18..077a95f 100644
--- a/google/oauth2/credentials.py
+++ b/google/oauth2/credentials.py
@@ -68,6 +68,27 @@ class Credentials(credentials.Scoped, credentials.Credentials):
         self._client_id = client_id
         self._client_secret = client_secret
 
+    @property
+    def refresh_token(self):
+        """Optional[str]: The OAuth 2.0 refresh token."""
+        return self._refresh_token
+
+    @property
+    def token_uri(self):
+        """Optional[str]: The OAuth 2.0 authorization server's token endpoint
+        URI."""
+        return self._token_uri
+
+    @property
+    def client_id(self):
+        """Optional[str]: The OAuth 2.0 client ID."""
+        return self._client_id
+
+    @property
+    def client_secret(self):
+        """Optional[str]: The OAuth 2.0 client secret."""
+        return self._client_secret
+
     @property
     def requires_scopes(self):
         """False: OAuth 2.0 credentials have their scopes set when


Test patch:
diff --git a/tests/oauth2/test_credentials.py b/tests/oauth2/test_credentials.py
index b53b188..fa86a16 100644
--- a/tests/oauth2/test_credentials.py
+++ b/tests/oauth2/test_credentials.py
@@ -41,6 +41,11 @@ class TestCredentials(object):
         assert not self.credentials.expired
         # Scopes aren't required for these credentials
         assert not self.credentials.requires_scopes
+        # Test properties
+        assert self.credentials.refresh_token == self.REFRESH_TOKEN
+        assert self.credentials.token_uri == self.TOKEN_URI
+        assert self.credentials.client_id == self.CLIENT_ID
+        assert self.credentials.client_secret == self.CLIENT_SECRET
 
     def test_create_scoped(self):
         with pytest.raises(NotImplementedError):
Repository: GoogleCloudPlatform/google-auth-library-python
Pull request #179 (2017-08-01 13:44:27)

Fix retrieval of default project ID on Windows
- Fix for shell command call "subprocess.check_output(_CLOUD_SDK_CONFIG_COMMAND...)".
- Previously, it would trigger an error "WindowsError: [Error 2] The system cannot find the file specified". A workaround was to specify the env variable GCLOUD_PROJECT.
- With this patch, "gcloud" default project is successfully retrieved.

jonparrott: Thanks, @PicardParis. I made a few changes and added a test. :)

Patch:
diff --git a/google/auth/_cloud_sdk.py b/google/auth/_cloud_sdk.py
index 428b612..898c6ec 100644
--- a/google/auth/_cloud_sdk.py
+++ b/google/auth/_cloud_sdk.py
@@ -33,9 +33,11 @@ _WINDOWS_CONFIG_ROOT_ENV_VAR = 'APPDATA'
 # The name of the file in the Cloud SDK config that contains default
 # credentials.
 _CREDENTIALS_FILENAME = 'application_default_credentials.json'
+# The name of the Cloud SDK shell script
+_CLOUD_SDK_POSIX_COMMAND = 'gcloud'
+_CLOUD_SDK_WINDOWS_COMMAND = 'gcloud.cmd'
 # The command to get the Cloud SDK configuration
-_CLOUD_SDK_CONFIG_COMMAND = (
-    'gcloud', 'config', 'config-helper', '--format', 'json')
+_CLOUD_SDK_CONFIG_COMMAND = ('config', 'config-helper', '--format', 'json')
 
 
 def get_config_path():
@@ -114,10 +116,14 @@ def get_project_id():
     Returns:
         Optional[str]: The project ID.
     """
+    if os.name == 'nt':
+        command = _CLOUD_SDK_WINDOWS_COMMAND
+    else:
+        command = _CLOUD_SDK_POSIX_COMMAND
 
     try:
         output = subprocess.check_output(
-            _CLOUD_SDK_CONFIG_COMMAND,
+            (command,) + _CLOUD_SDK_CONFIG_COMMAND,
             stderr=subprocess.STDOUT)
     except (subprocess.CalledProcessError, OSError, IOError):
         return None


Test patch:
diff --git a/tests/test__cloud_sdk.py b/tests/test__cloud_sdk.py
index 6e92ca6..c14fc20 100644
--- a/tests/test__cloud_sdk.py
+++ b/tests/test__cloud_sdk.py
@@ -65,6 +65,24 @@ def test_get_project_id_call_error(check_output):
     assert check_output.called
 
 
+@mock.patch('os.name', new='nt')
+def test_get_project_id_windows():
+    check_output_patch = mock.patch(
+        'subprocess.check_output', autospec=True,
+        return_value=CLOUD_SDK_CONFIG_FILE_DATA)
+
+    with check_output_patch as check_output:
+        project_id = _cloud_sdk.get_project_id()
+
+    assert project_id == 'example-project'
+    assert check_output.called
+    # Make sure the executable is `gcloud.cmd`.
+    args = check_output.call_args[0]
+    command = args[0]
+    executable = command[0]
+    assert executable == 'gcloud.cmd'
+
+
 @mock.patch(
     'google.auth._cloud_sdk.get_config_path', autospec=True)
 def test_get_application_default_credentials_path(get_config_dir):