Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Commit

Permalink
Setup script to apply to android plus somewhere to put it's tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rsheeter committed Jan 10, 2022
1 parent 3e680f2 commit 187b0c1
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 1 deletion.
Empty file added android_connection/__init__.py
Empty file.
33 changes: 33 additions & 0 deletions android_connection/apply_to_android.py
Original file line number Diff line number Diff line change
@@ -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()
File renamed without changes.
Empty file added tests/__init__.py
Empty file.
20 changes: 20 additions & 0 deletions tests/apply_to_android_test.py
Original file line number Diff line number Diff line change
@@ -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())
2 changes: 1 addition & 1 deletion tests/noto_fonts_for_android_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,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
Expand Down
Empty file.
Empty file.

0 comments on commit 187b0c1

Please sign in to comment.