Skip to content

Commit

Permalink
Merge pull request #29 from olin/fix-ci
Browse files Browse the repository at this point in the history
Fix CI
  • Loading branch information
newsch authored Apr 15, 2022
2 parents e3d468a + dd230ec commit 6fadde2
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 73 deletions.
46 changes: 29 additions & 17 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,44 @@
name: Python package
# mash-up of matrix and pipenv examples from <https://github.com/actions/setup-python#usage>
name: Test

on:
push:
branches: [master]
pull_request:
types: [opened, synchronize, reopened] # default events

on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest
strategy:
max-parallel: 4
fail-fast: false # prevent one broken version from stopping all other runs
matrix:
python-version: [3.5, 3.6, 3.7, 3.8]

# these will be out of date again eventually, add the latest versions
# and remove the unsupported ones
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
name: Python ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
- uses: actions/checkout@v3
- name: Install pipenv
run: pipx install pipenv
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
architecture: x64
cache: 'pipenv'
- name: Install dependencies
run: |
pip install pipenv
pipenv install --dev
run: pipenv install --dev
- name: Lint with flake8
run: pipenv run flake8 *.py
continue-on-error: true
- name: Typecheck with mypy
run: pipenv run mypy *.py
- name: Test with unittest
run: |
pipenv run python -m unittest discover -v
- name: Install with pip
run: |
pip install .
run: pipenv run python -m unittest discover -v
- name: Install as package with pip
run: pip install .
- name: Run installed version
run: |
focstest --version
5 changes: 5 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ termcolor = "*"

[dev-packages]
"flake8" = "*"
mypy = "*"
types-setuptools = "*"
types-beautifulsoup4 = "*"
types-requests = "*"
types-termcolor = "*"
174 changes: 131 additions & 43 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 15 additions & 10 deletions focstest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@


# default url matching
BASE_URL = "http://rpucella.net/courses/focs-fa20/homeworks/" # website and path to look under
OCAML_FILE_PATTERN = "homework(\d{1,2}).ml" # pattern to pass the user-given ocaml file
BASE_URL = "http://rpucella.net/courses/focs-fa20/homeworks/" # default website and path to fetch from
OCAML_FILE_PATTERN = r"homework(\d{1,2}).ml" # pattern to extract homework number from the user-given ocaml file
HTML_FILE_TEMPLATE = "homework{}.html" # template to build the html filename given a homework number

# selectors for parsing html
CODE_BLOCK_SELECTOR = 'pre code' # css selector to get code blocks

# regex patterns for parsing text
TEST_PATTERN = "^(.+;;)\n(.*)$" # pattern to get input and output
OCAML_PATTERN = "^(.*)" # pattern to grab output of lines
TEST_PATTERN = r"^(.+;;)\n(.*)$" # pattern to get input and output
OCAML_PATTERN = r"^(.*)" # pattern to grab output of lines

# compile regexes ahead of time
OCAML_FILE_COMP = re.compile(OCAML_FILE_PATTERN)
Expand All @@ -55,8 +55,7 @@ def get_blocks(html):
page = BeautifulSoup(html, 'html.parser')
code_blocks = page.select(CODE_BLOCK_SELECTOR)
if len(code_blocks) == 0:
logger.error('Code block selector {!r} returned no matches'.format(
CODE_BLOCK_SELECTOR))
logger.error('Code block selector {!r} returned no matches'.format(CODE_BLOCK_SELECTOR))
return [block.get_text() for block in code_blocks]


Expand All @@ -72,7 +71,8 @@ def get_test(text):
for test_str in test_strs:
test = get_test(test_str)
if test is None:
logger.error('Test/response pattern {!r} returned no matches from string {!r}'.format(TEST_PATTERN, test_str))
logger.error(
'Test/response pattern {!r} returned no matches from string {!r}'.format(TEST_PATTERN, test_str))
else:
tests.append((test.group(1).strip(), test.group(2).strip()))
return tests
Expand Down Expand Up @@ -103,9 +103,11 @@ def _run_ocaml_code(code):
def equivalent(text):
return text


def strip_whitespace(text):
return text.strip()


def normalize_whitespace(text):
"""Replace instances of whitespace with ' '.
Expand Down Expand Up @@ -229,7 +231,9 @@ def main():
if not args.url:
url_guess = infer_url(FILE)
if not url_guess: # break if filename can't be matched
logger.critical('Could not infer url from filename {!r}. Try passing a url manually with the `--url` flag.'.format(FILE))
logger.critical((
'Could not infer url from filename {!r}. '
'Try passing a url manually with the `--url` flag.').format(FILE))
sys.exit(1)
else:
URL = url_guess
Expand Down Expand Up @@ -266,7 +270,8 @@ def main():
# TODO: get titles/descriptions from code blocks
blocks = get_blocks(html)
# parse code blocks for tests
test_suites = list(enumerate(filter(None, (get_tests(b) for b in blocks)), 1)) # list of suites and indices (starting at 1) (skipping empty suites)
# list of suites and indices (starting at 1) (skipping empty suites)
test_suites = list(enumerate(filter(None, (get_tests(b) for b in blocks)), 1))
num_tests = sum([len(suite) for j, suite in test_suites])
logger.info("Found {} test suites and {} tests total".format(
len(test_suites), num_tests))
Expand Down Expand Up @@ -300,7 +305,7 @@ def main():
res = run_test(test, expected_output, file=FILE)
header_temp = ' test {} of {} in suite {}'.format(k+1, len(suite), j)
if res is None: # skip unparsable texts
print(colored('Skipped'+header_temp+': Unable to parse output','yellow'))
print(colored('Skipped'+header_temp+': Unable to parse output', 'yellow'))
continue
else:
result, output, method = res
Expand Down
Loading

0 comments on commit 6fadde2

Please sign in to comment.