Refactor common methods out of sysfs package and add tests.