def test_string_conversion_exact_float(self): self.assertEqual(Range(1.234), Range.sift('1.234'))
def test_string_conversion_at_least_float(self): self.assertEqual(Range(1.234, ...), Range.sift('1.234..'))
def test_string_conversion_at_most_int(self): self.assertEqual(Range(..., 2), Range.sift('..2'))
def test_string_conversion_from_to_int(self): self.assertEqual(Range(1, 2), Range.sift('1..2'))
def test_int_conversion(self): self.assertEqual(Range(1), Range.sift(1))
def test_string_conversion_at_least_int(self): self.assertEqual(Range(1, ...), Range.sift('1..'))
def test_list_conversion_at_most(self): self.assertEqual(Range(..., 2), Range.sift([..., 2]))
def __setitem__(self, key, value): value = Range.sift(value, None) if value is None: raise ValueError( 'Value {} cannot be converted to a valid range'.format(value)) super().__setitem__(key, value)
def test_tuple_conversion_from_to(self): self.assertEqual(Range(1, 2), Range.sift((1, 2)))
def test_list_conversion_at_least(self): self.assertEqual(Range(1, ...), Range.sift([1, ...]))
def test_tuple_conversion_at_most(self): self.assertEqual(Range(..., 2), Range.sift((..., 2)))
def test_tuple_conversion_at_least(self): self.assertEqual(Range(1, ...), Range.sift((1, ...)))
def test_float_conversion(self): self.assertEqual(Range(1.234), Range.sift(1.234))
def test_string_conversion_at_most_float(self): self.assertEqual(Range(..., 2.345), Range.sift('..2.345'))
def test_list_conversion_from_to(self): self.assertEqual(Range(1, 2), Range.sift([1, 2]))
def test_string_conversion_from_to_float(self): self.assertEqual(Range(1.234, 2.345), Range.sift('1.234..2.345'))
def test_string_conversion_exact_int(self): self.assertEqual(Range(1), Range.sift('1'))
def __init__( self, position: Position.Generic = None, x: Real = None, y: Real = None, z: Real = None, volume: Position.Generic = None, dx: Real = None, dy: Real = None, dz: Real = None, x_rotation: Range.Generic = None, y_rotation: Range.Generic = None, distance: Range.Generic = None, level: Range.Generic = None, type_: EntityID = None, not_types: RepeatableEntityID = None, name: str = None, not_names: RepeatableString = None, team: str = None, not_teams: RepeatableString = None, gamemode: Gamemode.Generic = None, not_gamemodes: RepeatableGamemode = None, tags: RepeatableString = None, not_tags: RepeatableString = None, nbts: RepeatableNBT = None, not_nbts: RepeatableNBT = None, scores: ScoreSet.Generic = None, advancements: AdvancementSet.Generic = None, sort: SelectorSort = None, limit: int = None, ): # Intermediates used for calculations. position = Position.sift(position, None) volume = Position.sift(volume, None) x = first(x, position.x if isinstance(position, Position) else None) y = first(y, position.y if isinstance(position, Position) else None) z = first(z, position.z if isinstance(position, Position) else None) dx = first(dx, volume.x if isinstance(volume, Position) else None) dy = first(dy, volume.y if isinstance(volume, Position) else None) dz = first(dz, volume.z if isinstance(volume, Position) else None) # Actual instance attributes. self.x: Optional[float] = nullable_float(x) self.y: Optional[float] = nullable_float(y) self.z: Optional[float] = nullable_float(z) self.dx: Optional[float] = nullable_float(dx) self.dy: Optional[float] = nullable_float(dy) self.dz: Optional[float] = nullable_float(dz) self.x_rotation: Optional[Range] = Range.sift(x_rotation, None) self.y_rotation: Optional[Range] = Range.sift(y_rotation, None) self.distance: Optional[Range] = Range.sift(distance, None) self.level: Optional[Range] = Range.sift(level, None) self.type_: Optional[EntityID] = nullable_str(type_) self.not_types: Optional[Tuple[EntityID]] = nullable_tuple( not_types, converter=EntityID.sift) self.name: Optional[str] = nullable_str(name) self.not_names: Optional[Tuple[str]] = nullable_tuple(not_names, converter=str) self.team: Optional[str] = nullable_str(team) self.not_teams: Optional[Tuple[str]] = nullable_tuple(not_teams, converter=str) self.gamemode: Optional[Gamemode] = Gamemode.sift(gamemode, None) self.not_gamemodes: Optional[Tuple[Gamemode]] = nullable_tuple( not_gamemodes, converter=Gamemode.sift) self.tags: Optional[Tuple[str]] = nullable_tuple(tags, converter=str) self.not_tags: Optional[Tuple[str]] = nullable_tuple(not_tags, converter=str) self.nbts: Optional[Tuple[CompoundDataTag]] = nullable_tuple( nbts, converter=CompoundDataTag.sift) self.not_nbts: Optional[Tuple[CompoundDataTag]] = nullable_tuple( not_nbts, converter=CompoundDataTag.sift) self.scores: Optional[ScoreSet] = ScoreSet.sift(scores, None) self.advancements: Optional[AdvancementSet] = AdvancementSet.sift( advancements, None) self.sort: Optional[SelectorSort] = SelectorSort.sift(sort, None) self.limit: Optional[int] = nullable_int(limit)
def test_zero_conversion(self): self.assertEqual(Range(0), Range.sift(0))