def can_convert_data_classes_to_and_from_flat_list(): User = dodge.data_class("User", ["username", "password"]) user = User("bob", "password1") serialised_user = dodge.obj_to_flat_list(user) unserialised_user = dodge.flat_list_to_obj(serialised_user, User) expected_user = User("bob", "password1") assert_equal(unserialised_user, expected_user)
def can_convert_nested_data_classes_to_and_from_flat_list(): Profile = dodge.data_class("Profile", ["bio"]) User = dodge.data_class("User", ["username", dodge.field("profile", type=Profile)]) user = User("bob", Profile("I'm Bob.")) serialised_user = dodge.obj_to_flat_list(user) unserialised_user = dodge.flat_list_to_obj(serialised_user, User) assert_equal(user, unserialised_user)
def can_convert_nested_data_classes_to_and_from_flat_list(): Profile = dodge.data_class("Profile", ["bio"]) User = dodge.data_class("User", [ "username", dodge.field("profile", type=Profile), ]) user = User("bob", Profile("I'm Bob.")) serialised_user = dodge.obj_to_flat_list(user) unserialised_user = dodge.flat_list_to_obj(serialised_user, User) assert_equal(user, unserialised_user)
libc = self._run(["getconf", "GNU_LIBC_VERSION"]) return Platform(os_name=os_name, architecture=architecture, libc=libc) def _uname(self, *args): return self._run(["uname"] + list(args)) def _run(self, command): output = self._shell.run(command).output.decode("ascii") return output.strip().lower().replace("_", "-").replace(" ", "-") Platform = dodge.data_class("Platform", ["os_name", "architecture", "libc"]) Platform.dumps = lambda self: slugs.join(dodge.obj_to_flat_list(self)) Platform.load_list = staticmethod(lambda values: dodge.flat_list_to_obj(values, Platform)) def _platform_can_use(self, other): return ( self.os_name == other.os_name and self.architecture == other.architecture and _libc_can_use(self.libc, other.libc) ) def _libc_can_use(first, second): first_version, second_version = map(_glibc_version, (first, second)) if first_version is None or second_version is None: return first == second else: return first_version >= second_version