Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
test_extension.py118 linesDownload Raw Back to tests
1"""Tests for distutils.extension."""2 3import os4import pathlib5import warnings6from distutils.extension import Extension, read_setup_file7 8import pytest9from test.support.warnings_helper import check_warnings10 11 12class TestExtension:13    def test_read_setup_file(self):14        # trying to read a Setup file15        # (sample extracted from the PyGame project)16        setup = os.path.join(os.path.dirname(__file__), 'Setup.sample')17 18        exts = read_setup_file(setup)19        names = [ext.name for ext in exts]20        names.sort()21 22        # here are the extensions read_setup_file should have created23        # out of the file24        wanted = [25            '_arraysurfarray',26            '_camera',27            '_numericsndarray',28            '_numericsurfarray',29            'base',30            'bufferproxy',31            'cdrom',32            'color',33            'constants',34            'display',35            'draw',36            'event',37            'fastevent',38            'font',39            'gfxdraw',40            'image',41            'imageext',42            'joystick',43            'key',44            'mask',45            'mixer',46            'mixer_music',47            'mouse',48            'movie',49            'overlay',50            'pixelarray',51            'pypm',52            'rect',53            'rwobject',54            'scrap',55            'surface',56            'surflock',57            'time',58            'transform',59        ]60 61        assert names == wanted62 63    def test_extension_init(self):64        # the first argument, which is the name, must be a string65        with pytest.raises(TypeError):66            Extension(1, [])67        ext = Extension('name', [])68        assert ext.name == 'name'69 70        # the second argument, which is the list of files, must71        # be an iterable of strings or PathLike objects, and not a string72        with pytest.raises(TypeError):73            Extension('name', 'file')74        with pytest.raises(TypeError):75            Extension('name', ['file', 1])76        ext = Extension('name', ['file1', 'file2'])77        assert ext.sources == ['file1', 'file2']78        ext = Extension('name', [pathlib.Path('file1'), pathlib.Path('file2')])79        assert ext.sources == ['file1', 'file2']80 81        # any non-string iterable of strings or PathLike objects should work82        ext = Extension('name', ('file1', 'file2'))  # tuple83        assert ext.sources == ['file1', 'file2']84        ext = Extension('name', {'file1', 'file2'})  # set85        assert sorted(ext.sources) == ['file1', 'file2']86        ext = Extension('name', iter(['file1', 'file2']))  # iterator87        assert ext.sources == ['file1', 'file2']88        ext = Extension('name', [pathlib.Path('file1'), 'file2'])  # mixed types89        assert ext.sources == ['file1', 'file2']90 91        # others arguments have defaults92        for attr in (93            'include_dirs',94            'define_macros',95            'undef_macros',96            'library_dirs',97            'libraries',98            'runtime_library_dirs',99            'extra_objects',100            'extra_compile_args',101            'extra_link_args',102            'export_symbols',103            'swig_opts',104            'depends',105        ):106            assert getattr(ext, attr) == []107 108        assert ext.language is None109        assert ext.optional is None110 111        # if there are unknown keyword options, warn about them112        with check_warnings() as w:113            warnings.simplefilter('always')114            ext = Extension('name', ['file1', 'file2'], chic=True)115 116        assert len(w.warnings) == 1117        assert str(w.warnings[0].message) == "Unknown Extension options: 'chic'"118 
codekingpro/portable-devtools · Team Ai