Skip to content

Commit

Permalink
Merge pull request #6 from kavigupta/fix-and-automate-tests
Browse files Browse the repository at this point in the history
fix and automate tests
  • Loading branch information
kavigupta authored Feb 13, 2024
2 parents 53ed11a + bf4bc3e commit 0d84efe
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 8 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Python package

on: [push]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest pylint parameterized .
- name: Test with pytest
run: |
pytest tests
- name: Lint with pylint
run: |
# pylint ast_scope setup.py tests
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
download_url="https://github.com/kavigupta/ast_scope/archive/0.3.1.zip",
packages=setuptools.find_packages(exclude=["tests*"]),
classifiers=[
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Operating System :: OS Independent",
],
python_requires=">=3.5",
Expand Down
File renamed without changes.
13 changes: 7 additions & 6 deletions tests/assignment_tests.py → tests/assignment_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ImportAssignmentTests(DisplayAnnotatedTestCase):
def test_global_import(self):
self.assertAnnotationWorks(
"""
import os
import {>=3.10!g}os
{g}def f():
{g}os
"""
Expand All @@ -84,31 +84,32 @@ def test_local_import(self):
self.assertAnnotationWorks(
"""
{g}def f():
import os
import {>=3.10!~f@1:0}os
{~f@1:0}os
"""
)
def test_sub_import(self):
self.assertAnnotationWorks(
"""
{g}def f():
from os import system
from os import {>=3.10!~f@1:0}system
{~f@1:0}system
{g}os
"""
)
def test_star_import(self):
# TODO: no annotation in any version
self.assertAnnotationWorks(
"""
from os import *
from os import {>=3.10!g}*
"""
)
def test_aliases(self):
self.assertAnnotationWorks(
"""
{g}def f():
from os import system as a
import sys as b
from os import {>=3.10!~f@1:0}system as a
import {>=3.10!~f@1:0}sys as b
{g}os
{g}system
{~f@1:0}a
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def all_nodes_gen_for_variables(variables):
yield from variables.functions
yield from variables.classes
yield from variables.import_statements
yield from variables.arguments
yield from variables.exceptions

def all_nodes_gen_for_scope(scope):
if hasattr(scope, 'children'):
Expand All @@ -99,6 +101,14 @@ def _check_nodes(self, mapping, *scopes):
self.assertCountEqual([node for _, node in overall_scope], list(mapping))

def assertAnnotationWorks(self, annotated_code, code=None, *, class_binds_near=False):
# directives of the form {>version!scope} are removed unless the version is satisfied
regex = r"\{>=(\d+\.\d+)!([^\}]+)\}"
def replacer(match):
version, scope = match.groups()
if sys.version_info >= tuple(map(int, version.split("."))):
return "{" + scope + "}"
return ""
annotated_code = re.sub(regex, replacer, annotated_code)
if code is None:
code = trim(re.sub(r"\{[^\}]+\}", "", annotated_code))

Expand Down

0 comments on commit 0d84efe

Please sign in to comment.