Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that token is passed #412

Merged
merged 9 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

name: Pytest

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

on:
push:
branches:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_run.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os
from pathlib import Path
import subprocess
from typing import Any, Dict
Expand All @@ -22,8 +23,7 @@ def test_run_cli_help():
@pytest.fixture
def open_pr_hook_init_for_sop():
hook = OpenPRHook()
hook._token = ""
hook._env = None
hook._token = os.environ.get("GITHUB_TOKEN", "")
hook._data_path = "https://github.com/klieret/swe-agent-test-repo/issues/1"
hook._open_pr = True
hook._skip_if_commits_reference_issue = True
Expand Down
14 changes: 11 additions & 3 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import hashlib
import os
import subprocess
import pytest
from sweagent.environment.utils import InvalidGithubURL, format_trajectory_markdown, _MARKDOWN_TRAJECTORY_EMOJI_MAPPING, get_instances, is_github_repo_url, remove_triple_backticks, parse_gh_repo_url, parse_gh_issue_url, is_github_issue_url, get_associated_commit_urls


_TOKEN = {"token": os.environ.get("GITHUB_TOKEN", "")}

def test_format_trajectory_markdown(test_trajectory):
formatted = format_trajectory_markdown(test_trajectory["trajectory"])
assert formatted.startswith("<details>")
Expand Down Expand Up @@ -63,13 +67,14 @@ def test_get_associated_commit_urls():
assoc = get_associated_commit_urls(
org="princeton-nlp",
repo="SWE-agent",
issue_number="41"
issue_number="41",
token=os.environ.get("GITHUB_TOKEN", "")
)
assert len(assoc) > 0


def test_get_instance_gh_issue():
instance = get_instances("https://github.com/klieret/swe-agent-test-repo/issues/1")[0]
instance = get_instances("https://github.com/klieret/swe-agent-test-repo/issues/1", **_TOKEN)[0]
compare_with = {
'repo': 'klieret/swe-agent-test-repo',
'instance_id': 'klieret__swe-agent-test-repo-i1',
Expand All @@ -92,6 +97,7 @@ def test_get_instance_gh_issue_local_repo(tmp_path):
instance = get_instances(
file_path="https://github.com/klieret/swe-agent-test-repo/issues/1",
repo_path=str(tmp_path / "swe-agent-test-repo"),
**_TOKEN
)[0]
compare_with = {
'repo': str(tmp_path.resolve() / "swe-agent-test-repo"),
Expand Down Expand Up @@ -129,6 +135,7 @@ def test_get_instance_gh_issue_gh_repo(tmp_path):
instance = get_instances(
file_path="https://github.com/klieret/swe-agent-test-repo/issues/1",
repo_path="https://github.com/princeton-nlp/SWE-agent",
**_TOKEN
)[0]
compare_with = {
'repo': "princeton-nlp/SWE-agent",
Expand All @@ -146,6 +153,7 @@ def test_get_instance_text_issue_gh_repo(tmp_path):
instance = get_instances(
file_path="text://this is a test",
repo_path="https://github.com/princeton-nlp/SWE-agent",
**_TOKEN
)[0]
compare_with = {
'repo': "princeton-nlp/SWE-agent",
Expand All @@ -162,4 +170,4 @@ def test_load_instances(test_data_path, caplog):
test_data_sources = test_data_path / "data_sources"
examples = list(test_data_sources.iterdir())
for example in examples:
get_instances(file_path=str(example))
get_instances(file_path=str(example), **_TOKEN)
Loading