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

refactor: make tests agnostic from the running path #358

Merged
merged 1 commit into from
Aug 19, 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
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ jobs:
python setup.py sdist bdist_wheel
twine upload dist/*
env:
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion tests/pytest.ini → pytest.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[pytest]
python_files = Test*.py
pythonpath = ..
pythonpath = .
testpaths = tests
6 changes: 5 additions & 1 deletion tests/TestXCodeProject.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import unittest

from pbxproj import XcodeProject
from os.path import join
import re


Expand Down Expand Up @@ -37,13 +38,17 @@ def setUp(self):
}
}

self.pwd = os.getcwd()
os.chdir(os.path.dirname(os.path.abspath(__file__)))

# create tmp directory for results
if not os.path.exists("results"):
os.mkdir("results")

def tearDown(self):
# remove tmp directory
shutil.rmtree('results')
os.chdir(self.pwd)

def testSaveOnGivenPath(self):
XcodeProject().save("results/sample")
Expand Down Expand Up @@ -112,4 +117,3 @@ def testConsistency(self):
saved = project.__repr__() + '\n'

assert saved == original

8 changes: 6 additions & 2 deletions tests/pbxcli/TestPBXCLI.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@

from pbxproj import XcodeProject
from pbxproj.pbxcli import open_project, resolve_backup, backup_project, command_parser, PROJECT_PLACEHOLDER
from tests.pbxcli import BASE_PROJECT_PATH
import pytest

BASE_PROJECT_PATH = 'samplescli/project.pbxproj'


class PBXCLITest(unittest.TestCase):
def setUp(self):
self.pwd = os.getcwd()
os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))

def tearDown(self):
if hasattr(self, 'backup_file') and self.backup_file:
os.remove(self.backup_file)
sys.stdout = sys.__stdout__
os.chdir(self.pwd)

def testOpenProjectWithFullPath(self):
project = open_project({PROJECT_PLACEHOLDER: BASE_PROJECT_PATH})
Expand Down
8 changes: 5 additions & 3 deletions tests/pbxcli/TestPBXProjFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@
import pbxproj.pbxcli.pbxproj_file as pbxproj_file
from pbxproj import PBXGenericObject
from pbxproj.pbxcli import open_project, PROJECT_PLACEHOLDER, PATH_PLACEHOLDER
from tests.pbxcli import BASE_PROJECT_PATH, SAMPLE_PROJECT_PATH
import pytest

SAMPLE_PROJECT_PATH = 'samplescli/test.pbxproj'
BASE_PROJECT_PATH = 'samplescli/project.pbxproj'


class PBXProjFileTest(unittest.TestCase):
def setUp(self):
# copy the project.pbxproj, into a file that can be used by the tests
self.pwd = os.getcwd()
os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))

shutil.copyfile(BASE_PROJECT_PATH, SAMPLE_PROJECT_PATH)

def tearDown(self):
os.remove(SAMPLE_PROJECT_PATH)
sys.stdout = sys.__stdout__
os.chdir(self.pwd)

def testRemoveFileUnknown(self):
args = {
Expand Down
6 changes: 5 additions & 1 deletion tests/pbxcli/TestPBXProjFlag.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@

class TestPBXProjFlag(unittest.TestCase):
def setUp(self):
self.pwd = os.getcwd()
os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))

# copy the project.pbxproj, into a file that can be used by the tests
shutil.copyfile(BASE_PROJECT_PATH, SAMPLE_PROJECT_PATH)

def tearDown(self):
os.remove(SAMPLE_PROJECT_PATH)
sys.stdout = sys.__stdout__
os.chdir(self.pwd)

def testAddFlags(self):
args = {
Expand Down Expand Up @@ -56,4 +60,4 @@ def testRemoveFlags(self):
assert result == 'Flags removed successfully.'

for configuration in project.objects.get_configurations_on_targets(args['--target'], args['--configuration']):
assert 'MYFLAG' not in configuration.buildSettings
assert 'MYFLAG' not in configuration.buildSettings
9 changes: 6 additions & 3 deletions tests/pbxcli/TestPBXProjFolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@
from pbxproj import PBXGenericObject
from pbxproj.pbxcli import open_project, PROJECT_PLACEHOLDER, PATH_PLACEHOLDER
from pbxproj.pbxextensions.ProjectFiles import TreeType
from tests.pbxcli import BASE_PROJECT_PATH, SAMPLE_PROJECT_PATH
import pytest

SAMPLE_PROJECT_PATH = 'samplescli/test.pbxproj'
BASE_PROJECT_PATH = 'samplescli/project.pbxproj'


class PBXProjFolderTest(unittest.TestCase):

def setUp(self):
self.pwd = os.getcwd()
os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))

# copy the project.pbxproj, into a file that can be used by the tests
shutil.copyfile(BASE_PROJECT_PATH, SAMPLE_PROJECT_PATH)

def tearDown(self):
os.remove(SAMPLE_PROJECT_PATH)
sys.stdout = sys.__stdout__
os.chdir(self.pwd)

def testRemoveFolderUnknown(self):
args = {
Expand Down
4 changes: 4 additions & 0 deletions tests/pbxcli/TestPBXProjShow.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@

class PBXProjShowTest(unittest.TestCase):
def setUp(self):
self.pwd = os.getcwd()
os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))

# copy the project.pbxproj, into a file that can be used by the tests
shutil.copyfile(BASE_PROJECT_PATH, SAMPLE_PROJECT_PATH)

def tearDown(self):
os.remove(SAMPLE_PROJECT_PATH)
sys.stdout = sys.__stdout__
os.chdir(self.pwd)

def testShowAllTargetsInfo(self):
args = {
Expand Down
2 changes: 1 addition & 1 deletion tests/pbxcli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SAMPLE_PROJECT_PATH = 'samplescli/test.pbxproj'
BASE_PROJECT_PATH = 'samplescli/project.pbxproj'
BASE_PROJECT_PATH = 'samplescli/project.pbxproj'
6 changes: 6 additions & 0 deletions tests/pbxextensions/TestProjectFiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ def setUp(self):
}
}

self.pwd = os.getcwd()
os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))

def tearDown(self):
os.chdir(self.pwd)

def testInit(self):
with pytest.raises(EnvironmentError, match='^This class cannot be instantiated directly'):
ProjectFiles()
Expand Down