Ejemplo n.º 1
0
	def value(self, value):
		if self.type in {int, float, bool, str}:
			self._value = self.type(value)
		
		# Special case for datetime
		elif self.type == datetime:
			if isinstance(value, datetime.datetime):
				self._value = value.timestamp()
			elif isinstance(value, str):
				self._value = datetime.datetime.strptime(value, "%d/%m/%Y %H:%M:%S").timestamp()
			elif isinstance(value, (int, float)):
				self._value = value
		
		# Special case for directories
		elif self.type == dir:
			if isinstance(value, str):
				self._value = pathlib.Path(value)
			else:
				self._value = value
		
		elif self.type == tuple:
			if isinstance(value, str):
				self._value = str2tuple(value)
			elif isinstance(value, list):
				self._value = tuple(value)
			elif isinstance(value, tuple):
				self._value = value
			else:
				raise TypeError(f"'{self.name}' must be a list, tuple or comma-separated string")
Ejemplo n.º 2
0
	def mass_range(self, value):
		"""
		Sets the value for the mass range

		This must be small enough to encompass all samples

		:param value: Mass Range
		:type value: list, tuple or comma-separated string
		"""

		if isinstance(value, str):
			self._mass_range = str2tuple(value)
		elif isinstance(value, list):
			self._mass_range = tuple(value)
		elif isinstance(value, tuple):
			self._mass_range = value
		else:
			raise TypeError("'mass_range' must be a list, tuple or comma-separated string")
Ejemplo n.º 3
0
 def test_str2tuple_semicolon(self, value, expects):
     assert isinstance(str2tuple(value, sep=';'), tuple)
     assert str2tuple(value, sep=';') == expects
Ejemplo n.º 4
0
 def test_str2tuple(self, value, expects):
     assert isinstance(str2tuple(value), tuple)
     assert str2tuple(value) == expects