def test_inheritance(self): class Parent(DataSetFamily): extra_dims = [ ('dim_0', {'a', 'b', 'c'}), ('dim_1', {'d', 'e', 'f'}), ] column_0 = Column('f8') column_1 = Column('?') class Child(Parent): column_2 = Column('O') column_3 = Column('i8', -1) assert_is_subclass(Child, Parent) assert_equal(Child.extra_dims, Parent.extra_dims) ChildSlice = Child.slice(dim_0='a', dim_1='d') expected_child_slice_columns = frozenset({ ChildSlice.column_0, ChildSlice.column_1, ChildSlice.column_2, ChildSlice.column_3, }) assert_equal(ChildSlice.columns, expected_child_slice_columns)
def test_inheritance(self): class Parent(DataSetFamily): extra_dims = [ ("dim_0", {"a", "b", "c"}), ("dim_1", {"d", "e", "f"}), ] column_0 = Column("f8") column_1 = Column("?") class Child(Parent): column_2 = Column("O") column_3 = Column("i8", -1) assert_is_subclass(Child, Parent) assert_equal(Child.extra_dims, Parent.extra_dims) ChildSlice = Child.slice(dim_0="a", dim_1="d") expected_child_slice_columns = frozenset({ ChildSlice.column_0, ChildSlice.column_1, ChildSlice.column_2, ChildSlice.column_3, }) assert_equal(ChildSlice.columns, expected_child_slice_columns)
def test_with_metaclasses_with_subclasses(self): class E(with_metaclasses((M, N), C, D)): pass assert_true(E.M) assert_true(E.N) assert_is_instance(E, M) assert_is_instance(E, N) assert_is_subclass(E, C) assert_is_subclass(E, D)
def test_valid_slice(self, dims_spec): class MD(DataSetFamily): extra_dims = dims_spec f8 = Column('f8') i8 = Column('i8', missing_value=0) ob = Column('O') M8 = Column('M8[ns]') boolean = Column('?') expected_dims = OrderedDict([(k, frozenset(v)) for k, v in dims_spec]) assert_equal(MD.extra_dims, expected_dims) for valid_combination in itertools.product(*expected_dims.values()): Slice = MD.slice(*valid_combination) alternate_constructions = [ # all positional MD.slice(*valid_combination), # all keyword MD.slice(**dict(zip(expected_dims.keys(), valid_combination))), # mix keyword/positional MD.slice( *valid_combination[:len(valid_combination) // 2], **dict( list(zip(expected_dims.keys(), valid_combination))[ len(valid_combination) // 2: ], ) ), ] for alt in alternate_constructions: assert_is(Slice, alt, msg='Slices are not properly memoized') expected_coords = OrderedDict( zip(expected_dims, valid_combination), ) assert_equal(Slice.extra_coords, expected_coords) assert_is(Slice.dataset_family, MD) assert_is_subclass(Slice, DataSetFamilySlice) expected_columns = { ('f8', np.dtype('f8'), Slice), ('i8', np.dtype('i8'), Slice), ('ob', np.dtype('O'), Slice), ('M8', np.dtype('M8[ns]'), Slice), ('boolean', np.dtype('?'), Slice), } actual_columns = { (c.name, c.dtype, c.dataset) for c in Slice.columns } assert_equal(actual_columns, expected_columns)
def test_compose(self): composed = compose_types(C, D) assert_is_subclass(composed, C) assert_is_subclass(composed, D)