diff --git a/android_connection/__init__.py b/android_connection/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/android_connection/apply_to_android.py b/android_connection/apply_to_android.py new file mode 100644 index 000000000..8eff732d4 --- /dev/null +++ b/android_connection/apply_to_android.py @@ -0,0 +1,33 @@ +from pathlib import Path +import sys + + +def _require_exists(a_file: Path) -> Path: + if not a_file.is_file(): + raise ValueError(f"{a_file} not found") + return a_file + + +def _fonts_xml(android_dir: Path) -> Path: + return _require_exists(android_dir / "frameworks" / "base" / "data" / "fonts" / "fonts.xml") + + +def _fonts_mk(android_dir: Path) -> Path: + return _require_exists(android_dir / "external" / "noto-fonts" / "fonts.mk") + + +def _validate_android_path(android_dir: Path): + assert android_dir.is_dir(), f"{android_dir} should be a directory" + _fonts_xml(android_dir) # just to trigger it's checks + _fonts_mk(android_dir) # just to trigger it's checks + + +def main(): + if len(sys.argv) != 2: + raise ValueError("Must have one arg, path to an Android checkout") + android_dir = Path(sys.argv[1]) + _validate_android_path(android_dir) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/android-connection/migrate_attrs.py b/android_connection/migrate_attrs.py similarity index 100% rename from android-connection/migrate_attrs.py rename to android_connection/migrate_attrs.py diff --git a/android-connection/noto-fonts-4-android.xml b/android_connection/noto-fonts-4-android.xml similarity index 100% rename from android-connection/noto-fonts-4-android.xml rename to android_connection/noto-fonts-4-android.xml diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/apply_to_android_test.py b/tests/apply_to_android_test.py new file mode 100644 index 000000000..f7d7d88aa --- /dev/null +++ b/tests/apply_to_android_test.py @@ -0,0 +1,20 @@ +from android_connection import apply_to_android +from pathlib import Path +import pytest + + +def _testdata_dir() -> Path: + return Path(__file__).parent / "testdata" + + +def _fake_android_dir() -> Path: + return _testdata_dir() / "fake_android" + + +def test_apply_to_bad_dir(): + with pytest.raises(ValueError, match="not found"): + apply_to_android._validate_android_path(_testdata_dir()) + + +def test_apply_to_good_dir(): + apply_to_android._validate_android_path(_fake_android_dir()) diff --git a/tests/noto_fonts_for_android_test.py b/tests/noto_fonts_for_android_test.py index 017507c71..bcfd84522 100644 --- a/tests/noto_fonts_for_android_test.py +++ b/tests/noto_fonts_for_android_test.py @@ -22,7 +22,7 @@ def _repo_root() -> Path: def _noto_4_android_file() -> Path: - xml_file = _repo_root() / "android-connection" / "noto-fonts-4-android.xml" + xml_file = _repo_root() / "android_connection" / "noto-fonts-4-android.xml" if not xml_file.is_file(): raise IOError(f"No file {xml_file}") return xml_file diff --git a/tests/testdata/fake_android/external/noto-fonts/fonts.mk b/tests/testdata/fake_android/external/noto-fonts/fonts.mk new file mode 100644 index 000000000..e69de29bb diff --git a/tests/testdata/fake_android/frameworks/base/data/fonts/fonts.xml b/tests/testdata/fake_android/frameworks/base/data/fonts/fonts.xml new file mode 100644 index 000000000..e69de29bb