예제 #1
0
def test_creation(unit):
    """Verify that a Time Type instantiates with the properproperty values from inputs."""
    value = random.randint(0, 1000) / 10
    instance = TimeType(value, unit)
    assert isinstance(instance, TimeType)
    assert instance.value == value
    assert instance.as_(unit) == pytest.approx(value)
예제 #2
0
 def from_dict(self, data):
     """Convert a BeerJSON dict into values for this instance."""
     self.name = data['name']
     self.mtype = data['type'].title()
     if 'step_temperature' in data:
         self.temperature = TemperatureType(json=data['step_temperature'])
     if 'step_time' in data:
         self.time = TimeType(json=data['step_time'])
예제 #3
0
    def on_add(self):
        """Fires when the user clicks the add button."""
        step = MashStep(self.recipe)

        count = len(self.recipe.mash)
        step.name = f'Rest {count + 1}'
        step.mtype = 'Infusion'
        step.time = TimeType(0, 'min')

        self.recipe.mash.append(step)
예제 #4
0
 def from_dict(self, data):
     """Convert a BeerJSON dict into values for this instance."""
     self.name = data['name']
     if 'start_temperature' in data:
         self.startTemperature = TemperatureType(
             json=data['start_temperature'])
     if 'end_temperature' in data:
         self.endTemperature = TemperatureType(json=data['end_temperature'])
     if 'step_time' in data:
         self.time = TimeType(json=data['step_time'])
예제 #5
0
    def from_dict(self, data):
        """Load the provided data from a BeerJSON dictionary into this instance."""
        if 'time' in data:
            self.time = TimeType(json=data['time'])

        if 'duration' in data:
            self.duration = TimeType(json=data['duration'])

        if 'continuous' in data:
            self.continuous = bool(data['continuous'])

        if 'specific_gravity' in data:
            self.continuous = GravityType(json=data['specific_gravity'])

        if 'pH' in data:
            self.pH = AcidityType(json=data['pH'])

        if 'step' in data:
            self.step = int(data['step'])

        if 'use' in data:
            self.use = data['use'].replace('add_to_', '').title()
예제 #6
0
    def on_add(self):
        """Fires when the user clicks the add button."""
        # Iterate though the selection(s) the user has made.
        for index in self.ui.library.selectedIndexes():
            # We get an index for each cell, lets filter down to a single column so that we can focus on row indexes.
            if index.column() != 0:
                continue

            # Get the data through the proxy as the indexes don't align with the library when filtering.
            available = self.proxy.data(index, QtCore.Qt.UserRole)

            # Make a copy of the hop so as to not modify the version in the library when working with recipe.
            hop = available.copy(self.recipe)

            hop.timing = TimingType(use='Boil', duration=TimeType(0, 'min'))
            hop.amount = MassType(0, 'oz')

            # Add the new hop into the recipe.
            self.recipe.hops.append(hop)
예제 #7
0
def test_conversion(inVal, inUnit, outVal, outUnit, tolerance):
    """Verify appropriate conversions between types."""
    instance = TimeType(inVal, inUnit)
    result = instance.as_(outUnit)
    assert result == pytest.approx(outVal, tolerance)
예제 #8
0
class TimingType:
    """Represents a BeerJSON TimingType instance providing for timing on ingredients such as fermentables and hops."""

    def __init__(self, time=None, duration=None, continuous=None, specificGravity=None, pH=None, step=None, use=None):
        self._use = None

        self.time: TimeType = time
        self.duration: TimeType = duration
        self.continuous: bool = continuous
        self.specificGravity = specificGravity
        self.pH = pH
        self.step: int = step
        self.use: str = use



# ======================================================================================================================
# Properties
# ----------------------------------------------------------------------------------------------------------------------
    @property
    def use(self):
        """Get the current use value."""
        return self._use

# ----------------------------------------------------------------------------------------------------------------------
    @use.setter
    def use(self, value):
        """Set the use value - but ensure that it is valid."""
        if value is not None and value not in ['Mash', 'Boil', 'Fermentation', 'Package']:
            raise ValueError(f'Timing.use does not support value "{value}"')
        self._use = value



# ======================================================================================================================
# Methods
# ----------------------------------------------------------------------------------------------------------------------
    def to_dict(self):
        """Convert this instance into a BeerJSON compatible dictionary of values."""
        data = {}

        if self.time is not None:
            data['time'] = self.time.to_dict()

        if self.duration is not None:
            data['duration'] = self.duration.to_dict()

        if self.continuous is not None:
            data['continuous'] = self.continuous

        if self.specificGravity is not None:
            data['specific_gravity'] = self.specificGravity.to_dict()

        if self.pH is not None:
            data['pH'] = self.pH.to_dict()

        if self.step is not None:
            data['step'] = self.step.to_dict()

        if self.use is not None:
            data['use'] = 'add_to_' + self.use.lower()

        return data


# ----------------------------------------------------------------------------------------------------------------------
    def from_dict(self, data):
        """Load the provided data from a BeerJSON dictionary into this instance."""
        if 'time' in data:
            self.time = TimeType(json=data['time'])

        if 'duration' in data:
            self.duration = TimeType(json=data['duration'])

        if 'continuous' in data:
            self.continuous = bool(data['continuous'])

        if 'specific_gravity' in data:
            self.continuous = GravityType(json=data['specific_gravity'])

        if 'pH' in data:
            self.pH = AcidityType(json=data['pH'])

        if 'step' in data:
            self.step = int(data['step'])

        if 'use' in data:
            self.use = data['use'].replace('add_to_', '').title()


# ----------------------------------------------------------------------------------------------------------------------
    def copy(self):
        """Return a new instance with the same numerical values."""
        new = TimingType()

        if self.time is not None:
            new.time = self.time.copy()

        if self.duration is not None:
            new.duration = self.duration.copy()

        if self.continuous is not None:
            new.continuous = self.continuous

        if self.specificGravity is not None:
            new.specific_gravity = self.specificGravity.copy()

        if self.pH is not None:
            new.pH = self.pH.copy()

        if self.step is not None:
            new.step = self.step.copy()

        if self.use is not None:
            new.use = self.use

        return new
예제 #9
0
 def on_add(self):
     """Fires when the user clicks the add button."""
     misc = Miscellaneous(self.recipe)
     misc.amount = UnitType(1, 'each')
     misc.timing = TimingType(duration=TimeType(0, 'min'))
     self.recipe.misc.append(misc)