Skip to content

Commit 1406898

Browse files
eustascopybara-github
authored andcommitted
Build and test with PY2.7
PiperOrigin-RevId: 811352084
1 parent 0bef8a6 commit 1406898

File tree

8 files changed

+68
-47
lines changed

8 files changed

+68
-47
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ tests/testdata/empty !export-ignore
5151
tests/testdata/empty.compressed !export-ignore
5252
tests/testdata/ukkonooa !export-ignore
5353
tests/testdata/ukkonooa.compressed !export-ignore
54+
tests/testdata/zerosukkanooa.compressed !export-ignore

.github/workflows/build_test.yml

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ concurrency:
1818
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
1919

2020
jobs:
21-
ubuntu_build:
21+
build_test:
2222
name: Build and test ${{ matrix.name }}
2323
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
2424
defaults:
@@ -188,13 +188,6 @@ jobs:
188188
submodules: false
189189
fetch-depth: 1
190190

191-
#- name: Checkout VC9 for Python
192-
# if: ${{ runner.os == 'Windows' && matrix.build_system == 'python' && matrix.python_version == '2.7' }}
193-
# uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
194-
# with:
195-
# repository: reider-roque/sulley-win-installer
196-
# path: third_party/VCForPython27
197-
198191
- name: Configure / Build / Test with CMake
199192
if: ${{ matrix.build_system == 'cmake' }}
200193
run: |
@@ -294,17 +287,36 @@ jobs:
294287
with:
295288
python-version: ${{ matrix.python_version }}
296289

297-
# TODO: investigate, why msiexec hangs
298-
#- name: Install VC9 for Python
299-
# if: ${{ runner.os == 'Windows' && matrix.build_system == 'python' && matrix.python_version == '2.7' }}
300-
# run: |
301-
# echo "070474db76a2e625513a5835df4595df9324d820f9cc97eab2a596dcbc2f5cbf third_party/VCForPython27/VCForPython27.msi" | sha256sum --check --status
302-
# msiexec ALLUSERS=1 /qn /norestart /i third_party/VCForPython27/VCForPython27.msi /l*v ${RUNNER_TEMP}/msiexec.log
303-
# cat ${RUNNER_TEMP}/msiexec.log
304-
305290
- name: Build / Test with Python
306291
if: ${{ matrix.build_system == 'python' }}
307292
run: |
308293
python -VV
309294
python -c "import sys; sys.exit('Invalid python version') if '.'.join(map(str,sys.version_info[0:2])) != '${{ matrix.python_version }}' else True"
310295
python setup.py ${{ matrix.py_setuptools_cmd || 'test'}}
296+
297+
build_test_py27:
298+
name: Build and test with Python 2.7
299+
runs-on: ubuntu-latest
300+
container:
301+
image: ubuntu:22.04
302+
steps:
303+
304+
- name: Install deps
305+
run: |
306+
apt update
307+
apt install -y curl gcc python2.7 python2.7-dev
308+
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
309+
python2.7 get-pip.py
310+
python2.7 -m pip install distutils-pytest==0.1
311+
312+
- name: Checkout the source
313+
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
314+
with:
315+
submodules: false
316+
fetch-depth: 1
317+
318+
- name: Build / Test
319+
run: |
320+
python2.7 -VV
321+
python2.7 -c "import sys; sys.exit('Invalid python version') if '.'.join(map(str,sys.version_info[0:2])) != '2.7' else True"
322+
python2.7 setup.py test

CMakeLists.txt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,16 @@ if(NOT BROTLI_DISABLE_TESTS AND BROTLI_BUILD_TOOLS)
255255
tests/testdata/*.compressed*)
256256

257257
foreach(INPUT ${COMPATIBILITY_INPUTS})
258-
add_test(NAME "${BROTLI_TEST_PREFIX}compatibility/${INPUT}"
259-
COMMAND "${CMAKE_COMMAND}"
260-
-DBROTLI_WRAPPER=${BROTLI_WRAPPER}
261-
-DBROTLI_WRAPPER_LD_PREFIX=${BROTLI_WRAPPER_LD_PREFIX}
262-
-DBROTLI_CLI=$<TARGET_FILE:brotli>
263-
-DINPUT=${CMAKE_CURRENT_SOURCE_DIR}/${INPUT}
264-
-P ${CMAKE_CURRENT_SOURCE_DIR}/tests/run-compatibility-test.cmake)
258+
string(REGEX REPLACE "([a-zA-Z0-9\\.]+)\\.compressed(\\.[0-9]+)?$" "\\1" UNCOMPRESSED_INPUT "${INPUT}")
259+
if (EXISTS ${UNCOMPRESSED_INPUT})
260+
add_test(NAME "${BROTLI_TEST_PREFIX}compatibility/${INPUT}"
261+
COMMAND "${CMAKE_COMMAND}"
262+
-DBROTLI_WRAPPER=${BROTLI_WRAPPER}
263+
-DBROTLI_WRAPPER_LD_PREFIX=${BROTLI_WRAPPER_LD_PREFIX}
264+
-DBROTLI_CLI=$<TARGET_FILE:brotli>
265+
-DINPUT=${CMAKE_CURRENT_SOURCE_DIR}/${INPUT}
266+
-P ${CMAKE_CURRENT_SOURCE_DIR}/tests/run-compatibility-test.cmake)
267+
endif()
265268
endforeach()
266269
endif() # BROTLI_DISABLE_TESTS
267270

python/_brotli.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -854,18 +854,6 @@ static PyMethodDef brotli_methods[] = {
854854
brotli_decompress__doc__},
855855
{NULL, NULL, 0, NULL}};
856856

857-
static struct PyModuleDef brotli_module = {
858-
PyModuleDef_HEAD_INIT,
859-
"_brotli", /* m_name */
860-
brotli_doc, /* m_doc */
861-
0, /* m_size */
862-
brotli_methods, /* m_methods */
863-
NULL, /* m_reload */
864-
NULL, /* m_traverse */
865-
NULL, /* m_clear */
866-
NULL /* m_free */
867-
};
868-
869857
static PyMethodDef brotli_Compressor_methods[] = {
870858
{"process", (PyCFunction)brotli_Compressor_process, METH_VARARGS,
871859
brotli_Compressor_process_doc},
@@ -889,6 +877,18 @@ static PyMethodDef brotli_Decompressor_methods[] = {
889877

890878
#if PY_MAJOR_VERSION >= 3
891879

880+
static struct PyModuleDef brotli_module = {
881+
PyModuleDef_HEAD_INIT,
882+
"_brotli", /* m_name */
883+
brotli_doc, /* m_doc */
884+
0, /* m_size */
885+
brotli_methods, /* m_methods */
886+
NULL, /* m_reload */
887+
NULL, /* m_traverse */
888+
NULL, /* m_clear */
889+
NULL /* m_free */
890+
};
891+
892892
static PyType_Slot brotli_Compressor_slots[] = {
893893
{Py_tp_dealloc, (destructor)brotli_Compressor_dealloc},
894894
{Py_tp_doc, (void*)brotli_Compressor_doc},

python/tests/_test_utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ def generate_test_methods(
9797
generate a separate test method.
9898
"""
9999
if for_decompression:
100-
paths = TESTDATA_PATHS_FOR_DECOMPRESSION
100+
paths = [
101+
path for path in TESTDATA_PATHS_FOR_DECOMPRESSION
102+
if os.path.exists(path.replace('.compressed', ''))
103+
]
101104
else:
102105
paths = TESTDATA_PATHS
103106
opts = []
@@ -141,7 +144,7 @@ def tearDown(self):
141144
os.unlink(get_temp_uncompressed_name(f))
142145
except OSError:
143146
pass
144-
super().tearDown()
147+
# super().tearDown() # Requires Py3+
145148

146149
def assert_files_match(self, first, second):
147150
self.assertTrue(

python/tests/compressor_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class _TestCompressor(object):
2020

2121
def tearDown(self):
2222
self.compressor = None
23-
super().tearDown()
23+
# super().tearDown() # Requires Py3+
2424

2525
def _check_decompression(self, test_data):
2626
# Write decompression to temp file and verify it matches the original.
@@ -71,28 +71,28 @@ def _test_multiple_process_and_flush(self, test_data):
7171
class TestCompressorQuality1(_TestCompressor, _test_utils.TestCase):
7272

7373
def setUp(self):
74-
super().setUp()
74+
# super().setUp() # Requires Py3+
7575
self.compressor = brotli.Compressor(quality=1)
7676

7777

7878
class TestCompressorQuality6(_TestCompressor, _test_utils.TestCase):
7979

8080
def setUp(self):
81-
super().setUp()
81+
# super().setUp() # Requires Py3+
8282
self.compressor = brotli.Compressor(quality=6)
8383

8484

8585
class TestCompressorQuality9(_TestCompressor, _test_utils.TestCase):
8686

8787
def setUp(self):
88-
super().setUp()
88+
# super().setUp() # Requires Py3+
8989
self.compressor = brotli.Compressor(quality=9)
9090

9191

9292
class TestCompressorQuality11(_TestCompressor, _test_utils.TestCase):
9393

9494
def setUp(self):
95-
super().setUp()
95+
# super().setUp() # Requires Py3+
9696
self.compressor = brotli.Compressor(quality=11)
9797

9898

python/tests/decompressor_test.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ class TestDecompressor(_test_utils.TestCase):
2222
MIN_OUTPUT_BUFFER_SIZE = 32768 # Actually, several bytes less.
2323

2424
def setUp(self):
25-
super().setUp()
25+
# super().setUp() # Requires Py3+
2626
self.decompressor = brotli.Decompressor()
2727

2828
def tearDown(self):
2929
self.decompressor = None
30-
super().tearDown()
30+
# super().tearDown() # Requires Py3+
3131

3232
def _check_decompression(self, test_data):
3333
# Verify decompression matches the original.
@@ -86,6 +86,7 @@ def test_changing_limit(self):
8686
test_data = os.path.join(
8787
_test_utils.TESTDATA_DIR, 'zerosukkanooa.compressed'
8888
)
89+
check_output = os.path.exists(test_data.replace('.compressed', ''))
8990
temp_uncompressed = _test_utils.get_temp_uncompressed_name(test_data)
9091
with open(temp_uncompressed, 'wb') as out_file:
9192
with open(test_data, 'rb') as in_file:
@@ -98,7 +99,8 @@ def test_changing_limit(self):
9899
while not self.decompressor.can_accept_more_data():
99100
out_file.write(self.decompressor.process(b''))
100101
out_file.write(self.decompressor.process(compressed[-1:]))
101-
self._check_decompression(test_data)
102+
if check_output:
103+
self._check_decompression(test_data)
102104

103105
def test_garbage_appended(self):
104106
with self.assertRaises(brotli.error):

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424
CURR_DIR = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
2525

2626

27-
def bool_from_environ(key: str):
27+
def bool_from_environ(key):
2828
value = os.environ.get(key)
2929
if not value:
3030
return False
3131
if value == "1":
3232
return True
3333
if value == "0":
3434
return False
35-
raise ValueError(f"Environment variable {key} has invalid value {value}. Please set it to 1, 0 or an empty string")
35+
raise ValueError("Environment variable {} has invalid value {}. Please set it to 1, 0 or an empty string".format(key, value))
3636

3737

3838
def read_define(path, macro):

0 commit comments

Comments
 (0)