From 099e5067f78c6767ee34cf177b97e16efba69cd3 Mon Sep 17 00:00:00 2001 From: Ignacio Calderon Date: Mon, 19 Aug 2024 14:04:14 +0200 Subject: [PATCH] make the test fixtures agnostic from the invocation path --- .github/workflows/branch-check.yml | 10 +++++----- .github/workflows/publish.yml | 7 +++---- Makefile | 10 +++++----- pytest.ini | 3 ++- tests/TestParsing.py | 14 +++++++++----- tests/pytest.ini | 3 --- 6 files changed, 24 insertions(+), 23 deletions(-) delete mode 100644 tests/pytest.ini diff --git a/.github/workflows/branch-check.yml b/.github/workflows/branch-check.yml index 0e75628..e5c1c0d 100644 --- a/.github/workflows/branch-check.yml +++ b/.github/workflows/branch-check.yml @@ -18,11 +18,11 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 id: checkout - name: Setup - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python }} @@ -34,7 +34,7 @@ jobs: - name: SonarCloud Scan uses: SonarSource/sonarcloud-github-action@master - if: github.event_name == 'pull_request' && matrix.python == '3.x' + if: github.event_name == 'pull_request' && matrix.python == '3.x' && github.event.pull_request.head.repo.full_name != github.repository with: args: > -Dsonar.projectVersion=${{ env.VERSION }} @@ -58,7 +58,7 @@ jobs: - name: SonarCloud Scan uses: SonarSource/sonarcloud-github-action@master - if: github.event_name == 'push' && matrix.python == '3.x' + if: github.event_name == 'push' && matrix.python == '3.x' && github.event.pull_request.head.repo.full_name != github.repository with: args: > -Dsonar.projectVersion=${{ env.VERSION }} @@ -76,4 +76,4 @@ jobs: -Dsonar.objc.file.suffixes=- env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c7ac16f..166670a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -10,11 +10,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 - id: checkout + uses: actions/checkout@v4 - name: Setup - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: '3.x' @@ -29,4 +28,4 @@ jobs: twine upload dist/* env: TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - TWINE_USERNAME: kronenthaler \ No newline at end of file + TWINE_USERNAME: kronenthaler diff --git a/Makefile b/Makefile index cfd589b..d003eab 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,15 @@ .PHONY: coverage coverage-term test install-dependencies coverage: install-dependencies - cd tests; pytest --cov-report=xml --cov=../ --cov-branch - cd tests; rm -rf .coverage + pytest --cov-report=xml --cov=../ --cov-branch + rm -rf .coverage coverage-term: install-dependencies - cd tests; pytest --cov-report=term --cov=../ --cov-branch - cd tests; rm -rf .coverage + pytest --cov-report=term --cov=../ --cov-branch + rm -rf .coverage test: - cd tests; pytest + pytest install-dependencies: pip3 install -r dev-requirements.txt diff --git a/pytest.ini b/pytest.ini index bd165df..b513e88 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,3 +1,4 @@ [pytest] python_files = Test*.py -pythonpath = . \ No newline at end of file +pythonpath = . +testpaths = tests diff --git a/tests/TestParsing.py b/tests/TestParsing.py index 4e985a1..715c11f 100644 --- a/tests/TestParsing.py +++ b/tests/TestParsing.py @@ -23,35 +23,39 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +import os +from os.path import join import unittest from openstep_parser import openstep_parser as osp class ParsingTest(unittest.TestCase): + PWD = os.path.dirname(os.path.abspath(__file__)) + def testParseNestedDictionary(self): line = '''{ a = { b = b1; }; };''' result = osp.OpenStepDecoder()._parse_dictionary(line, 0) assert result def testParseFileSample1(self): - result = osp.OpenStepDecoder.ParseFromFile(open('samples/music-cube.pbxproj')) + result = osp.OpenStepDecoder.ParseFromFile(open(join(self.PWD, 'samples/music-cube.pbxproj'))) assert result def testParseFileSample2(self): - result = osp.OpenStepDecoder.ParseFromFile(open('samples/cloud-search.pbxproj')) + result = osp.OpenStepDecoder.ParseFromFile(open(join(self.PWD, 'samples/cloud-search.pbxproj'))) assert result def testParseFileSample3(self): - result = osp.OpenStepDecoder.ParseFromFile(open('samples/collection-view.pbxproj')) + result = osp.OpenStepDecoder.ParseFromFile(open(join(self.PWD, 'samples/collection-view.pbxproj'))) assert result def testParseFileSample4(self): - result = osp.OpenStepDecoder.ParseFromFile(open('samples/metal-image-processing.pbxproj')) + result = osp.OpenStepDecoder.ParseFromFile(open(join(self.PWD, 'samples/metal-image-processing.pbxproj'))) assert result def testParseFileSample5(self): - result = osp.OpenStepDecoder.ParseFromFile(open('samples/no_whitespace.pbxproj')) + result = osp.OpenStepDecoder.ParseFromFile(open(join(self.PWD, 'samples/no_whitespace.pbxproj'))) assert result def testIgnoreWhitespacesFromBeginning(self): diff --git a/tests/pytest.ini b/tests/pytest.ini deleted file mode 100644 index 95ec019..0000000 --- a/tests/pytest.ini +++ /dev/null @@ -1,3 +0,0 @@ -[pytest] -python_files = Test*.py -pythonpath = .. \ No newline at end of file