Skip to content

Commit 8ac6d98

Browse files
authored
refactor: make tests agnostic from the running path (#358)
1 parent 3ea5059 commit 8ac6d98

File tree

11 files changed

+46
-18
lines changed

11 files changed

+46
-18
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ jobs:
2727
python setup.py sdist bdist_wheel
2828
twine upload dist/*
2929
env:
30-
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
30+
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
3131
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
.PHONY: coverage coverage-term test install-dependencies
22

33
coverage: install-dependencies
4-
cd tests; pytest --cov-report=xml --cov=../ --cov-branch
5-
cd tests; rm -rf .coverage
4+
pytest --cov-report=xml --cov=../ --cov-branch
5+
rm -rf .coverage
66

77
coverage-term: install-dependencies
8-
cd tests; pytest --cov-report=term --cov=../ --cov-branch
9-
cd tests; rm -rf .coverage
8+
pytest --cov-report=term --cov=../ --cov-branch
9+
rm -rf .coverage
1010

1111
test:
12-
cd tests; pytest
12+
pytest
1313

1414
install-dependencies:
1515
pip3 install -r dev-requirements.txt
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[pytest]
22
python_files = Test*.py
3-
pythonpath = ..
3+
pythonpath = .
4+
testpaths = tests

tests/TestXCodeProject.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import unittest
44

55
from pbxproj import XcodeProject
6+
from os.path import join
67
import re
78

89

@@ -37,13 +38,17 @@ def setUp(self):
3738
}
3839
}
3940

41+
self.pwd = os.getcwd()
42+
os.chdir(os.path.dirname(os.path.abspath(__file__)))
43+
4044
# create tmp directory for results
4145
if not os.path.exists("results"):
4246
os.mkdir("results")
4347

4448
def tearDown(self):
4549
# remove tmp directory
4650
shutil.rmtree('results')
51+
os.chdir(self.pwd)
4752

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

114119
assert saved == original
115-

tests/pbxcli/TestPBXCLI.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@
66

77
from pbxproj import XcodeProject
88
from pbxproj.pbxcli import open_project, resolve_backup, backup_project, command_parser, PROJECT_PLACEHOLDER
9+
from tests.pbxcli import BASE_PROJECT_PATH
910
import pytest
1011

11-
BASE_PROJECT_PATH = 'samplescli/project.pbxproj'
12-
1312

1413
class PBXCLITest(unittest.TestCase):
14+
def setUp(self):
15+
self.pwd = os.getcwd()
16+
os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))
17+
1518
def tearDown(self):
1619
if hasattr(self, 'backup_file') and self.backup_file:
1720
os.remove(self.backup_file)
1821
sys.stdout = sys.__stdout__
22+
os.chdir(self.pwd)
1923

2024
def testOpenProjectWithFullPath(self):
2125
project = open_project({PROJECT_PLACEHOLDER: BASE_PROJECT_PATH})

tests/pbxcli/TestPBXProjFile.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,22 @@
66
import pbxproj.pbxcli.pbxproj_file as pbxproj_file
77
from pbxproj import PBXGenericObject
88
from pbxproj.pbxcli import open_project, PROJECT_PLACEHOLDER, PATH_PLACEHOLDER
9+
from tests.pbxcli import BASE_PROJECT_PATH, SAMPLE_PROJECT_PATH
910
import pytest
1011

11-
SAMPLE_PROJECT_PATH = 'samplescli/test.pbxproj'
12-
BASE_PROJECT_PATH = 'samplescli/project.pbxproj'
13-
1412

1513
class PBXProjFileTest(unittest.TestCase):
1614
def setUp(self):
1715
# copy the project.pbxproj, into a file that can be used by the tests
16+
self.pwd = os.getcwd()
17+
os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))
18+
1819
shutil.copyfile(BASE_PROJECT_PATH, SAMPLE_PROJECT_PATH)
1920

2021
def tearDown(self):
2122
os.remove(SAMPLE_PROJECT_PATH)
2223
sys.stdout = sys.__stdout__
24+
os.chdir(self.pwd)
2325

2426
def testRemoveFileUnknown(self):
2527
args = {

tests/pbxcli/TestPBXProjFlag.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@
1010

1111
class TestPBXProjFlag(unittest.TestCase):
1212
def setUp(self):
13+
self.pwd = os.getcwd()
14+
os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))
15+
1316
# copy the project.pbxproj, into a file that can be used by the tests
1417
shutil.copyfile(BASE_PROJECT_PATH, SAMPLE_PROJECT_PATH)
1518

1619
def tearDown(self):
1720
os.remove(SAMPLE_PROJECT_PATH)
1821
sys.stdout = sys.__stdout__
22+
os.chdir(self.pwd)
1923

2024
def testAddFlags(self):
2125
args = {
@@ -56,4 +60,4 @@ def testRemoveFlags(self):
5660
assert result == 'Flags removed successfully.'
5761

5862
for configuration in project.objects.get_configurations_on_targets(args['--target'], args['--configuration']):
59-
assert 'MYFLAG' not in configuration.buildSettings
63+
assert 'MYFLAG' not in configuration.buildSettings

tests/pbxcli/TestPBXProjFolder.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,23 @@
77
from pbxproj import PBXGenericObject
88
from pbxproj.pbxcli import open_project, PROJECT_PLACEHOLDER, PATH_PLACEHOLDER
99
from pbxproj.pbxextensions.ProjectFiles import TreeType
10+
from tests.pbxcli import BASE_PROJECT_PATH, SAMPLE_PROJECT_PATH
1011
import pytest
1112

12-
SAMPLE_PROJECT_PATH = 'samplescli/test.pbxproj'
13-
BASE_PROJECT_PATH = 'samplescli/project.pbxproj'
14-
1513

1614
class PBXProjFolderTest(unittest.TestCase):
15+
1716
def setUp(self):
17+
self.pwd = os.getcwd()
18+
os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))
19+
1820
# copy the project.pbxproj, into a file that can be used by the tests
1921
shutil.copyfile(BASE_PROJECT_PATH, SAMPLE_PROJECT_PATH)
2022

2123
def tearDown(self):
2224
os.remove(SAMPLE_PROJECT_PATH)
2325
sys.stdout = sys.__stdout__
26+
os.chdir(self.pwd)
2427

2528
def testRemoveFolderUnknown(self):
2629
args = {

tests/pbxcli/TestPBXProjShow.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@
1010

1111
class PBXProjShowTest(unittest.TestCase):
1212
def setUp(self):
13+
self.pwd = os.getcwd()
14+
os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))
15+
1316
# copy the project.pbxproj, into a file that can be used by the tests
1417
shutil.copyfile(BASE_PROJECT_PATH, SAMPLE_PROJECT_PATH)
1518

1619
def tearDown(self):
1720
os.remove(SAMPLE_PROJECT_PATH)
1821
sys.stdout = sys.__stdout__
22+
os.chdir(self.pwd)
1923

2024
def testShowAllTargetsInfo(self):
2125
args = {

tests/pbxcli/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
SAMPLE_PROJECT_PATH = 'samplescli/test.pbxproj'
2-
BASE_PROJECT_PATH = 'samplescli/project.pbxproj'
2+
BASE_PROJECT_PATH = 'samplescli/project.pbxproj'

tests/pbxextensions/TestProjectFiles.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ def setUp(self):
4141
}
4242
}
4343

44+
self.pwd = os.getcwd()
45+
os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))
46+
47+
def tearDown(self):
48+
os.chdir(self.pwd)
49+
4450
def testInit(self):
4551
with pytest.raises(EnvironmentError, match='^This class cannot be instantiated directly'):
4652
ProjectFiles()

0 commit comments

Comments
 (0)