@@ -77,6 +77,23 @@ def mock_ios_ver(*args):
7777 monkeypatch .setattr (platform , "ios_ver" , mock_ios_ver )
7878
7979
80+ @pytest .fixture
81+ def mock_android (monkeypatch ):
82+ monkeypatch .setattr (sys , "platform" , "android" )
83+ monkeypatch .setattr (platform , "system" , lambda : "Android" )
84+ monkeypatch .setattr (sysconfig , "get_platform" , lambda : "android-21-arm64_v8a" )
85+
86+ AndroidVer = collections .namedtuple (
87+ "AndroidVer" , "release api_level manufacturer model device is_emulator"
88+ )
89+ monkeypatch .setattr (
90+ platform ,
91+ "android_ver" ,
92+ lambda : AndroidVer ("5.0" , 21 , "Google" , "sdk_gphone64_arm64" , "emu64a" , True ),
93+ raising = False , # This function was added in Python 3.13.
94+ )
95+
96+
8097class TestTag :
8198 def test_lowercasing (self ):
8299 tag = tags .Tag ("PY3" , "None" , "ANY" )
@@ -437,6 +454,69 @@ def test_ios_platforms(self, mock_ios):
437454 ]
438455
439456
457+ class TestAndroidPlatforms :
458+ def test_non_android (self ):
459+ non_android_error = pytest .raises (TypeError )
460+ with non_android_error :
461+ list (tags .android_platforms ())
462+ with non_android_error :
463+ list (tags .android_platforms (api_level = 18 ))
464+ with non_android_error :
465+ list (tags .android_platforms (abi = "x86_64" ))
466+
467+ # The function can only be called on non-Android platforms if both arguments are
468+ # provided.
469+ assert list (tags .android_platforms (api_level = 18 , abi = "x86_64" )) == [
470+ "android_18_x86_64" ,
471+ "android_17_x86_64" ,
472+ "android_16_x86_64" ,
473+ ]
474+
475+ def test_detection (self , mock_android ):
476+ assert list (tags .android_platforms ()) == [
477+ "android_21_arm64_v8a" ,
478+ "android_20_arm64_v8a" ,
479+ "android_19_arm64_v8a" ,
480+ "android_18_arm64_v8a" ,
481+ "android_17_arm64_v8a" ,
482+ "android_16_arm64_v8a" ,
483+ ]
484+
485+ def test_api_level (self ):
486+ # API levels below the minimum should return nothing.
487+ assert list (tags .android_platforms (api_level = 14 , abi = "x86" )) == []
488+ assert list (tags .android_platforms (api_level = 15 , abi = "x86" )) == []
489+
490+ assert list (tags .android_platforms (api_level = 16 , abi = "x86" )) == [
491+ "android_16_x86" ,
492+ ]
493+ assert list (tags .android_platforms (api_level = 17 , abi = "x86" )) == [
494+ "android_17_x86" ,
495+ "android_16_x86" ,
496+ ]
497+ assert list (tags .android_platforms (api_level = 18 , abi = "x86" )) == [
498+ "android_18_x86" ,
499+ "android_17_x86" ,
500+ "android_16_x86" ,
501+ ]
502+
503+ def test_abi (self ):
504+ # Real ABI, normalized.
505+ assert list (tags .android_platforms (api_level = 16 , abi = "armeabi_v7a" )) == [
506+ "android_16_armeabi_v7a" ,
507+ ]
508+
509+ # Real ABI, not normalized.
510+ assert list (tags .android_platforms (api_level = 16 , abi = "armeabi-v7a" )) == [
511+ "android_16_armeabi_v7a" ,
512+ ]
513+
514+ # Nonexistent ABIs should still be accepted and normalized.
515+ assert list (tags .android_platforms (api_level = 16 , abi = "myarch-4.2" )) == [
516+ "android_16_myarch_4_2" ,
517+ ]
518+
519+
440520class TestManylinuxPlatform :
441521 def teardown_method (self ):
442522 # Clear the version cache
@@ -722,6 +802,7 @@ def test_linux_not_linux(self, monkeypatch):
722802 [
723803 ("Darwin" , "mac_platforms" ),
724804 ("iOS" , "ios_platforms" ),
805+ ("Android" , "android_platforms" ),
725806 ("Linux" , "_linux_platforms" ),
726807 ("Generic" , "_generic_platforms" ),
727808 ],
0 commit comments