Skip to content

Commit

Permalink
Fix open source unit tests (#43)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #43

We were adding an extra "fixtures" directory for fixture paths in TARGETS. Pathing doesn't work like that for standard python imports, so remove this extra level. Also consolidate the two read_fixture() definitions into a single place

Reviewed By: chantra

Differential Revision: D58969097

fbshipit-source-id: 5dd8b08e5590f1690a7588179cd2832b6d6502fc
  • Loading branch information
Daniel Xu authored and facebook-github-bot committed Jun 26, 2024
1 parent c5a4ff6 commit 5714ecf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
12 changes: 12 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

# pyre-strict

import importlib.resources
import logging

logging.disable()


def read_fixture(filepath: str) -> str:
return (
importlib.resources.files(__package__)
.joinpath("fixtures")
.joinpath(filepath)
.read_text()
)
10 changes: 2 additions & 8 deletions tests/test_branch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

# pyre-unsafe

import importlib.resources
import os
import random
import re
import shutil
Expand Down Expand Up @@ -51,6 +49,8 @@
init_pw_responses,
)

from . import read_fixture


TEST_REPO = "repo"
TEST_REPO_URL = f"https://user:[email protected]:0/org/{TEST_REPO}"
Expand Down Expand Up @@ -104,12 +104,6 @@
}


def read_fixture(filepath: str) -> str:
with importlib.resources.path(__package__, "fixtures") as base:
with open(os.path.join(base, "fixtures", filepath)) as f:
return f.read()


class BranchWorkerMock(BranchWorker):
def __init__(self, *args: Any, **kwargs: Any) -> None:
presets = {
Expand Down
8 changes: 1 addition & 7 deletions tests/test_github_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,14 @@

# pyre-unsafe

import importlib.resources
import os
import unittest

from aioresponses import aioresponses
from github.WorkflowJob import WorkflowJob

from kernel_patches_daemon.github_logs import BpfGithubLogExtractor, GithubFailedJobLog


def read_fixture(filepath: str) -> str:
with importlib.resources.path(__package__, "fixtures") as base:
with open(os.path.join(base, "fixtures", filepath)) as f:
return f.read()
from . import read_fixture


class MockWorkflowJob(WorkflowJob):
Expand Down

0 comments on commit 5714ecf

Please sign in to comment.