Exemple #1
0
def test_creation(unit):
    """Verify that a Mass Type instantiates with the properproperty values from inputs."""
    value = random.randint(0, 1000) / 10
    instance = MassType(value, unit)
    assert isinstance(instance, MassType)
    assert instance.value == value
    assert instance.as_(unit) == pytest.approx(value)
Exemple #2
0
def test_sucrose(amount, ftype, mashed, fyield, moisture, sucrose):
    """Verify the sucrose value for mashed and non-mashed fermentables."""
    fermentable = Fermentable(
        amount=MassType(amount, 'lb'),
        ftype=ftype,
        fyield=PercentType(fyield, '%'),
        moisture=PercentType(moisture, '%'),
        mashed=mashed,
    )

    assert fermentable.sucrose == pytest.approx(sucrose)
Exemple #3
0
def test_copy():
    """Ensure that the copy method makes a proper copy of the fermentable."""
    recipe = RecipeStub()

    original = Fermentable(
        recipe=recipe,
        name='Test',
        amount=MassType(1, 'lb'),
        ftype='Grain',
        group='Smoked',
        producer='Crisp',
        origin='UK',
        fyield=PercentType(68, '%'),
        color=ColorType(45, 'SRM'),
        moisture=PercentType(3, '%'),
        diastaticPower=DiastaticPowerType(4, 'Lintner'),
        addAfterBoil=False,
        mashed=True,
        notes='A note',
        phi=5.6,
        bi=43.2
    )

    newRecipe = RecipeStub()
    copy = original.copy(newRecipe)

    assert isinstance(copy, Fermentable)
    assert copy.recipe == newRecipe
    assert copy.name == 'Test'
    assert isinstance(copy.amount, MassType)
    assert copy.amount is not original.amount # Should be a new instance of MassType.
    assert copy.amount.lb == 1
    assert copy.ftype == 'Grain'
    assert copy.group == 'Smoked'
    assert copy.producer == 'Crisp'
    assert copy.origin == 'UK'
    assert copy.fyield is not original.fyield
    assert copy.fyield.percent == 68
    assert copy.color is not original.color
    assert copy.color.SRM == 45
    assert copy.moisture is not original.moisture
    assert copy.moisture.percent == 3
    assert copy.diastaticPower is not original.diastaticPower
    assert copy.diastaticPower.Lintner == 4
    assert copy.addAfterBoil is not None
    assert not copy.addAfterBoil
    assert copy.mashed is not None
    assert copy.mashed
    assert copy.notes == 'A note'
    assert copy.phi == 5.6
    assert copy.bi == 43.2
Exemple #4
0
def caramel_grain(recipe, pounds):
    return Fermentable(
        recipe=recipe,
        name='Caramel 20',
        amount=MassType(pounds, 'lb'),
        ftype='Grain',
        group='Caramel',
        producer='Generic',
        origin='N/A',
        fyield=PercentType(68, '%'),
        color=ColorType(20, 'SRM'),
        moisture=PercentType(3, '%'),
        diastaticPower=DiastaticPowerType(6, 'Lintner'),
        addAfterBoil=False,
        mashed=True,
        notes='Not a real grain type',
        phi=5.2,
        bi=56,
    )
Exemple #5
0
def test_to_dict():
    """Ensure that the to_dict method produces a dict with the expected values."""
    recipe = RecipeStub()
    fermentable = Fermentable(
        recipe=recipe,
        name='Test',
        amount=MassType(1, 'lb'),
        ftype='Grain',
        group='Smoked',
        producer='Crisp',
        origin='UK',
        fyield=PercentType(68, '%'),
        color=ColorType(45, 'SRM'),
        moisture=PercentType(3, '%'),
        diastaticPower=DiastaticPowerType(4, 'Lintner'),
        addAfterBoil=False,
        mashed=True,
        notes='A note\nSecond line',
        phi=5.6,
        bi=43.2
    )

    output = fermentable.to_dict()

    assert output['name'] == 'Test'
    assert output['type'] == 'grain'
    assert output['origin'] == 'UK'
    assert output['producer'] == 'Crisp'
    assert output['yield']['fine_grind']['value'] == 68
    assert output['yield']['fine_grind']['unit'] == '%'
    assert output['color']['value'] == 45
    assert output['color']['unit'] == 'SRM'
    assert output['amount']['value'] == 1
    assert output['amount']['unit'] == 'lb'
    assert output['notes'] == 'A note\\nSecond line'
    assert output['moisture']['value'] == 3
    assert output['moisture']['unit'] == '%'
    assert output['diastatic_power']['value'] == 4
    assert output['diastatic_power']['unit'] == 'Lintner'
    assert output['recommend_mash'] == True
    assert output['grain_group'] == 'smoked'
    assert output['phi'] == 5.6
    assert output['bi'] == 43.2
Exemple #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 fermentable so as to not modify the version in the library when working with recipe.
            fermentable = available.copy(self.recipe)

            # Initialize the properties that are required in ingredients but missing in the library of items.
            fermentable.amount = MassType(0, 'lb')

            # Add the new fermentable into the recipe.
            self.recipe.fermentables.append(fermentable)
Exemple #7
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)
Exemple #8
0
def test_proper_creation():
    recipe = RecipeStub()

    fermentable = Fermentable(
        recipe=recipe,
        name='Test Grain',
        amount=MassType(1, 'lb'),
        ftype='Grain',
        group='Base',
        producer='Generic',
        origin='US',
        fyield=PercentType(70, '%'),
        color=ColorType(2, 'SRM'),
        moisture=PercentType(6, '%'),
        diastaticPower=DiastaticPowerType(10, 'Lintner'),
        addAfterBoil=False,
        mashed=True,
        notes='Not a real grain type',
        phi=5.5,
        bi=50,
    )

    assert fermentable.name == 'Test Grain'
    assert isinstance(fermentable.amount, MassType)
    assert fermentable.amount.lb == 1
    assert fermentable.ftype == 'Grain'
    assert fermentable.group == 'Base'
    assert fermentable.group == 'Base'
    assert fermentable.origin == 'US'
    assert isinstance(fermentable.fyield, PercentType)
    assert fermentable.fyield.percent == 70
    assert isinstance(fermentable.color, ColorType)
    assert fermentable.color.SRM == 2
    assert isinstance(fermentable.moisture, PercentType)
    assert fermentable.moisture.percent == 6
    assert isinstance(fermentable.diastaticPower, DiastaticPowerType)
    assert fermentable.diastaticPower.Lintner == 10
    assert not fermentable.addAfterBoil
    assert fermentable.mashed
    assert fermentable.notes == 'Not a real grain type'
    assert fermentable.phi == 5.5
    assert fermentable.bi == 50
Exemple #9
0
def test_to_dict_optional():
    """Verify that the optional items are not set when a fermentable without explicit values is stored."""
    recipe = RecipeStub()
    fermentable = Fermentable(
        recipe=recipe,
        name='Test',
        amount=MassType(1, 'lb'),
        ftype='Extract',
        producer='Crisp',
        origin='UK',
        fyield=PercentType(68, '%'),
        color=ColorType(45, 'SRM'),
        moisture=PercentType(3, '%'),
        diastaticPower=DiastaticPowerType(4, 'Lintner'),
    )

    output = fermentable.to_dict()

    assert 'grain_group' not in output
    assert 'phi' not in output
    assert 'bi' not in output
Exemple #10
0
 def updateSalt(name, value, use, salts):
     """Local helper function to assist with the salt updates.  Handles both the mash and kettle salts."""
     if value > 0:
         # If there is a value greater than zero, then we want to update this misc ingredient amount.
         mass = MassType(value, 'g')
         if name in salts:
             # Salt already exists, lets just update the value.
             salts[name].amount = mass
         else:
             # Salt does not yet exist, need to add it as a new misc ingredient.
             timing = TimingType(use=use)
             misc = Miscellaneous(self.recipe,
                                  name,
                                  'Water Agent',
                                  timing=timing,
                                  amount=mass)
             self.recipe.misc.append(misc)
     else:
         # Value has been made zero.
         if name in salts:
             # If there was previously an entry, remove it from the ingredient list now.
             self.recipe.misc.pop(self.recipe.misc.indexOf(salts[name]))
Exemple #11
0
def test_conversion(inVal, inUnit, outVal, outUnit):
    """Verify appropriate conversions between types."""
    instance = MassType(inVal, inUnit)
    result = instance.as_(outUnit)
    assert result == pytest.approx(outVal)
Exemple #12
0
 def mashWeight(self) -> MassType:
     """Returns the combined weight of all of the mashed ingredients."""
     return sum([item.amount for item in self.items if item.isMashed],
                MassType(0, 'lb'))