Пример #1
0
 def test_list_conversion_from_to(self):
     self.assertEqual(Range(1, 2), Range.sift([1, 2]))
Пример #2
0
 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)
Пример #3
0
 def test_at_most_int(self):
     self.assertEqual('..2', str(Range(..., 2)))
Пример #4
0
 def test_string_conversion_at_least_float(self):
     self.assertEqual(Range(1.234, ...), Range.sift('1.234..'))
Пример #5
0
 def test_string_conversion_from_to_float(self):
     self.assertEqual(Range(1.234, 2.345), Range.sift('1.234..2.345'))
Пример #6
0
 def test_string_conversion_at_least_int(self):
     self.assertEqual(Range(1, ...), Range.sift('1..'))
Пример #7
0
 def test_string_conversion_from_to_int(self):
     self.assertEqual(Range(1, 2), Range.sift('1..2'))
Пример #8
0
 def test_zero_conversion(self):
     self.assertEqual(Range(0), Range.sift(0))
Пример #9
0
 def test_int_conversion(self):
     self.assertEqual(Range(1), Range.sift(1))
Пример #10
0
 def test_at_most_float(self):
     self.assertEqual('..2.345', str(Range(..., 2.345)))
Пример #11
0
 def test_from_to_float(self):
     self.assertEqual('1.234..2.345', str(Range(1.234, 2.345)))
Пример #12
0
 def test_at_least_float(self):
     self.assertEqual('1.234..', str(Range(1.234, ...)))
Пример #13
0
 def test_exact_float(self):
     self.assertEqual('1.234', str(Range(1.234)))
Пример #14
0
 def test_from_to_int(self):
     self.assertEqual('1..2', str(Range(1, 2)))
Пример #15
0
 def test_undefined(self):
     self.assertEqual('..', str(Range(...)))
Пример #16
0
 def test_float_conversion(self):
     self.assertEqual(Range(1.234), Range.sift(1.234))
Пример #17
0
 def test_string_conversion_exact_int(self):
     self.assertEqual(Range(1), Range.sift('1'))
Пример #18
0
 def test_tuple_conversion_at_least(self):
     self.assertEqual(Range(1, ...), Range.sift((1, ...)))
Пример #19
0
 def test_string_conversion_at_most_int(self):
     self.assertEqual(Range(..., 2), Range.sift('..2'))
Пример #20
0
 def test_tuple_conversion_at_most(self):
     self.assertEqual(Range(..., 2), Range.sift((..., 2)))
Пример #21
0
 def test_string_conversion_exact_float(self):
     self.assertEqual(Range(1.234), Range.sift('1.234'))
Пример #22
0
 def test_tuple_conversion_from_to(self):
     self.assertEqual(Range(1, 2), Range.sift((1, 2)))
Пример #23
0
 def test_string_conversion_at_most_float(self):
     self.assertEqual(Range(..., 2.345), Range.sift('..2.345'))
Пример #24
0
 def test_list_conversion_at_least(self):
     self.assertEqual(Range(1, ...), Range.sift([1, ...]))
Пример #25
0
 def test_exact_int(self):
     self.assertEqual('1', str(Range(1)))
Пример #26
0
 def test_list_conversion_at_most(self):
     self.assertEqual(Range(..., 2), Range.sift([..., 2]))
Пример #27
0
    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)
Пример #28
0
 def test_at_least_int(self):
     self.assertEqual('1..', str(Range(1, ...)))