diff --git a/brew/cli/abv.py b/brew/cli/abv.py index 28beec8..bd26f6e 100644 --- a/brew/cli/abv.py +++ b/brew/cli/abv.py @@ -11,13 +11,16 @@ from brew.utilities.sugar import refractometer_adjustment -def get_abv(og, fg, - og_temp=HYDROMETER_ADJUSTMENT_TEMP, - fg_temp=HYDROMETER_ADJUSTMENT_TEMP, - alternative=False, - refractometer=False, - units=IMPERIAL_UNITS, - verbose=False): +def get_abv( + og, + fg, + og_temp=HYDROMETER_ADJUSTMENT_TEMP, + fg_temp=HYDROMETER_ADJUSTMENT_TEMP, + alternative=False, + refractometer=False, + units=IMPERIAL_UNITS, + verbose=False, +): """ Get Alcohol by Volume for CLI Utility @@ -41,8 +44,9 @@ def get_abv(og, fg, raise Exception(u"Original Gravity must be higher than Final Gravity") if units not in [IMPERIAL_UNITS, SI_UNITS]: - raise Exception(u"Units must be in either {} or {}".format(IMPERIAL_UNITS, # noqa - SI_UNITS)) + raise Exception( + u"Units must be in either {} or {}".format(IMPERIAL_UNITS, SI_UNITS) # noqa + ) # Adjust the gravity based on temperature og = hydrometer_adjustment(og, og_temp, units=units) @@ -60,7 +64,7 @@ def get_abv(og, fg, if verbose: out = [] - t_unit = u'F' if units == IMPERIAL_UNITS else u'C' + t_unit = u"F" if units == IMPERIAL_UNITS else u"C" out.append(u"OG : {:0.3f}".format(og)) out.append(u"OG Adj : {:0.3f}".format(og)) out.append(u"OG Temp: {:0.2f} {}".format(og_temp, t_unit)) @@ -68,37 +72,62 @@ def get_abv(og, fg, out.append(u"FG Adj : {:0.3f}".format(fg)) out.append(u"FG Temp: {:0.2f} {}".format(fg_temp, t_unit)) out.append(u"ABV : {:0.2%}".format(abv)) - return u'\n'.join(out) + return u"\n".join(out) else: return abv def get_parser(): - parser = argparse.ArgumentParser(description=u'ABV Calculator') - parser.add_argument(u'-o', u'--og', metavar=u'O', type=float, - required=True, - help=u'Original Gravity') - parser.add_argument(u'-f', u'--fg', metavar=u'F', type=float, - required=True, - help=u'Final Gravity') - parser.add_argument(u'--og-temp', metavar=u'T', type=float, - default=HYDROMETER_ADJUSTMENT_TEMP, - help=u'Original Gravity Temperature (default: %(default)s)') # noqa - parser.add_argument(u'--fg-temp', metavar=u'T', type=float, - default=HYDROMETER_ADJUSTMENT_TEMP, - help=u'Final Gravity Temperature (default: %(default)s)') # noqa - parser.add_argument(u'-a', u'--alternative', action=u'store_true', - default=False, - help=u'Use alternative ABV equation') - parser.add_argument(u'-r', u'--refractometer', action=u'store_true', - default=False, - help=u'Adjust the Final Gravity if using a Refractometer reading') # noqa - parser.add_argument(u'--units', metavar=u"U", type=str, - default=IMPERIAL_UNITS, - help=u'Units to use (default: %(default)s)') - parser.add_argument(u'-v', u'--verbose', action=u'store_true', - default=False, - help=u'Verbose Output') + parser = argparse.ArgumentParser(description=u"ABV Calculator") + parser.add_argument( + u"-o", + u"--og", + metavar=u"O", + type=float, + required=True, + help=u"Original Gravity", + ) + parser.add_argument( + u"-f", u"--fg", metavar=u"F", type=float, required=True, help=u"Final Gravity" + ) + parser.add_argument( + u"--og-temp", + metavar=u"T", + type=float, + default=HYDROMETER_ADJUSTMENT_TEMP, + help=u"Original Gravity Temperature (default: %(default)s)", + ) # noqa + parser.add_argument( + u"--fg-temp", + metavar=u"T", + type=float, + default=HYDROMETER_ADJUSTMENT_TEMP, + help=u"Final Gravity Temperature (default: %(default)s)", + ) # noqa + parser.add_argument( + u"-a", + u"--alternative", + action=u"store_true", + default=False, + help=u"Use alternative ABV equation", + ) + parser.add_argument( + u"-r", + u"--refractometer", + action=u"store_true", + default=False, + help=u"Adjust the Final Gravity if using a Refractometer reading", + ) # noqa + parser.add_argument( + u"--units", + metavar=u"U", + type=str, + default=IMPERIAL_UNITS, + help=u"Units to use (default: %(default)s)", + ) + parser.add_argument( + u"-v", u"--verbose", action=u"store_true", default=False, help=u"Verbose Output" + ) return parser @@ -110,13 +139,16 @@ def main(parser_fn=get_parser, parser_kwargs=None): parser = parser_fn(**parser_kwargs) args = parser.parse_args() try: - out = get_abv(args.og, args.fg, - og_temp=args.og_temp, - fg_temp=args.fg_temp, - alternative=args.alternative, - refractometer=args.refractometer, - units=args.units, - verbose=args.verbose) + out = get_abv( + args.og, + args.fg, + og_temp=args.og_temp, + fg_temp=args.fg_temp, + alternative=args.alternative, + refractometer=args.refractometer, + units=args.units, + verbose=args.verbose, + ) if args.verbose: print(out) else: diff --git a/brew/cli/gravity_volume.py b/brew/cli/gravity_volume.py index 3d5d769..974df04 100644 --- a/brew/cli/gravity_volume.py +++ b/brew/cli/gravity_volume.py @@ -14,13 +14,26 @@ def get_gravity(original_volume, final_volume, gravity): def get_parser(): - parser = argparse.ArgumentParser(description=u'Gravity-Volume Conversion') - parser.add_argument(u'-o', u'--original-volume', metavar=u'V', type=float, - required=True, help=u'Original Volume') - parser.add_argument(u'-f', u'--final-volume', metavar=u'V', type=float, - required=True, help=u'Final Volume') - parser.add_argument(u'-g', u'--gravity', metavar=u'G', type=float, - required=True, help=u'Gravity') + parser = argparse.ArgumentParser(description=u"Gravity-Volume Conversion") + parser.add_argument( + u"-o", + u"--original-volume", + metavar=u"V", + type=float, + required=True, + help=u"Original Volume", + ) + parser.add_argument( + u"-f", + u"--final-volume", + metavar=u"V", + type=float, + required=True, + help=u"Final Volume", + ) + parser.add_argument( + u"-g", u"--gravity", metavar=u"G", type=float, required=True, help=u"Gravity" + ) return parser @@ -31,14 +44,10 @@ def main(parser_fn=get_parser, parser_kwargs=None): else: parser = parser_fn(**parser_kwargs) args = parser.parse_args() - if not all([args.original_volume, - args.final_volume, - args.gravity]): + if not all([args.original_volume, args.final_volume, args.gravity]): print("Please provide all arguments") sys.exit(1) - out = get_gravity(args.original_volume, - args.final_volume, - args.gravity) + out = get_gravity(args.original_volume, args.final_volume, args.gravity) print("{:0.3f}".format(out)) diff --git a/brew/cli/sugar.py b/brew/cli/sugar.py index 50dd1e3..93784eb 100644 --- a/brew/cli/sugar.py +++ b/brew/cli/sugar.py @@ -37,30 +37,42 @@ def get_sugar_conversion(brix_in, plato_in, sg_in, sugar_out): brix = round(brix, 1) plato = round(plato, 1) sg = round(sg, 3) - if sugar_out and sugar_out in [u'b', u'p', u's']: - if sugar_out == u'b': + if sugar_out and sugar_out in [u"b", u"p", u"s"]: + if sugar_out == u"b": return brix - elif sugar_out == u'p': + elif sugar_out == u"p": return plato - elif sugar_out == u's': + elif sugar_out == u"s": return sg else: - out = textwrap.dedent(u"""\ + out = textwrap.dedent( + u"""\ SG\tPlato\tBrix - {:0.3f}\t{:0.1f}\t{:0.1f}""".format(sg, plato, brix)) + {:0.3f}\t{:0.1f}\t{:0.1f}""".format( + sg, plato, brix + ) + ) return out def get_parser(): - parser = argparse.ArgumentParser(description=u'Sugar Conversion') - parser.add_argument(u'-b', u'--brix', metavar=u'B', type=float, - help=u'Degrees Brix') - parser.add_argument(u'-p', u'--plato', metavar=u'P', type=float, - help=u'Degrees Plato') - parser.add_argument(u'-s', u'--sg', metavar=u'S', type=float, - help=u'Specific Gravity') - parser.add_argument(u'-o', u'--out', metavar=u'O', type=str, - help=u'Desired Output (b, p, s accepted)') + parser = argparse.ArgumentParser(description=u"Sugar Conversion") + parser.add_argument( + u"-b", u"--brix", metavar=u"B", type=float, help=u"Degrees Brix" + ) + parser.add_argument( + u"-p", u"--plato", metavar=u"P", type=float, help=u"Degrees Plato" + ) + parser.add_argument( + u"-s", u"--sg", metavar=u"S", type=float, help=u"Specific Gravity" + ) + parser.add_argument( + u"-o", + u"--out", + metavar=u"O", + type=str, + help=u"Desired Output (b, p, s accepted)", + ) return parser diff --git a/brew/cli/temp.py b/brew/cli/temp.py index 5d33ab3..0cb9da4 100644 --- a/brew/cli/temp.py +++ b/brew/cli/temp.py @@ -17,11 +17,17 @@ def get_temp_conversion(fahrenheit, celsius): def get_parser(): - parser = argparse.ArgumentParser(description=u'Temperature Conversion') - parser.add_argument(u'-c', u'--celsius', metavar=u'C', type=float, - help=u'Temperature in Celsius') - parser.add_argument(u'-f', u'--fahrenheit', metavar=u'F', type=float, - help=u'Temperature in Fahrenheit') + parser = argparse.ArgumentParser(description=u"Temperature Conversion") + parser.add_argument( + u"-c", u"--celsius", metavar=u"C", type=float, help=u"Temperature in Celsius" + ) + parser.add_argument( + u"-f", + u"--fahrenheit", + metavar=u"F", + type=float, + help=u"Temperature in Fahrenheit", + ) return parser diff --git a/brew/cli/yeast.py b/brew/cli/yeast.py index 9dc8a7c..aa06ec4 100644 --- a/brew/cli/yeast.py +++ b/brew/cli/yeast.py @@ -19,31 +19,35 @@ def get_yeast_pitch_calculation( - model_cls=WhiteYeastModel, - method=u'stir plate', - og=1.05, - fv=5.0, - sg=1.036, - sv=0.53, - target_pitch_rate=1.42, - yeast_type=u'liquid', - cells=100, - num=1, - days=0, - units=IMPERIAL_UNITS): + model_cls=WhiteYeastModel, + method=u"stir plate", + og=1.05, + fv=5.0, + sg=1.036, + sv=0.53, + target_pitch_rate=1.42, + yeast_type=u"liquid", + cells=100, + num=1, + days=0, + units=IMPERIAL_UNITS, +): msg_list = [] model = model_cls(method, units=units) - data = model.get_yeast_pitch_rate(original_gravity=og, - final_volume=fv, - target_pitch_rate=target_pitch_rate, - yeast_type=yeast_type, - cells_per_pack=cells, - num_packs=num, - days_since_manufacture=days) - cells_needed = data[u'cells_needed'] + data = model.get_yeast_pitch_rate( + original_gravity=og, + final_volume=fv, + target_pitch_rate=target_pitch_rate, + yeast_type=yeast_type, + cells_per_pack=cells, + num_packs=num, + days_since_manufacture=days, + ) + cells_needed = data[u"cells_needed"] data.update(model.types) - msg = textwrap.dedent(u"""\ + msg = textwrap.dedent( + u"""\ Yeast Pitch Calculator ----------------------------------- Original Gravity {original_gravity:0.3f} @@ -55,19 +59,23 @@ def get_yeast_pitch_calculation( Pitch Rate Cells {pitch_rate_cells:0.0f} B Cells Needed {cells_needed} B Required Growth Rate {required_growth_rate} - Units {units}""".format(**data)) + Units {units}""".format( + **data + ) + ) msg_list.append(msg) - if data[u'cells'] <= 0: + if data[u"cells"] <= 0: msg_list.append(u"\nNo cells available for further calculation") - return u'\n'.join(msg_list) + return u"\n".join(msg_list) - data = model.get_starter_volume(available_cells=data[u'cells'], - starter_volume=sv, - original_gravity=sg) - end_cell_count = data[u'end_cell_count'] + data = model.get_starter_volume( + available_cells=data[u"cells"], starter_volume=sv, original_gravity=sg + ) + end_cell_count = data[u"end_cell_count"] data.update(model.types) - msg = textwrap.dedent(u"""\ + msg = textwrap.dedent( + u"""\ Starter Volume ----------------------------------- @@ -78,7 +86,10 @@ def get_yeast_pitch_calculation( Inoculation Rate {inoculation_rate} Growth Rate {growth_rate} End Cell Count {end_cell_count} B - Units {units}""".format(**data)) + Units {units}""".format( + **data + ) + ) msg_list.append(msg) if cells_needed < end_cell_count: @@ -87,11 +98,11 @@ def get_yeast_pitch_calculation( msg_list.append(u"\nStarter DOES NOT HAVE enough cells") resulting_pitch_rate = model.get_resulting_pitch_rate( - starter_cell_count=end_cell_count, - original_gravity=sg, - final_volume=fv) + starter_cell_count=end_cell_count, original_gravity=sg, final_volume=fv + ) data.update(model.types) - msg = textwrap.dedent(u"""\ + msg = textwrap.dedent( + u"""\ Resulting Pitch Rate ----------------------------------- @@ -99,53 +110,106 @@ def get_yeast_pitch_calculation( Original Gravity {original_gravity} Final Volume {final_volume} {volume} Pitch Rate {resulting_pitch_rate}""".format( - starter_cell_count=end_cell_count, - original_gravity=sg, - final_volume=fv, - resulting_pitch_rate=resulting_pitch_rate, - **model.types)) + starter_cell_count=end_cell_count, + original_gravity=sg, + final_volume=fv, + resulting_pitch_rate=resulting_pitch_rate, + **model.types + ) + ) msg_list.append(msg) - return(u'\n'.join(msg_list)) + return u"\n".join(msg_list) def get_parser(): - parser = argparse.ArgumentParser(description=u'Yeast Pitch Calculator') - parser.add_argument(u'--og', metavar=u'O', type=float, - default=1.05, - help=u'Wort Original Gravity (default: %(default)s)') - parser.add_argument(u'--fv', metavar=u'V', type=float, - default=5.0, - help=u'Wort Final Volume (default: %(default)s)') - parser.add_argument(u'--sg', metavar=u'O', type=float, - default=1.036, - help=u'Starter Original Gravity (default: %(default)s)') # noqa - parser.add_argument(u'--sv', metavar=u'V', type=float, - default=2.0 * GAL_PER_LITER, - help=u'Starter Volume (default: %(default)s)') - parser.add_argument(u'--target-pitch-rate', metavar=u'T', type=float, - default=1.42, - help=u'Target Pitch Rate (default: %(default)s)') - parser.add_argument(u'--type', metavar=u'T', type=str, - default=u'liquid', - help=u'Yeast Type (default: %(default)s)') - parser.add_argument(u'-c', u'--cells', metavar=u'C', type=int, - default=100, - help=u'Number of cells per container in Billions') - parser.add_argument(u'-n', u'--num', metavar=u'N', type=int, - default=1, - help=u'Number of containers (default: %(default)s)') - parser.add_argument(u'-d', u'--days', metavar=u'D', type=int, - default=0, - help=u'Number of days since yeast manufacture (default: %(default)s)') # noqa - parser.add_argument(u'--model', metavar=u'M', type=str, - default=u'white', - help=u'Model of yeast growth, white or kaiser (default: %(default)s)') # noqa - parser.add_argument(u'--method', metavar=u'M', type=str, - default=u'stir plate', - help=u'Method of growth (default: %(default)s)') # noqa - parser.add_argument(u'--units', metavar=u'U', type=str, - default=IMPERIAL_UNITS, - help=u'Units to use (default: %(default)s)') + parser = argparse.ArgumentParser(description=u"Yeast Pitch Calculator") + parser.add_argument( + u"--og", + metavar=u"O", + type=float, + default=1.05, + help=u"Wort Original Gravity (default: %(default)s)", + ) + parser.add_argument( + u"--fv", + metavar=u"V", + type=float, + default=5.0, + help=u"Wort Final Volume (default: %(default)s)", + ) + parser.add_argument( + u"--sg", + metavar=u"O", + type=float, + default=1.036, + help=u"Starter Original Gravity (default: %(default)s)", + ) # noqa + parser.add_argument( + u"--sv", + metavar=u"V", + type=float, + default=2.0 * GAL_PER_LITER, + help=u"Starter Volume (default: %(default)s)", + ) + parser.add_argument( + u"--target-pitch-rate", + metavar=u"T", + type=float, + default=1.42, + help=u"Target Pitch Rate (default: %(default)s)", + ) + parser.add_argument( + u"--type", + metavar=u"T", + type=str, + default=u"liquid", + help=u"Yeast Type (default: %(default)s)", + ) + parser.add_argument( + u"-c", + u"--cells", + metavar=u"C", + type=int, + default=100, + help=u"Number of cells per container in Billions", + ) + parser.add_argument( + u"-n", + u"--num", + metavar=u"N", + type=int, + default=1, + help=u"Number of containers (default: %(default)s)", + ) + parser.add_argument( + u"-d", + u"--days", + metavar=u"D", + type=int, + default=0, + help=u"Number of days since yeast manufacture (default: %(default)s)", + ) # noqa + parser.add_argument( + u"--model", + metavar=u"M", + type=str, + default=u"white", + help=u"Model of yeast growth, white or kaiser (default: %(default)s)", + ) # noqa + parser.add_argument( + u"--method", + metavar=u"M", + type=str, + default=u"stir plate", + help=u"Method of growth (default: %(default)s)", + ) # noqa + parser.add_argument( + u"--units", + metavar=u"U", + type=str, + default=IMPERIAL_UNITS, + help=u"Units to use (default: %(default)s)", + ) return parser @@ -159,17 +223,20 @@ def main(parser_fn=get_parser, parser_kwargs=None): # Check on output if args.units not in [IMPERIAL_UNITS, SI_UNITS]: - print(u"Units must be in either {} or {}".format(IMPERIAL_UNITS, - SI_UNITS)) + print(u"Units must be in either {} or {}".format(IMPERIAL_UNITS, SI_UNITS)) sys.exit(1) model_cls = None - if args.model == u'white': + if args.model == u"white": model_cls = WhiteYeastModel - elif args.model == u'kaiser': + elif args.model == u"kaiser": model_cls = KaiserYeastModel else: - print(u"Unknown Yeast Growth Model '{}', must be 'white' or 'kaiser'".format(args.model)) # noqa + print( + u"Unknown Yeast Growth Model '{}', must be 'white' or 'kaiser'".format( + args.model + ) + ) # noqa sys.exit(1) try: @@ -185,7 +252,8 @@ def main(parser_fn=get_parser, parser_kwargs=None): cells=args.cells, num=args.num, days=args.days, - units=args.units) + units=args.units, + ) print(out) except Exception as e: print(e) diff --git a/brew/constants.py b/brew/constants.py index 8caa107..a476daf 100644 --- a/brew/constants.py +++ b/brew/constants.py @@ -2,36 +2,36 @@ # Unit Types #: Imperial Units -IMPERIAL_UNITS = u'imperial' +IMPERIAL_UNITS = u"imperial" #: SI or Metric Units -SI_UNITS = u'metric' +SI_UNITS = u"metric" #: Imperial unit types IMPERIAL_TYPES = { - u'volume': u'gallon', - u'weight_large': u'lbs', - u'weight_small': u'oz', - u'temperature': u'degF', + u"volume": u"gallon", + u"weight_large": u"lbs", + u"weight_small": u"oz", + u"temperature": u"degF", } #: SI unit types SI_TYPES = { - u'volume': u'liter', - u'weight_large': u'kg', - u'weight_small': u'mg', - u'temperature': u'degC', + u"volume": u"liter", + u"weight_large": u"kg", + u"weight_small": u"mg", + u"temperature": u"degC", } # Grains #: Grain type cereal -GRAIN_TYPE_CEREAL = u'cereal' +GRAIN_TYPE_CEREAL = u"cereal" #: Grain type specialty -GRAIN_TYPE_SPECIALTY = u'specialty' +GRAIN_TYPE_SPECIALTY = u"specialty" #: Grain type DME -GRAIN_TYPE_DME = u'dme' +GRAIN_TYPE_DME = u"dme" #: Grain type LME -GRAIN_TYPE_LME = u'lme' +GRAIN_TYPE_LME = u"lme" #: Grain type list GRAIN_TYPE_LIST = [ GRAIN_TYPE_CEREAL, @@ -43,20 +43,15 @@ # Hops #: Hop type pellet -HOP_TYPE_PELLET = u'pellet' +HOP_TYPE_PELLET = u"pellet" #: Hop type whole leaf -HOP_TYPE_WHOLE = u'whole' +HOP_TYPE_WHOLE = u"whole" #: Hop type whole leaf, wet -HOP_TYPE_WHOLE_WET = u'whole wet' +HOP_TYPE_WHOLE_WET = u"whole wet" #: Hop type plug -HOP_TYPE_PLUG = u'plug' +HOP_TYPE_PLUG = u"plug" #: Hop type list -HOP_TYPE_LIST = [ - HOP_TYPE_PELLET, - HOP_TYPE_WHOLE, - HOP_TYPE_WHOLE_WET, - HOP_TYPE_PLUG, -] +HOP_TYPE_LIST = [HOP_TYPE_PELLET, HOP_TYPE_WHOLE, HOP_TYPE_WHOLE_WET, HOP_TYPE_PLUG] # Hop utilization scale factors #: Hop utilization scale factor for pellets @@ -97,11 +92,11 @@ # Elevation #: Elevation at Sea Level in feet or meters -ELEVATION_SEA_LEVEL = 0 # feet or meters +ELEVATION_SEA_LEVEL = 0 # feet or meters #: Elevation at one mile high in feet ELEVATION_MILE_HIGH = 5280 # feet #: Elevation at one kilometer high in meters -ELEVATION_KM_HIGH = 1000 # meters +ELEVATION_KM_HIGH = 1000 # meters # Grind Constants # fine/coarse difference percentage for different grain in decimal format diff --git a/brew/exceptions.py b/brew/exceptions.py index 9f40d51..69f8181 100644 --- a/brew/exceptions.py +++ b/brew/exceptions.py @@ -1,16 +1,16 @@ # -*- coding: utf-8 -*- __all__ = [ - u'BrewdayException', - u'ColorException', - u'DataLoaderException', - u'GrainException', - u'HopException', - u'RecipeException', - u'StyleException', - u'SugarException', - u'ValidatorException', - u'YeastException', + u"BrewdayException", + u"ColorException", + u"DataLoaderException", + u"GrainException", + u"HopException", + u"RecipeException", + u"StyleException", + u"SugarException", + u"ValidatorException", + u"YeastException", ] diff --git a/brew/grains.py b/brew/grains.py index 2d0df12..376ae48 100644 --- a/brew/grains.py +++ b/brew/grains.py @@ -25,7 +25,7 @@ from .validators import validate_required_fields from .validators import validate_units -__all__ = [u'Grain', u'GrainAddition'] +__all__ = [u"Grain", u"GrainAddition"] class Grain(object): @@ -33,10 +33,7 @@ class Grain(object): A representation of a type of grain. """ - def __init__(self, name, - color=None, - ppg=None, - hwe=None): + def __init__(self, name, color=None, ppg=None, hwe=None): """ :param str name: The name of the grain :param float color: The color of the grain in SRM @@ -48,12 +45,12 @@ def __init__(self, name, """ self.name = name if color is None: - raise GrainException(u"{}: Must provide color value".format( - self.name)) + raise GrainException(u"{}: Must provide color value".format(self.name)) self.color = float(color) if ppg and hwe: - raise GrainException(u"{}: Cannot provide both ppg and hwe".format( - self.name)) + raise GrainException( + u"{}: Cannot provide both ppg and hwe".format(self.name) + ) if ppg: self.ppg = float(ppg) self.hwe = ppg_to_hwe(self.ppg) @@ -61,14 +58,13 @@ def __init__(self, name, self.hwe = float(hwe) self.ppg = hwe_to_ppg(self.hwe) else: - raise GrainException(u"{}: Must provide ppg or hwe".format( - self.name)) + raise GrainException(u"{}: Must provide ppg or hwe".format(self.name)) def __str__(self): if sys.version_info[0] >= 3: return self.__unicode__() else: - return self.__unicode__().encode(u'utf8') + return self.__unicode__().encode(u"utf8") def __unicode__(self): return self.name @@ -78,8 +74,7 @@ def __repr__(self): if self.color: out = u"{0}, color={1}".format(out, self.color) if self.hwe: - out = u"{0}, hwe={1}".format(out, - round(self.hwe, 2)) + out = u"{0}, hwe={1}".format(out, round(self.hwe, 2)) out = u"{0})".format(out) return out @@ -87,9 +82,11 @@ def __eq__(self, other): if not isinstance(other, self.__class__): return False # Short name does not need to match - if (self.name == other.name) and \ - (self.ppg == other.ppg) and \ - (self.color == other.color): + if ( + (self.name == other.name) + and (self.ppg == other.ppg) + and (self.color == other.color) + ): return True return False @@ -97,23 +94,27 @@ def __ne__(self, other): return not self.__eq__(other) def to_dict(self): - return {u'name': self.name, - u'color': round(self.color, 1), - u'ppg': round(self.ppg, 2), - u'hwe': round(self.hwe, 2), - } + return { + u"name": self.name, + u"color": round(self.color, 1), + u"ppg": round(self.ppg, 2), + u"hwe": round(self.hwe, 2), + } def to_json(self): return json.dumps(self.to_dict(), sort_keys=True) def format(self): - msg = textwrap.dedent(u"""\ + msg = textwrap.dedent( + u"""\ {name} Grain ----------------------------------- Color: {color} degL PPG: {ppg:0.2f} Hot Water Extract: {hwe:0.2f}""".format( - **self.to_dict())) + **self.to_dict() + ) + ) return msg def get_working_yield(self, brew_house_yield): @@ -125,12 +126,11 @@ def get_working_yield(self, brew_house_yield): :rtype: float """ validate_percentage(brew_house_yield) - return (hwe_to_basis(self.hwe) * - brew_house_yield) + return hwe_to_basis(self.hwe) * brew_house_yield def convert_to_cereal(self, ppg=None): if not ppg: - raise GrainException(u'Must provide PPG to convert to cereal') + raise GrainException(u"Must provide PPG to convert to cereal") return Grain(self.name, color=self.color, ppg=ppg) def convert_to_lme(self, ppg=PPG_LME): @@ -145,10 +145,9 @@ class GrainAddition(object): A representation of the grain as added to a Recipe. """ - def __init__(self, grain, - weight=None, - grain_type=GRAIN_TYPE_CEREAL, - units=IMPERIAL_UNITS): + def __init__( + self, grain, weight=None, grain_type=GRAIN_TYPE_CEREAL, units=IMPERIAL_UNITS + ): """ :param Grain grain: The Grain object :param float weight: The weight of the grain addition @@ -187,21 +186,18 @@ def change_units(self): elif self.units == SI_UNITS: weight = self.weight * POUND_PER_KG units = IMPERIAL_UNITS - return GrainAddition(self.grain, - weight=weight, - units=units) + return GrainAddition(self.grain, weight=weight, units=units) def __str__(self): if sys.version_info[0] >= 3: return self.__unicode__() else: - return self.__unicode__().encode(u'utf8') + return self.__unicode__().encode(u"utf8") def __unicode__(self): return u"{grain}, weight {weight} {weight_large}".format( - grain=self.grain, - weight=self.weight, - **self.types) + grain=self.grain, weight=self.weight, **self.types + ) def __repr__(self): out = u"{0}({1}".format(type(self).__name__, repr(self.grain)) @@ -216,10 +212,12 @@ def __repr__(self): def __eq__(self, other): if not isinstance(other, self.__class__): return False - if (abs(1.0 - self.weight / other.weight) < WEIGHT_TOLERANCE) and \ - (self.grain_type == other.grain_type) and \ - (self.units == other.units) and \ - (self.grain == other.grain): + if ( + (abs(1.0 - self.weight / other.weight) < WEIGHT_TOLERANCE) + and (self.grain_type == other.grain_type) + and (self.units == other.units) + and (self.grain == other.grain) + ): return True return False @@ -262,9 +260,9 @@ def get_weight_map(self): :rtype: dict """ return { - u'grain_weight': round(self.get_cereal_weight(), 2), - u'lme_weight': round(self.get_lme_weight(), 2), - u'dry_weight': round(self.get_dme_weight(), 2), + u"grain_weight": round(self.get_cereal_weight(), 2), + u"lme_weight": round(self.get_lme_weight(), 2), + u"dry_weight": round(self.get_dme_weight(), 2), } def convert_to_cereal(self, ppg=None, brew_house_yield=1.0): @@ -279,7 +277,7 @@ def convert_to_cereal(self, ppg=None, brew_house_yield=1.0): if self.grain_type == GRAIN_TYPE_CEREAL: return self if not ppg: - raise GrainException('Must provide PPG to convert to cereal') + raise GrainException("Must provide PPG to convert to cereal") validate_percentage(brew_house_yield) new_grain = self.grain.convert_to_cereal(ppg=ppg) @@ -288,10 +286,8 @@ def convert_to_cereal(self, ppg=None, brew_house_yield=1.0): # When converting away from cereal BHY works in reverse weight = self.weight * ppg_factor / brew_house_yield return GrainAddition( - new_grain, - weight=weight, - grain_type=GRAIN_TYPE_CEREAL, - units=self.units) + new_grain, weight=weight, grain_type=GRAIN_TYPE_CEREAL, units=self.units + ) def convert_to_lme(self, ppg=PPG_LME, brew_house_yield=1.0): """ @@ -313,10 +309,8 @@ def convert_to_lme(self, ppg=PPG_LME, brew_house_yield=1.0): ppg_factor = self.grain.ppg / new_grain.ppg weight = self.weight * ppg_factor * brew_house_yield return GrainAddition( - new_grain, - weight=weight, - grain_type=GRAIN_TYPE_LME, - units=self.units) + new_grain, weight=weight, grain_type=GRAIN_TYPE_LME, units=self.units + ) def convert_to_dme(self, ppg=PPG_DME, brew_house_yield=1.0): """ @@ -338,10 +332,8 @@ def convert_to_dme(self, ppg=PPG_DME, brew_house_yield=1.0): ppg_factor = self.grain.ppg / new_grain.ppg weight = self.weight * ppg_factor * brew_house_yield return GrainAddition( - new_grain, - weight=weight, - grain_type=GRAIN_TYPE_DME, - units=self.units) + new_grain, weight=weight, grain_type=GRAIN_TYPE_DME, units=self.units + ) @property def gu(self): @@ -355,35 +347,35 @@ def get_gravity_units(self): """ # Pick the attribute based on units if self.units == IMPERIAL_UNITS: - attr = u'ppg' + attr = u"ppg" if self.units == SI_UNITS: - attr = u'hwe' + attr = u"hwe" return getattr(self.grain, attr) * self.weight def to_dict(self): grain_data = self.grain.to_dict() - return {u'name': grain_data.pop('name'), - u'data': grain_data, - u'weight': round(self.weight, 2), - u'grain_type': self.grain_type, - u'units': self.units, - } + return { + u"name": grain_data.pop("name"), + u"data": grain_data, + u"weight": round(self.weight, 2), + u"grain_type": self.grain_type, + u"units": self.units, + } def to_json(self): return json.dumps(self.to_dict(), sort_keys=True) @classmethod def validate(cls, grain_data): - required_fields = [(u'name', str), - (u'weight', float), - ] - optional_fields = [(u'color', (int, float)), - (u'ppg', (int, float)), - (u'hwe', (int, float)), - (u'grain_type', str), - (u'units', str), - ] + required_fields = [(u"name", str), (u"weight", float)] + optional_fields = [ + (u"color", (int, float)), + (u"ppg", (int, float)), + (u"hwe", (int, float)), + (u"grain_type", str), + (u"units", str), + ] validate_required_fields(grain_data, required_fields) validate_optional_fields(grain_data, optional_fields) @@ -391,10 +383,13 @@ def format(self): kwargs = {} kwargs.update(self.to_dict()) kwargs.update(self.types) - msg = textwrap.dedent(u"""\ + msg = textwrap.dedent( + u"""\ {name} Addition ----------------------------------- Grain Type: {grain_type} Weight: {weight:0.2f} {weight_large}""".format( - **kwargs)) + **kwargs + ) + ) return msg diff --git a/brew/hops.py b/brew/hops.py index d0bb933..5af9789 100644 --- a/brew/hops.py +++ b/brew/hops.py @@ -19,7 +19,7 @@ from .validators import validate_required_fields from .validators import validate_units -__all__ = [u'Hop', u'HopAddition'] +__all__ = [u"Hop", u"HopAddition"] class Hop(object): @@ -27,8 +27,7 @@ class Hop(object): A representation of a type of Hop. """ - def __init__(self, name, - percent_alpha_acids=None): + def __init__(self, name, percent_alpha_acids=None): """ :param str name: The name of the hop :param float percent_alpha_acids: The percent alpha acids in the hop @@ -36,33 +35,35 @@ def __init__(self, name, """ self.name = name if percent_alpha_acids is None: - raise HopException(u"{}: Must provide percent alpha acids".format( - self.name)) + raise HopException( + u"{}: Must provide percent alpha acids".format(self.name) + ) self.percent_alpha_acids = validate_percentage(percent_alpha_acids) def __str__(self): if sys.version_info[0] >= 3: return self.__unicode__() else: - return self.__unicode__().encode(u'utf8') + return self.__unicode__().encode(u"utf8") def __unicode__(self): - return u"{0}, alpha {1:0.1%}".format(self.name.capitalize(), - self.percent_alpha_acids) + return u"{0}, alpha {1:0.1%}".format( + self.name.capitalize(), self.percent_alpha_acids + ) def __repr__(self): out = u"{0}('{1}'".format(type(self).__name__, self.name) if self.percent_alpha_acids: - out = u"{0}, percent_alpha_acids={1}".format( - out, self.percent_alpha_acids) + out = u"{0}, percent_alpha_acids={1}".format(out, self.percent_alpha_acids) out = u"{0})".format(out) return out def __eq__(self, other): if not isinstance(other, self.__class__): return False - if (self.name == other.name) and \ - (self.percent_alpha_acids == other.percent_alpha_acids): + if (self.name == other.name) and ( + self.percent_alpha_acids == other.percent_alpha_acids + ): return True return False @@ -70,19 +71,23 @@ def __ne__(self, other): return not self.__eq__(other) def to_dict(self): - return {u'name': self.name, - u'percent_alpha_acids': round(self.percent_alpha_acids, 3), - } + return { + u"name": self.name, + u"percent_alpha_acids": round(self.percent_alpha_acids, 3), + } def to_json(self): return json.dumps(self.to_dict(), sort_keys=True) def format(self): - msg = textwrap.dedent(u"""\ + msg = textwrap.dedent( + u"""\ {name} Hops ----------------------------------- Alpha Acids: {percent_alpha_acids:0.1%}""".format( - **self.to_dict())) + **self.to_dict() + ) + ) return msg @@ -91,13 +96,16 @@ class HopAddition(object): A representation of the Hop as added to a Recipe. """ - def __init__(self, hop, - weight=None, - boil_time=None, - hop_type=HOP_TYPE_PELLET, - utilization_cls=HopsUtilizationGlennTinseth, - utilization_cls_kwargs=None, - units=IMPERIAL_UNITS): + def __init__( + self, + hop, + weight=None, + boil_time=None, + hop_type=HOP_TYPE_PELLET, + utilization_cls=HopsUtilizationGlennTinseth, + utilization_cls_kwargs=None, + units=IMPERIAL_UNITS, + ): """ :param Hop hop: The Hop object :param float weight: The weight of the hop addition @@ -112,7 +120,9 @@ def __init__(self, hop, self.boil_time = boil_time self.hop_type = validate_hop_type(hop_type) self.utilization_cls_kwargs = utilization_cls_kwargs or {} - self.utilization_cls = utilization_cls(self, **self.utilization_cls_kwargs) # noqa + self.utilization_cls = utilization_cls( + self, **self.utilization_cls_kwargs + ) # noqa # Manage units self.set_units(units) @@ -142,25 +152,28 @@ def change_units(self): elif self.units == SI_UNITS: weight = self.weight * OZ_PER_MG units = IMPERIAL_UNITS - return HopAddition(self.hop, - weight=weight, - boil_time=self.boil_time, - utilization_cls_kwargs={u'units': units}, - units=units) + return HopAddition( + self.hop, + weight=weight, + boil_time=self.boil_time, + utilization_cls_kwargs={u"units": units}, + units=units, + ) def __str__(self): if sys.version_info[0] >= 3: return self.__unicode__() else: - return self.__unicode__().encode(u'utf8') + return self.__unicode__().encode(u"utf8") def __unicode__(self): return u"{hop}, {weight} {weight_small}, {boil_time} min, {hop_type}".format( # noqa - hop=self.hop, - weight=self.weight, - boil_time=self.boil_time, - hop_type=self.hop_type, - **self.types) + hop=self.hop, + weight=self.weight, + boil_time=self.boil_time, + hop_type=self.hop_type, + **self.types + ) def __repr__(self): out = u"{0}({1}".format(type(self).__name__, repr(self.hop)) @@ -171,9 +184,13 @@ def __repr__(self): if self.hop_type: out = u"{0}, hop_type='{1}'".format(out, self.hop_type) if self.utilization_cls: - out = u"{0}, utilization_cls={1}".format(out, type(self.utilization_cls).__name__) # noqa + out = u"{0}, utilization_cls={1}".format( + out, type(self.utilization_cls).__name__ + ) # noqa if self.utilization_cls_kwargs: - out = u"{0}, utilization_cls_kwargs={1}".format(out, str(self.utilization_cls_kwargs)) # noqa + out = u"{0}, utilization_cls_kwargs={1}".format( + out, str(self.utilization_cls_kwargs) + ) # noqa out = u"{0}, units='{1}'".format(out, self.units) out = u"{0})".format(out) return out @@ -181,11 +198,13 @@ def __repr__(self): def __eq__(self, other): if not isinstance(other, self.__class__): return False - if (self.hop == other.hop) and \ - (self.boil_time == other.boil_time) and \ - (abs(1.0 - self.weight / other.weight) < WEIGHT_TOLERANCE) and \ - (self.hop_type == other.hop_type) and \ - (self.units == other.units): + if ( + (self.hop == other.hop) + and (self.boil_time == other.boil_time) + and (abs(1.0 - self.weight / other.weight) < WEIGHT_TOLERANCE) + and (self.hop_type == other.hop_type) + and (self.units == other.units) + ): return True return False @@ -194,29 +213,28 @@ def __ne__(self, other): def to_dict(self): hop_data = self.hop.to_dict() - return {u'name': hop_data.pop(u'name'), - u'data': hop_data, - u'weight': round(self.weight, 2), - u'boil_time': round(self.boil_time, 1), - u'hop_type': self.hop_type, - u'utilization_cls': str(self.utilization_cls), - u'utilization_cls_kwargs': self.utilization_cls_kwargs, - u'units': self.units, - } + return { + u"name": hop_data.pop(u"name"), + u"data": hop_data, + u"weight": round(self.weight, 2), + u"boil_time": round(self.boil_time, 1), + u"hop_type": self.hop_type, + u"utilization_cls": str(self.utilization_cls), + u"utilization_cls_kwargs": self.utilization_cls_kwargs, + u"units": self.units, + } def to_json(self): return json.dumps(self.to_dict(), sort_keys=True) @classmethod def validate(cls, hop_data): - required_fields = [(u'name', str), - (u'weight', float), - (u'boil_time', float), - ] - optional_fields = [(u'percent_alpha_acids', float), - (u'hop_type', str), - (u'units', str), - ] + required_fields = [(u"name", str), (u"weight", float), (u"boil_time", float)] + optional_fields = [ + (u"percent_alpha_acids", float), + (u"hop_type", str), + (u"units", str), + ] validate_required_fields(hop_data, required_fields) validate_optional_fields(hop_data, optional_fields) @@ -224,14 +242,17 @@ def format(self): kwargs = {} kwargs.update(self.to_dict()) kwargs.update(self.types) - msg = textwrap.dedent(u"""\ + msg = textwrap.dedent( + u"""\ {name} Addition ----------------------------------- Hop Type: {hop_type} AA %: {data[percent_alpha_acids]:0.1%} Weight: {weight:0.2f} {weight_small} Boil Time: {boil_time:0.1f} min""".format( - **kwargs)) + **kwargs + ) + ) return msg def get_ibus(self, sg, final_volume): diff --git a/brew/parsers.py b/brew/parsers.py index 10e75ca..737319d 100644 --- a/brew/parsers.py +++ b/brew/parsers.py @@ -13,12 +13,12 @@ from .yeasts import Yeast __all__ = [ - u'DataLoader', - u'JSONDataLoader', - u'parse_cereals', - u'parse_hops', - u'parse_yeast', - u'parse_recipe', + u"DataLoader", + u"JSONDataLoader", + u"parse_cereals", + u"parse_hops", + u"parse_yeast", + u"parse_recipe", ] @@ -26,17 +26,20 @@ class DataLoader(object): """ Base class for loading data from data files inside the data_dir. """ + #: A local cache of loaded data DATA = {} #: The expected file extension (json, xml, csv) - EXT = '' + EXT = "" def __init__(self, data_dir): """ :param str data_dir: The directory where the data resides """ if not os.path.isdir(data_dir): - raise DataLoaderException(u"Directory '{}' does not exist".format(data_dir)) # noqa + raise DataLoaderException( + u"Directory '{}' does not exist".format(data_dir) + ) # noqa self.data_dir = data_dir @classmethod @@ -44,7 +47,7 @@ def format_name(cls, name): """ Reformat a given name to match the filename of a data file. """ - return name.lower().replace(u' ', u'_').replace(u'-', u'_') + return name.lower().replace(u" ", u"_").replace(u"-", u"_") @classmethod def read_data(cls, filename): @@ -64,25 +67,30 @@ def get_item(self, dir_suffix, item_name): """ item_dir = os.path.join(self.data_dir, dir_suffix) if not os.path.isdir(item_dir): - raise DataLoaderException(u"Item directory '{}' does not exist".format(item_dir)) # noqa + raise DataLoaderException( + u"Item directory '{}' does not exist".format(item_dir) + ) # noqa # Cache the directory if dir_suffix not in self.DATA: self.DATA[dir_suffix] = {} - for item in glob.glob('{}*.{}'.format(item_dir, self.EXT)): + for item in glob.glob("{}*.{}".format(item_dir, self.EXT)): ext_len = len(self.EXT) + 1 filename = os.path.basename(item)[:-ext_len] self.DATA[dir_suffix][filename] = {} name = self.format_name(item_name) if name not in self.DATA[dir_suffix]: - warnings.warn(u'Item from {} dir not found: {}'.format(dir_suffix, # noqa - name)) + warnings.warn( + u"Item from {} dir not found: {}".format(dir_suffix, name) # noqa + ) return {} # Cache file data if not self.DATA[dir_suffix][name]: - item_filename = os.path.join(item_dir, '{}.{}'.format(name, self.EXT)) # noqa + item_filename = os.path.join( + item_dir, "{}.{}".format(name, self.EXT) + ) # noqa data = self.read_data(item_filename) self.DATA[dir_suffix][name] = data return data @@ -94,8 +102,9 @@ class JSONDataLoader(DataLoader): """ Load data from JSON files inside the data_dir. """ + #: The JSON file extension - EXT = 'json' + EXT = "json" @classmethod def read_data(cls, filename): @@ -104,12 +113,12 @@ def read_data(cls, filename): :return: The data loaded from a JSON file """ data = None - with open(filename, 'r') as data_file: + with open(filename, "r") as data_file: data = json.loads(data_file.read()) return data -def parse_cereals(cereal, loader, dir_suffix='cereals/'): +def parse_cereals(cereal, loader, dir_suffix="cereals/"): """ Parse grains data from a recipe @@ -130,35 +139,33 @@ def parse_cereals(cereal, loader, dir_suffix='cereals/'): """ GrainAddition.validate(cereal) - cereal_data = loader.get_item(dir_suffix, cereal[u'name']) + cereal_data = loader.get_item(dir_suffix, cereal[u"name"]) - name = cereal_data.get(u'name', cereal[u'name']) + name = cereal_data.get(u"name", cereal[u"name"]) color = None ppg = None - if u'data' in cereal: - color = cereal[u'data'].get(u'color', None) - ppg = cereal[u'data'].get(u'ppg', None) + if u"data" in cereal: + color = cereal[u"data"].get(u"color", None) + ppg = cereal[u"data"].get(u"ppg", None) if not color: - color = cereal_data.get(u'color', None) + color = cereal_data.get(u"color", None) if not ppg: - ppg = cereal_data.get(u'ppg', None) + ppg = cereal_data.get(u"ppg", None) grain_obj = Grain(name, color=color, ppg=ppg) - grain_add_kwargs = { - u'weight': float(cereal[u'weight']), - } - if u'grain_type' in cereal: - grain_add_kwargs[u'grain_type'] = cereal[u'grain_type'] - if u'units' in cereal: - grain_add_kwargs[u'units'] = cereal[u'units'] + grain_add_kwargs = {u"weight": float(cereal[u"weight"])} + if u"grain_type" in cereal: + grain_add_kwargs[u"grain_type"] = cereal[u"grain_type"] + if u"units" in cereal: + grain_add_kwargs[u"units"] = cereal[u"units"] return GrainAddition(grain_obj, **grain_add_kwargs) -def parse_hops(hop, loader, dir_suffix='hops/'): +def parse_hops(hop, loader, dir_suffix="hops/"): """ Parse hops data from a recipe @@ -179,30 +186,27 @@ def parse_hops(hop, loader, dir_suffix='hops/'): """ HopAddition.validate(hop) - hop_data = loader.get_item(dir_suffix, hop[u'name']) + hop_data = loader.get_item(dir_suffix, hop[u"name"]) - name = hop_data.get(u'name', hop[u'name']) + name = hop_data.get(u"name", hop[u"name"]) alpha_acids = None - if u'data' in hop: - alpha_acids = hop[u'data'].get(u'percent_alpha_acids', None) + if u"data" in hop: + alpha_acids = hop[u"data"].get(u"percent_alpha_acids", None) if not alpha_acids: - alpha_acids = hop_data.get(u'percent_alpha_acids', None) + alpha_acids = hop_data.get(u"percent_alpha_acids", None) hop_obj = Hop(name, percent_alpha_acids=alpha_acids) - hop_add_kwargs = { - u'weight': float(hop[u'weight']), - u'boil_time': hop[u'boil_time'], - } - if u'hop_type' in hop: - hop_add_kwargs[u'hop_type'] = hop[u'hop_type'] - if u'units' in hop: - hop_add_kwargs[u'units'] = hop[u'units'] + hop_add_kwargs = {u"weight": float(hop[u"weight"]), u"boil_time": hop[u"boil_time"]} + if u"hop_type" in hop: + hop_add_kwargs[u"hop_type"] = hop[u"hop_type"] + if u"units" in hop: + hop_add_kwargs[u"units"] = hop[u"units"] return HopAddition(hop_obj, **hop_add_kwargs) -def parse_yeast(yeast, loader, dir_suffix='yeast/'): +def parse_yeast(yeast, loader, dir_suffix="yeast/"): """ Parse yeast data from a recipe @@ -221,27 +225,30 @@ def parse_yeast(yeast, loader, dir_suffix='yeast/'): """ Yeast.validate(yeast) - yeast_data = loader.get_item(dir_suffix, yeast[u'name']) # noqa + yeast_data = loader.get_item(dir_suffix, yeast[u"name"]) # noqa - name = yeast_data.get(u'name', yeast[u'name']) + name = yeast_data.get(u"name", yeast[u"name"]) attenuation = None - if u'data' in yeast: - attenuation = yeast[u'data'].get(u'percent_attenuation', None) + if u"data" in yeast: + attenuation = yeast[u"data"].get(u"percent_attenuation", None) if not attenuation: - attenuation = yeast_data.get(u'percent_attenuation', None) + attenuation = yeast_data.get(u"percent_attenuation", None) return Yeast(name, percent_attenuation=attenuation) -def parse_recipe(recipe, loader, - cereals_loader=None, - hops_loader=None, - yeast_loader=None, - cereals_dir_suffix='cereals/', - hops_dir_suffix='hops/', - yeast_dir_suffix='yeast/'): +def parse_recipe( + recipe, + loader, + cereals_loader=None, + hops_loader=None, + yeast_loader=None, + cereals_dir_suffix="cereals/", + hops_dir_suffix="hops/", + yeast_dir_suffix="yeast/", +): """ Parse a recipe from a python Dict @@ -282,32 +289,29 @@ def parse_recipe(recipe, loader, Recipe.validate(recipe) grain_additions = [] - for grain in recipe[u'grains']: - grain_additions.append(parse_cereals(grain, cereals_loader, - dir_suffix=cereals_dir_suffix)) + for grain in recipe[u"grains"]: + grain_additions.append( + parse_cereals(grain, cereals_loader, dir_suffix=cereals_dir_suffix) + ) hop_additions = [] - for hop in recipe[u'hops']: - hop_additions.append(parse_hops(hop, hops_loader, - dir_suffix=hops_dir_suffix)) + for hop in recipe[u"hops"]: + hop_additions.append(parse_hops(hop, hops_loader, dir_suffix=hops_dir_suffix)) - yeast = parse_yeast(recipe[u'yeast'], yeast_loader, - dir_suffix=yeast_dir_suffix) + yeast = parse_yeast(recipe[u"yeast"], yeast_loader, dir_suffix=yeast_dir_suffix) recipe_kwargs = { - u'grain_additions': grain_additions, - u'hop_additions': hop_additions, - u'yeast': yeast, - u'start_volume': recipe[u'start_volume'], - u'final_volume': recipe[u'final_volume'], + u"grain_additions": grain_additions, + u"hop_additions": hop_additions, + u"yeast": yeast, + u"start_volume": recipe[u"start_volume"], + u"final_volume": recipe[u"final_volume"], } - if u'data' in recipe: - if u'brew_house_yield' in recipe[u'data']: - recipe_kwargs[u'brew_house_yield'] = \ - recipe[u'data'][u'brew_house_yield'] - if u'units' in recipe[u'data']: - recipe_kwargs[u'units'] = recipe[u'data'][u'units'] - - beer = Recipe(recipe[u'name'], - **recipe_kwargs) + if u"data" in recipe: + if u"brew_house_yield" in recipe[u"data"]: + recipe_kwargs[u"brew_house_yield"] = recipe[u"data"][u"brew_house_yield"] + if u"units" in recipe[u"data"]: + recipe_kwargs[u"units"] = recipe[u"data"][u"units"] + + beer = Recipe(recipe[u"name"], **recipe_kwargs) return beer diff --git a/brew/recipes.py b/brew/recipes.py index 91466eb..ad71a5e 100644 --- a/brew/recipes.py +++ b/brew/recipes.py @@ -46,24 +46,28 @@ from .validators import validate_required_fields from .validators import validate_units -__all__ = [u'Recipe', u'RecipeBuilder'] +__all__ = [u"Recipe", u"RecipeBuilder"] class Recipe(object): """ A representation of a Recipe that can be brewed to make beer. """ + grain_lookup = {} hop_lookup = {} - def __init__(self, name, - grain_additions=None, - hop_additions=None, - yeast=None, - brew_house_yield=0.70, - start_volume=7.0, - final_volume=5.0, - units=IMPERIAL_UNITS): + def __init__( + self, + name, + grain_additions=None, + hop_additions=None, + yeast=None, + brew_house_yield=0.70, + start_volume=7.0, + final_volume=5.0, + units=IMPERIAL_UNITS, + ): """ :param str name: The name of the recipe :param grain_additions: A list of Grain Additions @@ -99,21 +103,27 @@ def __init__(self, name, for grain_add in self.grain_additions: self.grain_lookup[grain_add.grain.name] = grain_add if grain_add.units != self.units: - raise RecipeException(u"{}: Grain addition units must be in '{}' not '{}'".format( # noqa - self.name, self.units, grain_add.units)) + raise RecipeException( + u"{}: Grain addition units must be in '{}' not '{}'".format( # noqa + self.name, self.units, grain_add.units + ) + ) for hop_add in self.hop_additions: # The same hops may be used several times, so we must distinguish - hop_key = u'{}_{}'.format(hop_add.hop.name, hop_add.boil_time) + hop_key = u"{}_{}".format(hop_add.hop.name, hop_add.boil_time) self.hop_lookup[hop_key] = hop_add if hop_add.units != self.units: - raise RecipeException(u"{}: Hop addition units must be in '{}' not '{}'".format( # noqa - self.name, self.units, hop_add.units)) + raise RecipeException( + u"{}: Hop addition units must be in '{}' not '{}'".format( # noqa + self.name, self.units, hop_add.units + ) + ) def __str__(self): if sys.version_info[0] >= 3: return self.__unicode__() else: - return self.__unicode__().encode(u'utf8') + return self.__unicode__().encode(u"utf8") def __unicode__(self): return self.name @@ -121,13 +131,19 @@ def __unicode__(self): def __repr__(self): out = u"{0}('{1}'".format(type(self).__name__, self.name) if self.grain_additions: - out = u"{0}, grain_additions=[{1}]".format(out, u', '.join([repr(h) for h in self.grain_additions])) # noqa + out = u"{0}, grain_additions=[{1}]".format( + out, u", ".join([repr(h) for h in self.grain_additions]) + ) # noqa if self.hop_additions: - out = u"{0}, hop_additions=[{1}]".format(out, u', '.join([repr(h) for h in self.hop_additions])) # noqa + out = u"{0}, hop_additions=[{1}]".format( + out, u", ".join([repr(h) for h in self.hop_additions]) + ) # noqa if self.yeast: out = u"{0}, yeast={1}".format(out, repr(self.yeast)) if self.brew_house_yield: - out = u"{0}, brew_house_yield={1}".format(out, self.brew_house_yield) # noqa + out = u"{0}, brew_house_yield={1}".format( + out, self.brew_house_yield + ) # noqa if self.start_volume: out = u"{0}, start_volume={1}".format(out, self.start_volume) if self.final_volume: @@ -140,15 +156,16 @@ def __repr__(self): def __eq__(self, other): if not isinstance(other, self.__class__): return False - if (self.name == other.name) and \ - (self.grain_additions == other.grain_additions) and \ - (self.hop_additions == other.hop_additions) and \ - (self.yeast == other.yeast) and \ - (self.brew_house_yield == - other.brew_house_yield) and \ - (self.start_volume == other.start_volume) and \ - (self.final_volume == other.final_volume) and \ - (self.units == other.units): + if ( + (self.name == other.name) + and (self.grain_additions == other.grain_additions) + and (self.hop_additions == other.hop_additions) + and (self.yeast == other.yeast) + and (self.brew_house_yield == other.brew_house_yield) + and (self.start_volume == other.start_volume) + and (self.final_volume == other.final_volume) + and (self.units == other.units) + ): return True return False @@ -182,16 +199,16 @@ def change_units(self): start_volume = self.start_volume * GAL_PER_LITER final_volume = self.final_volume * GAL_PER_LITER units = IMPERIAL_UNITS - return Recipe(self.name, - grain_additions=[ga.change_units() for ga in - self.grain_additions], - hop_additions=[ha.change_units() for ha in - self.hop_additions], - yeast=self.yeast, - brew_house_yield=self.brew_house_yield, - start_volume=start_volume, - final_volume=final_volume, - units=units) + return Recipe( + self.name, + grain_additions=[ga.change_units() for ga in self.grain_additions], + hop_additions=[ha.change_units() for ha in self.hop_additions], + yeast=self.yeast, + brew_house_yield=self.brew_house_yield, + start_volume=start_volume, + final_volume=final_volume, + units=units, + ) def get_total_points(self): """ @@ -240,7 +257,9 @@ def get_boil_gravity_units(self, evaporation=BOIL_EVAPORATION): # noqa :return: The boil gravity units :rtype: float """ - return self.get_total_points() / ((1.0 - evaporation) * self.start_volume) # noqa + return self.get_total_points() / ( + (1.0 - evaporation) * self.start_volume + ) # noqa def get_boil_gravity(self, evaporation=BOIL_EVAPORATION): # noqa """ @@ -263,7 +282,9 @@ def get_final_gravity_units(self): :return: The final gravity units :rtype: float """ - return self.get_original_gravity_units() * (1.0 - self.yeast.percent_attenuation) # noqa + return self.get_original_gravity_units() * ( + 1.0 - self.yeast.percent_attenuation + ) # noqa def get_final_gravity(self): """ @@ -278,16 +299,17 @@ def get_final_gravity(self): def fg(self): return self.get_final_gravity() - def get_wort_correction(self, current_gu, current_volume, - efficiency=PPG_DME): + def get_wort_correction(self, current_gu, current_volume, efficiency=PPG_DME): """ Get the amount of sugar to add to correct the wort """ - return get_wort_correction(current_gu, - current_volume, - self.get_original_gravity_units(), - self.final_volume, - efficiency=efficiency) + return get_wort_correction( + current_gu, + current_volume, + self.get_original_gravity_units(), + self.final_volume, + efficiency=efficiency, + ) def get_degrees_plato(self): """ @@ -325,8 +347,12 @@ def get_extract_weight(self): water_density = WATER_WEIGHT_IMPERIAL if self.units == SI_UNITS: water_density = WATER_WEIGHT_SI - return (water_density * self.final_volume * self.get_boil_gravity() * - (self.plato / 100.0)) + return ( + water_density + * self.final_volume + * self.get_boil_gravity() + * (self.plato / 100.0) + ) def get_percent_malt_bill(self, grain_add): """ @@ -339,7 +365,9 @@ def get_percent_malt_bill(self, grain_add): To ensure different additions are measured equally each is converted to dry weight. """ - return self.get_grain_add_dry_weight(grain_add) / self.get_total_dry_weight() # noqa + return ( + self.get_grain_add_dry_weight(grain_add) / self.get_total_dry_weight() + ) # noqa def get_grain_add_dry_weight(self, grain_add): """ @@ -416,8 +444,7 @@ def get_total_ibu(self): """ bg = self.get_boil_gravity() fv = self.final_volume - return sum([hop_add.get_ibus(bg, fv) - for hop_add in self.hop_additions]) + return sum([hop_add.get_ibus(bg, fv) for hop_add in self.hop_additions]) @property def ibu(self): @@ -445,10 +472,9 @@ def get_wort_color_mcu(self, grain_add): :rtype: float """ # noqa weight = self.get_grain_add_cereal_weight(grain_add) - return calculate_mcu(weight, - grain_add.grain.color, - self.final_volume, - units=self.units) + return calculate_mcu( + weight, grain_add.grain.color, self.final_volume, units=self.units + ) def get_wort_color(self, grain_add): """ @@ -484,13 +510,13 @@ def get_total_wort_color_map(self): """ # noqa mcu = sum([self.get_wort_color_mcu(ga) for ga in self.grain_additions]) - srm_morey = u'N/A' - srm_daniels = u'N/A' - srm_mosher = u'N/A' + srm_morey = u"N/A" + srm_daniels = u"N/A" + srm_mosher = u"N/A" - ebc_morey = u'N/A' - ebc_daniels = u'N/A' - ebc_mosher = u'N/A' + ebc_morey = u"N/A" + ebc_daniels = u"N/A" + ebc_mosher = u"N/A" try: srm_morey = calculate_srm_morey(mcu) @@ -514,15 +540,15 @@ def get_total_wort_color_map(self): pass return { - u'srm': { - u'morey': srm_morey, - u'daniels': srm_daniels, - u'mosher': srm_mosher, + u"srm": { + u"morey": srm_morey, + u"daniels": srm_daniels, + u"mosher": srm_mosher, }, - u'ebc': { - u'morey': ebc_morey, - u'daniels': ebc_daniels, - u'mosher': ebc_mosher, + u"ebc": { + u"morey": ebc_morey, + u"daniels": ebc_daniels, + u"mosher": ebc_mosher, }, } @@ -534,7 +560,11 @@ def get_grain_additions_by_type(self, grain_type): :return: list of GrainAddition objects """ validate_grain_type(grain_type) - return [grain_add for grain_add in self.grain_additions if grain_add.grain_type == grain_type] # noqa + return [ + grain_add + for grain_add in self.grain_additions + if grain_add.grain_type == grain_type + ] # noqa def get_hop_additions_by_type(self, hop_type): """ @@ -544,7 +574,9 @@ def get_hop_additions_by_type(self, hop_type): :return: list of HopAddition objects """ validate_hop_type(hop_type) - return [hop_add for hop_add in self.hop_additions if hop_add.hop_type == hop_type] # noqa + return [ + hop_add for hop_add in self.hop_additions if hop_add.hop_type == hop_type + ] # noqa def to_dict(self): og = self.og @@ -553,41 +585,47 @@ def to_dict(self): abv_standard = self.abv abv_alternative = alcohol_by_volume_alternative(og, fg) recipe_dict = { - u'name': self.name, - u'start_volume': round(self.start_volume, 2), - u'final_volume': round(self.final_volume, 2), - u'data': { - u'brew_house_yield': round(self.brew_house_yield, 3), # noqa - u'original_gravity': round(og, 3), - u'boil_gravity': round(bg, 3), - u'final_gravity': round(fg, 3), - u'abv_standard': round(abv_standard, 4), - u'abv_alternative': round(abv_alternative, 4), - u'abw_standard': round(alcohol_by_weight(abv_standard), 4), - u'abw_alternative': round(alcohol_by_weight(abv_alternative), 4), # noqa - u'total_wort_color_map': self.get_total_wort_color_map(), - u'total_ibu': round(self.get_total_ibu(), 1), - u'bu_to_gu': round(self.get_bu_to_gu(), 1), - u'units': self.units, + u"name": self.name, + u"start_volume": round(self.start_volume, 2), + u"final_volume": round(self.final_volume, 2), + u"data": { + u"brew_house_yield": round(self.brew_house_yield, 3), # noqa + u"original_gravity": round(og, 3), + u"boil_gravity": round(bg, 3), + u"final_gravity": round(fg, 3), + u"abv_standard": round(abv_standard, 4), + u"abv_alternative": round(abv_alternative, 4), + u"abw_standard": round(alcohol_by_weight(abv_standard), 4), + u"abw_alternative": round( + alcohol_by_weight(abv_alternative), 4 + ), # noqa + u"total_wort_color_map": self.get_total_wort_color_map(), + u"total_ibu": round(self.get_total_ibu(), 1), + u"bu_to_gu": round(self.get_bu_to_gu(), 1), + u"units": self.units, }, - u'grains': [], - u'hops': [], - u'yeast': {}, + u"grains": [], + u"hops": [], + u"yeast": {}, } for grain_add in self.grain_additions: grain = grain_add.to_dict() wort_color_srm = self.get_wort_color(grain_add) wort_color_ebc = srm_to_ebc(wort_color_srm) - working_yield = round(grain_add.grain.get_working_yield(self.brew_house_yield), 3) # noqa + working_yield = round( + grain_add.grain.get_working_yield(self.brew_house_yield), 3 + ) # noqa percent_malt_bill = round(self.get_percent_malt_bill(grain_add), 3) - grain[u'data'].update({ - u'working_yield': working_yield, - u'percent_malt_bill': percent_malt_bill, - u'wort_color_srm': round(wort_color_srm, 1), - u'wort_color_ebc': round(wort_color_ebc, 1), - }) - recipe_dict[u'grains'].append(grain) + grain[u"data"].update( + { + u"working_yield": working_yield, + u"percent_malt_bill": percent_malt_bill, + u"wort_color_srm": round(wort_color_srm, 1), + u"wort_color_ebc": round(wort_color_ebc, 1), + } + ) + recipe_dict[u"grains"].append(grain) for hop_add in self.hop_additions: hop = hop_add.to_dict() @@ -595,18 +633,18 @@ def to_dict(self): ibus = hop_add.get_ibus(bg, self.final_volume) utilization = hop_add.utilization_cls.get_percent_utilization( - bg, hop_add.boil_time) + bg, hop_add.boil_time + ) # Utilization is 10% higher for pellet vs whole/plug if hop_add.hop_type == HOP_TYPE_PELLET: utilization *= HOP_UTILIZATION_SCALE_PELLET - hop[u'data'].update({ - u'ibus': round(ibus, 1), - u'utilization': round(utilization, 3), - }) - recipe_dict[u'hops'].append(hop) + hop[u"data"].update( + {u"ibus": round(ibus, 1), u"utilization": round(utilization, 3)} + ) + recipe_dict[u"hops"].append(hop) - recipe_dict[u'yeast'] = self.yeast.to_dict() + recipe_dict[u"yeast"] = self.yeast.to_dict() return recipe_dict @@ -615,16 +653,15 @@ def to_json(self): @classmethod def validate(cls, recipe): - required_fields = [(u'name', str), - (u'start_volume', (int, float)), - (u'final_volume', (int, float)), - (u'grains', (list, tuple)), - (u'hops', (list, tuple)), - (u'yeast', dict), - ] - optional_fields = [(u'brew_house_yield', float), - (u'units', str), - ] + required_fields = [ + (u"name", str), + (u"start_volume", (int, float)), + (u"final_volume", (int, float)), + (u"grains", (list, tuple)), + (u"hops", (list, tuple)), + (u"yeast", dict), + ] + optional_fields = [(u"brew_house_yield", float), (u"units", str)] validate_required_fields(recipe, required_fields) validate_optional_fields(recipe, optional_fields) @@ -639,12 +676,11 @@ def format(self, short=False): kwargs.update(recipe_data) kwargs.update(self.types) # Additional format information - kwargs.update({ - 'evaporation': BOIL_EVAPORATION, - }) + kwargs.update({"evaporation": BOIL_EVAPORATION}) msg = u"" - msg += textwrap.dedent(u"""\ + msg += textwrap.dedent( + u"""\ {name} =================================== @@ -665,68 +701,84 @@ def format(self, short=False): Morey (SRM/EBC): {data[total_wort_color_map][srm][morey]} degL / {data[total_wort_color_map][ebc][morey]} Daniels (SRM/EBC): {data[total_wort_color_map][srm][daniels]} degL / {data[total_wort_color_map][ebc][daniels]} Mosher (SRM/EBC): {data[total_wort_color_map][srm][mosher]} degL / {data[total_wort_color_map][ebc][mosher]} - """.format(**kwargs)) # noqa + """.format( + **kwargs + ) + ) # noqa # If short output is requested then return it if short: return msg - msg += textwrap.dedent(u"""\ + msg += textwrap.dedent( + u"""\ Grains =================================== - """) + """ + ) - for grain_data in recipe_data[u'grains']: + for grain_data in recipe_data[u"grains"]: grain_kwargs = {} grain_kwargs.update(grain_data) grain_kwargs.update(self.types) - grain_name = grain_data[u'name'] + grain_name = grain_data[u"name"] grain_add = self.grain_lookup[grain_name] if grain_add.units != self.units: grain_add = grain_add.change_units() msg += grain_add.format() - msg += textwrap.dedent(u"""\ + msg += textwrap.dedent( + u"""\ Percent Malt Bill: {data[percent_malt_bill]:0.1%} Working Yield: {data[working_yield]:0.1%} SRM/EBC: {data[wort_color_srm]:0.1f} degL / {data[wort_color_ebc]:0.1f} - """.format(**grain_kwargs)) # noqa + """.format( + **grain_kwargs + ) + ) # noqa - msg += textwrap.dedent(u"""\ + msg += textwrap.dedent( + u"""\ Hops =================================== - """) + """ + ) - for hop_data in recipe_data[u'hops']: + for hop_data in recipe_data[u"hops"]: hop_kwargs = {} hop_kwargs.update(hop_data) hop_kwargs.update(self.types) - hop_key = u'{}_{}'.format(hop_data[u'name'], - hop_data[u'boil_time']) + hop_key = u"{}_{}".format(hop_data[u"name"], hop_data[u"boil_time"]) hop = self.hop_lookup[hop_key] if hop.units != self.units: hop = hop.change_units() msg += hop.format() - msg += textwrap.dedent(u"""\ + msg += textwrap.dedent( + u"""\ IBUs: {data[ibus]:0.1f} Utilization: {data[utilization]:0.1%} - """.format(**hop_kwargs)) + """.format( + **hop_kwargs + ) + ) - msg += textwrap.dedent(u"""\ + msg += textwrap.dedent( + u"""\ Yeast =================================== - """) + """ + ) msg += self.yeast.format() return msg @@ -736,18 +788,22 @@ class RecipeBuilder(object): """ A class for building recipes """ + grain_lookup = {} hop_lookup = {} - def __init__(self, name, - grain_list=None, - hop_list=None, - target_ibu=33.0, - target_og=1.050, - brew_house_yield=0.70, - start_volume=7.0, - final_volume=5.0, - units=IMPERIAL_UNITS): + def __init__( + self, + name, + grain_list=None, + hop_list=None, + target_ibu=33.0, + target_og=1.050, + brew_house_yield=0.70, + start_volume=7.0, + final_volume=5.0, + units=IMPERIAL_UNITS, + ): """ :param str name: The name of the recipe :param grain_list: A list of Grains @@ -789,7 +845,7 @@ def __str__(self): if sys.version_info[0] >= 3: return self.__unicode__() else: - return self.__unicode__().encode(u'utf8') + return self.__unicode__().encode(u"utf8") def __unicode__(self): return self.name @@ -797,13 +853,19 @@ def __unicode__(self): def __repr__(self): out = u"{0}('{1}'".format(type(self).__name__, self.name) if self.grain_list: - out = u"{0}, grain_list=[{1}]".format(out, u', '.join([repr(h) for h in self.grain_list])) # noqa + out = u"{0}, grain_list=[{1}]".format( + out, u", ".join([repr(h) for h in self.grain_list]) + ) # noqa if self.hop_list: - out = u"{0}, hop_list=[{1}]".format(out, u', '.join([repr(h) for h in self.hop_list])) # noqa + out = u"{0}, hop_list=[{1}]".format( + out, u", ".join([repr(h) for h in self.hop_list]) + ) # noqa if self.target_og: out = u"{0}, target_og={1}".format(out, self.target_og) # noqa if self.brew_house_yield: - out = u"{0}, brew_house_yield={1}".format(out, self.brew_house_yield) # noqa + out = u"{0}, brew_house_yield={1}".format( + out, self.brew_house_yield + ) # noqa if self.start_volume: out = u"{0}, start_volume={1}".format(out, self.start_volume) if self.final_volume: @@ -816,15 +878,16 @@ def __repr__(self): def __eq__(self, other): if not isinstance(other, self.__class__): return False - if (self.name == other.name) and \ - (self.grain_list == other.grain_list) and \ - (self.hop_list == other.hop_list) and \ - (self.target_og == other.target_og) and \ - (self.brew_house_yield == - other.brew_house_yield) and \ - (self.start_volume == other.start_volume) and \ - (self.final_volume == other.final_volume) and \ - (self.units == other.units): + if ( + (self.name == other.name) + and (self.grain_list == other.grain_list) + and (self.hop_list == other.hop_list) + and (self.target_og == other.target_og) + and (self.brew_house_yield == other.brew_house_yield) + and (self.start_volume == other.start_volume) + and (self.final_volume == other.final_volume) + and (self.units == other.units) + ): return True return False @@ -866,7 +929,8 @@ def change_units(self): brew_house_yield=self.brew_house_yield, start_volume=start_volume, final_volume=final_volume, - units=units) + units=units, + ) def get_grain_additions(self, percent_list): """ @@ -885,13 +949,15 @@ def get_grain_additions(self, percent_list): raise RecipeException(u"Percentages must sum to 1.0") if len(percent_list) != len(self.grain_list): - raise RecipeException(u"The length of percent_list must equal length of self.grain_list") # noqa + raise RecipeException( + u"The length of percent_list must equal length of self.grain_list" + ) # noqa # Pick the attribute based on units if self.units == IMPERIAL_UNITS: - attr = u'ppg' + attr = u"ppg" if self.units == SI_UNITS: - attr = u'hwe' + attr = u"hwe" gu = sg_to_gu(self.target_og) total_points = gu * self.final_volume @@ -899,14 +965,20 @@ def get_grain_additions(self, percent_list): grain_additions = [] for index, grain in enumerate(self.grain_list): efficiency = self.brew_house_yield - weight = (percent_list[index] * total_points) / (getattr(grain, attr) * efficiency) # noqa + weight = (percent_list[index] * total_points) / ( + getattr(grain, attr) * efficiency + ) # noqa grain_add = GrainAddition(grain, weight=weight, units=self.units) grain_additions.append(grain_add) return grain_additions - def get_hop_additions(self, percent_list, boil_time_list, - hop_type=HOP_TYPE_PELLET, - utilization_cls=HopsUtilizationGlennTinseth): + def get_hop_additions( + self, + percent_list, + boil_time_list, + hop_type=HOP_TYPE_PELLET, + utilization_cls=HopsUtilizationGlennTinseth, + ): """ Calculate HopAdditions from list of boil times @@ -925,10 +997,14 @@ def get_hop_additions(self, percent_list, boil_time_list, raise RecipeException(u"Percentages must sum to 1.0") if len(percent_list) != len(self.grain_list): - raise RecipeException(u"The length of percent_list must equal length of self.grain_list") # noqa + raise RecipeException( + u"The length of percent_list must equal length of self.grain_list" + ) # noqa if len(boil_time_list) != len(self.hop_list): - raise RecipeException(u"The length of boil_time_list must equal length of self.hop_list") # noqa + raise RecipeException( + u"The length of boil_time_list must equal length of self.hop_list" + ) # noqa hops_constant = HOPS_CONSTANT_IMPERIAL if self.units == SI_UNITS: @@ -940,20 +1016,24 @@ def get_hop_additions(self, percent_list, boil_time_list, boil_time = boil_time_list[index] # Calculate utilization from boil gravity - bg = gu_to_sg(sg_to_gu(self.target_og) * self.final_volume / self.start_volume) # noqa + bg = gu_to_sg( + sg_to_gu(self.target_og) * self.final_volume / self.start_volume + ) # noqa utilization = utilization_cls.get_percent_utilization(bg, boil_time) # noqa if hop_type == HOP_TYPE_PELLET: utilization *= HOP_UTILIZATION_SCALE_PELLET - num = (self.target_ibu * percent * self.final_volume) - den = (utilization * hop.percent_alpha_acids * hops_constant) + num = self.target_ibu * percent * self.final_volume + den = utilization * hop.percent_alpha_acids * hops_constant weight = num / den - hop_add = HopAddition(hop, - weight=weight, - boil_time=boil_time, - hop_type=hop_type, - utilization_cls=utilization_cls, - units=self.units) + hop_add = HopAddition( + hop, + weight=weight, + boil_time=boil_time, + hop_type=hop_type, + utilization_cls=utilization_cls, + units=self.units, + ) hop_additions.append(hop_add) return hop_additions diff --git a/brew/styles.py b/brew/styles.py index 15e13ae..761ef27 100644 --- a/brew/styles.py +++ b/brew/styles.py @@ -7,7 +7,7 @@ from .exceptions import StyleException from .validators import validate_required_fields -__all__ = [u'Style'] +__all__ = [u"Style"] class Style(object): @@ -15,15 +15,17 @@ class Style(object): A beer style """ - def __init__(self, - style, - category=u'', - subcategory=u'', - og=None, - fg=None, - abv=None, - ibu=None, - color=None): + def __init__( + self, + style, + category=u"", + subcategory=u"", + og=None, + fg=None, + abv=None, + ibu=None, + color=None, + ): """ :param str category: The style category :param str subcategory: The style subcategory @@ -57,24 +59,27 @@ def _validate_input_list(cls, value_list, value_type, name): :raises StyleException: If value_list is out of order """ if not value_list: - raise StyleException(u"Must provide value_list for {}".format( - name)) + raise StyleException(u"Must provide value_list for {}".format(name)) if not isinstance(value_list, (list, tuple)): raise StyleException(u"{} must be a list".format(name)) if len(value_list) != 2: raise StyleException(u"{} must contain two values".format(name)) for v in value_list: if not isinstance(v, value_type): - raise StyleException(u"{} must be type '{}'".format(name, value_type)) # noqa + raise StyleException( + u"{} must be type '{}'".format(name, value_type) + ) # noqa if value_list[0] > value_list[1]: - raise StyleException(u"{} values must be lowest value first".format(name)) # noqa + raise StyleException( + u"{} values must be lowest value first".format(name) + ) # noqa return value_list def __str__(self): if sys.version_info[0] >= 3: return self.__unicode__() else: - return self.__unicode__().encode(u'utf8') + return self.__unicode__().encode(u"utf8") def __unicode__(self): return u"{}{} {}".format(self.category, self.subcategory, self.style) @@ -94,14 +99,16 @@ def __repr__(self): def __eq__(self, other): if not isinstance(other, self.__class__): return False - if (self.style == other.style) and \ - (self.category == other.category) and \ - (self.subcategory == other.subcategory) and \ - (self.og == other.og) and \ - (self.fg == other.fg) and \ - (self.abv == other.abv) and \ - (self.ibu == other.ibu) and \ - (self.color == other.color): + if ( + (self.style == other.style) + and (self.category == other.category) + and (self.subcategory == other.subcategory) + and (self.og == other.og) + and (self.fg == other.fg) + and (self.abv == other.abv) + and (self.ibu == other.ibu) + and (self.color == other.color) + ): return True return False @@ -116,7 +123,7 @@ def og_matches(self, og): :return: True if matches style, otherwise False :rtype: bool """ - return (self.og[0] <= og <= self.og[1]) + return self.og[0] <= og <= self.og[1] def og_errors(self, og): """ @@ -128,9 +135,9 @@ def og_errors(self, og): """ errors = [] if og < self.og[0]: - errors.append(u'OG is below style') + errors.append(u"OG is below style") if og > self.og[1]: - errors.append(u'OG is above style') + errors.append(u"OG is above style") return errors def fg_matches(self, fg): @@ -141,7 +148,7 @@ def fg_matches(self, fg): :return: True if matches style, otherwise False :rtype: bool """ - return (self.fg[0] <= fg <= self.fg[1]) + return self.fg[0] <= fg <= self.fg[1] def fg_errors(self, fg): """ @@ -153,9 +160,9 @@ def fg_errors(self, fg): """ errors = [] if fg < self.fg[0]: - errors.append(u'FG is below style') + errors.append(u"FG is below style") if fg > self.fg[1]: - errors.append(u'FG is above style') + errors.append(u"FG is above style") return errors def abv_matches(self, abv): @@ -166,7 +173,7 @@ def abv_matches(self, abv): :return: True if matches style, otherwise False :rtype: bool """ - return (self.abv[0] <= abv <= self.abv[1]) + return self.abv[0] <= abv <= self.abv[1] def abv_errors(self, abv): """ @@ -178,9 +185,9 @@ def abv_errors(self, abv): """ errors = [] if abv < self.abv[0]: - errors.append(u'ABV is below style') + errors.append(u"ABV is below style") if abv > self.abv[1]: - errors.append(u'ABV is above style') + errors.append(u"ABV is above style") return errors def ibu_matches(self, ibu): @@ -191,7 +198,7 @@ def ibu_matches(self, ibu): :return: True if matches style, otherwise False :rtype: bool """ - return (self.ibu[0] <= ibu <= self.ibu[1]) + return self.ibu[0] <= ibu <= self.ibu[1] def ibu_errors(self, ibu): """ @@ -203,9 +210,9 @@ def ibu_errors(self, ibu): """ errors = [] if ibu < self.ibu[0]: - errors.append(u'IBU is below style') + errors.append(u"IBU is below style") if ibu > self.ibu[1]: - errors.append(u'IBU is above style') + errors.append(u"IBU is above style") return errors def color_matches(self, color): @@ -216,7 +223,7 @@ def color_matches(self, color): :return: True if matches style, otherwise False :rtype: bool """ - return (self.color[0] <= color <= self.color[1]) + return self.color[0] <= color <= self.color[1] def color_errors(self, color): """ @@ -228,9 +235,9 @@ def color_errors(self, color): """ errors = [] if color < self.color[0]: - errors.append(u'Color is below style') + errors.append(u"Color is below style") if color > self.color[1]: - errors.append(u'Color is above style') + errors.append(u"Color is above style") return errors def recipe_matches(self, recipe): @@ -241,11 +248,13 @@ def recipe_matches(self, recipe): :return: True if recipe matches style, otherwise False :rtype: bool """ - if self.og_matches(recipe.og) and \ - self.fg_matches(recipe.fg) and \ - self.abv_matches(recipe.abv) and \ - self.ibu_matches(recipe.ibu) and \ - self.color_matches(recipe.color): + if ( + self.og_matches(recipe.og) + and self.fg_matches(recipe.fg) + and self.abv_matches(recipe.abv) + and self.ibu_matches(recipe.ibu) + and self.color_matches(recipe.color) + ): return True return False @@ -265,19 +274,19 @@ def recipe_errors(self, recipe): try: errors.extend(self.color_errors(recipe.color)) except ColorException: - errors.extend(['Color cannot be calculated']) + errors.extend(["Color cannot be calculated"]) return errors def to_dict(self): style_dict = { - u'style': self.style, - u'category': self.category, - u'subcategory': self.subcategory, - u'og': self.og, - u'fg': self.fg, - u'abv': self.abv, - u'ibu': self.ibu, - u'color': self.color, + u"style": self.style, + u"category": self.category, + u"subcategory": self.subcategory, + u"og": self.og, + u"fg": self.fg, + u"abv": self.abv, + u"ibu": self.ibu, + u"color": self.color, } return style_dict @@ -286,15 +295,16 @@ def to_json(self): @classmethod def validate(cls, recipe): - required_fields = [(u'style', str), - (u'category', str), - (u'subcategory', str), - (u'og', (list, tuple)), - (u'fg', (list, tuple)), - (u'abv', (list, tuple)), - (u'ibu', (list, tuple)), - (u'color', (list, tuple)), - ] + required_fields = [ + (u"style", str), + (u"category", str), + (u"subcategory", str), + (u"og", (list, tuple)), + (u"fg", (list, tuple)), + (u"abv", (list, tuple)), + (u"ibu", (list, tuple)), + (u"color", (list, tuple)), + ] validate_required_fields(recipe, required_fields) def format(self): @@ -303,7 +313,8 @@ def format(self): kwargs.update(style_data) msg = u"" - msg += textwrap.dedent(u"""\ + msg += textwrap.dedent( + u"""\ {category}{subcategory} {style} =================================== @@ -312,18 +323,20 @@ def format(self): ABV: {abv[0]:0.2%} - {abv[1]:0.2%} IBU: {ibu[0]:0.1f} - {ibu[1]:0.1f} Color (SRM): {color[0]:0.1f} - {color[1]:0.1f} - """.format(**kwargs)) # noqa + """.format( + **kwargs + ) + ) # noqa return msg class StyleFactory(object): - def __init__(self, filename): """ :param str filename: The filename of a JSON file containing Styles """ self.filename = filename - with open(filename, 'r') as f: + with open(filename, "r") as f: self.data = json.loads(f.read()) def create_style(self, category, subcategory): @@ -336,14 +349,16 @@ def create_style(self, category, subcategory): :rtype: Style """ data = self.data.get(str(category), {}).get(subcategory, None) - return Style(data['style'], - category=data['category'], - subcategory=data['subcategory'], - og=data['og'], - fg=data['fg'], - abv=data['abv'], - ibu=data['ibu'], - color=data['color']) + return Style( + data["style"], + category=data["category"], + subcategory=data["subcategory"], + og=data["og"], + fg=data["fg"], + abv=data["abv"], + ibu=data["ibu"], + color=data["color"], + ) def format(self): msg = [] @@ -354,8 +369,8 @@ def format(self): style = self.create_style(category, subcategory) msg.append(style.format()) except StyleException: - name = self.data[category][subcategory]['style'] - msg.append("{}{} {} - Not parseable".format(category, - subcategory, - name)) - return '\n'.join(msg) + name = self.data[category][subcategory]["style"] + msg.append( + "{}{} {} - Not parseable".format(category, subcategory, name) + ) + return "\n".join(msg) diff --git a/brew/utilities/abv.py b/brew/utilities/abv.py index 3809f81..52365db 100644 --- a/brew/utilities/abv.py +++ b/brew/utilities/abv.py @@ -4,13 +4,13 @@ from .sugar import apparent_extract_to_real_extract __all__ = [ - u'apparent_attenuation', - u'real_attenuation', - u'real_attenuation_from_apparent_extract', - u'alcohol_by_volume_standard', - u'final_gravity_from_abv_standard', - u'alcohol_by_volume_alternative', - u'alcohol_by_weight', + u"apparent_attenuation", + u"real_attenuation", + u"real_attenuation_from_apparent_extract", + u"alcohol_by_volume_standard", + u"final_gravity_from_abv_standard", + u"alcohol_by_volume_alternative", + u"alcohol_by_weight", ] @@ -53,8 +53,7 @@ def real_attenuation_from_apparent_extract(original_extract, apparent_extract): :return: The percent of real attenuation :rtype: float """ - real_extract = apparent_extract_to_real_extract(original_extract, - apparent_extract) + real_extract = apparent_extract_to_real_extract(original_extract, apparent_extract) return real_attenuation(original_extract, real_extract) diff --git a/brew/utilities/color.py b/brew/utilities/color.py index fa42413..f51527f 100644 --- a/brew/utilities/color.py +++ b/brew/utilities/color.py @@ -7,20 +7,20 @@ from ..validators import validate_units __all__ = [ - u'srm_to_ebc', - u'ebc_to_srm', - u'calculate_mcu', - u'calculate_srm_mosher', - u'calculate_srm_daniels', - u'calculate_srm_daniels_power', - u'calculate_srm_noonan_power', - u'calculate_srm_morey_hybrid', - u'calculate_srm_morey', - u'calculate_srm', - u'lovibond_to_srm', - u'srm_to_lovibond', - u'srm_to_a430', - u'ebc_to_a430', + u"srm_to_ebc", + u"ebc_to_srm", + u"calculate_mcu", + u"calculate_srm_mosher", + u"calculate_srm_daniels", + u"calculate_srm_daniels_power", + u"calculate_srm_noonan_power", + u"calculate_srm_morey_hybrid", + u"calculate_srm_morey", + u"calculate_srm", + u"lovibond_to_srm", + u"srm_to_lovibond", + u"srm_to_a430", + u"ebc_to_a430", ] @@ -46,8 +46,7 @@ def ebc_to_srm(ebc): return ebc / 1.97 -def calculate_mcu(grain_weight, beer_color, final_volume, - units=IMPERIAL_UNITS): +def calculate_mcu(grain_weight, beer_color, final_volume, units=IMPERIAL_UNITS): """ Calculate MCU from Grain @@ -110,7 +109,9 @@ def calculate_srm_daniels_power(mcu): """ # noqa srm = 1.73 * (mcu ** 0.64) - 0.27 if srm > 50.0: - raise ColorException(u"Daniels Power equation does not work above SRM 50.0") # noqa + raise ColorException( + u"Daniels Power equation does not work above SRM 50.0" + ) # noqa return srm @@ -125,7 +126,9 @@ def calculate_srm_noonan_power(mcu): """ # noqa srm = 15.03 * (mcu ** 0.27) - 15.53 if srm > 50.0: - raise ColorException(u"Noonan Power equation does not work above SRM 50.0") # noqa + raise ColorException( + u"Noonan Power equation does not work above SRM 50.0" + ) # noqa return srm diff --git a/brew/utilities/efficiency.py b/brew/utilities/efficiency.py index 06d9bc7..ca5de46 100644 --- a/brew/utilities/efficiency.py +++ b/brew/utilities/efficiency.py @@ -3,10 +3,7 @@ from .sugar import sg_to_gu from ..constants import PPG_DME -__all__ = [ - u'calculate_brew_house_yield', - u'get_wort_correction', -] +__all__ = [u"calculate_brew_house_yield", u"get_wort_correction"] def calculate_brew_house_yield(wort_volume, sg, grain_additions): @@ -29,9 +26,9 @@ def calculate_brew_house_yield(wort_volume, sg, grain_additions): return (sg_to_gu(sg) * wort_volume) / total_gu -def get_wort_correction(boil_gravity, boil_volume, - final_gravity, final_volume, - efficiency=PPG_DME): +def get_wort_correction( + boil_gravity, boil_volume, final_gravity, final_volume, efficiency=PPG_DME +): """ Get amount of sugar to add to correct wort @@ -46,4 +43,6 @@ def get_wort_correction(boil_gravity, boil_volume, :return: The amount of DME or LME to add to the boil in lbs :rtype: float """ # noqa - return (final_gravity * final_volume - boil_gravity * boil_volume) / efficiency # noqa + return ( + final_gravity * final_volume - boil_gravity * boil_volume + ) / efficiency # noqa diff --git a/brew/utilities/hops.py b/brew/utilities/hops.py index 051d776..6c8a664 100644 --- a/brew/utilities/hops.py +++ b/brew/utilities/hops.py @@ -16,10 +16,10 @@ from ..validators import validate_units __all__ = [ - u'hop_type_weight_conversion', - u'HopsUtilization', - u'HopsUtilizationJackieRager', - u'HopsUtilizationGlennTinseth', + u"hop_type_weight_conversion", + u"HopsUtilization", + u"HopsUtilizationJackieRager", + u"HopsUtilizationGlennTinseth", ] @@ -61,8 +61,7 @@ class HopsUtilization(object): http://www.boondocks-brewing.com/hops """ - def __init__(self, hop_addition, - units=IMPERIAL_UNITS): + def __init__(self, hop_addition, units=IMPERIAL_UNITS): """ :param HopAddition hop_addition: A hop addition :param str units: The units @@ -95,8 +94,7 @@ def change_units(self): units = SI_UNITS elif self.units == SI_UNITS: units = IMPERIAL_UNITS - return HopsUtilization(self.hop_addition, - units=units) + return HopsUtilization(self.hop_addition, units=units) def get_ibus(self, sg, final_volume): """ @@ -110,20 +108,22 @@ def get_ibus(self, sg, final_volume): hops_constant = HOPS_CONSTANT_IMPERIAL if self.units == SI_UNITS: hops_constant = HOPS_CONSTANT_SI - utilization = self.get_percent_utilization( - sg, self.hop_addition.boil_time) + utilization = self.get_percent_utilization(sg, self.hop_addition.boil_time) # Hop weight for wet is greater than dry hop_weight = self.hop_addition.weight if self.hop_addition.hop_type == HOP_TYPE_WHOLE_WET: - hop_weight = hop_type_weight_conversion(hop_weight, - self.hop_addition.hop_type, - HOP_TYPE_WHOLE) + hop_weight = hop_type_weight_conversion( + hop_weight, self.hop_addition.hop_type, HOP_TYPE_WHOLE + ) # Utilization is 10% higher for pellet vs whole/plug if self.hop_addition.hop_type == HOP_TYPE_PELLET: utilization *= HOP_UTILIZATION_SCALE_PELLET - num = (hop_weight * utilization * - self.hop_addition.hop.percent_alpha_acids * - hops_constant) + num = ( + hop_weight + * utilization + * self.hop_addition.hop.percent_alpha_acids + * hops_constant + ) return num / final_volume @classmethod @@ -173,23 +173,30 @@ def format_utilization_table(cls): boil_time_list = list(range(0, 60, 3)) + list(range(60, 130, 10)) table = cls.get_utilization_table(gravity_list, boil_time_list) - title = u'Percent Alpha Acid Utilization - ' \ - u'Boil Time vs Wort Original Gravity' + title = ( + u"Percent Alpha Acid Utilization - " u"Boil Time vs Wort Original Gravity" + ) table_size = 92 out = [] out.append(title.center(table_size)) - out.append(str(u'=' * len(title)).center(table_size)) - out.append(u'\n') - out.append(u' '.join([u' ' * 4] + [u'{0:7.3f}'.format(l / 1000.0) - for l in gravity_list])) - out.append(u'-' * table_size) + out.append(str(u"=" * len(title)).center(table_size)) + out.append(u"\n") + out.append( + u" ".join( + [u" " * 4] + [u"{0:7.3f}".format(l / 1000.0) for l in gravity_list] + ) + ) + out.append(u"-" * table_size) for index, line in enumerate(table): boil_time = boil_time_list[index] - out.append(u'{0} {1}'.format( - str(boil_time).rjust(4), - u' '.join([u'{0:7.3f}'.format(aau) for aau in line]))) - return u'\n'.join([o.rstrip() for o in out if o != u'\n']) + out.append( + u"{0} {1}".format( + str(boil_time).rjust(4), + u" ".join([u"{0:7.3f}".format(aau) for aau in line]), + ) + ) + return u"\n".join([o.rstrip() for o in out if o != u"\n"]) class HopsUtilizationJackieRager(HopsUtilization): diff --git a/brew/utilities/malt.py b/brew/utilities/malt.py index 8dd9455..0abf2ff 100644 --- a/brew/utilities/malt.py +++ b/brew/utilities/malt.py @@ -10,24 +10,24 @@ from .sugar import gu_to_sg __all__ = [ - u'dry_to_liquid_malt_weight', - u'liquid_to_dry_malt_weight', - u'grain_to_liquid_malt_weight', - u'liquid_malt_to_grain_weight', - u'dry_malt_to_grain_weight', - u'grain_to_dry_malt_weight', - u'specialty_grain_to_liquid_malt_weight', - u'liquid_malt_to_specialty_grain_weight', - u'fine_grind_to_coarse_grind', - u'coarse_grind_to_fine_grind', - u'dry_basis_to_as_is_basis', - u'as_is_basis_to_dry_basis', - u'sg_from_dry_basis', - u'plato_from_dry_basis', - u'basis_to_hwe', - u'hwe_to_basis', - u'ppg_to_hwe', - u'hwe_to_ppg', + u"dry_to_liquid_malt_weight", + u"liquid_to_dry_malt_weight", + u"grain_to_liquid_malt_weight", + u"liquid_malt_to_grain_weight", + u"dry_malt_to_grain_weight", + u"grain_to_dry_malt_weight", + u"specialty_grain_to_liquid_malt_weight", + u"liquid_malt_to_specialty_grain_weight", + u"fine_grind_to_coarse_grind", + u"coarse_grind_to_fine_grind", + u"dry_basis_to_as_is_basis", + u"as_is_basis_to_dry_basis", + u"sg_from_dry_basis", + u"plato_from_dry_basis", + u"basis_to_hwe", + u"hwe_to_basis", + u"ppg_to_hwe", + u"hwe_to_ppg", ] @@ -151,8 +151,7 @@ def coarse_grind_to_fine_grind(coarse_grind, fc_diff=FC_DIFF_TWO_ROW): return coarse_grind + fc_diff -def dry_basis_to_as_is_basis(dry_basis, - moisture_content=MOISTURE_FINISHED_MALT): +def dry_basis_to_as_is_basis(dry_basis, moisture_content=MOISTURE_FINISHED_MALT): """ Dry Basis to As-Is Basis Percentage @@ -166,8 +165,7 @@ def dry_basis_to_as_is_basis(dry_basis, return dry_basis * (1.0 - moisture_content) -def as_is_basis_to_dry_basis(as_is, - moisture_content=MOISTURE_FINISHED_MALT): +def as_is_basis_to_dry_basis(as_is, moisture_content=MOISTURE_FINISHED_MALT): """ As-Is Basis to Dry Basis Percentage @@ -181,10 +179,12 @@ def as_is_basis_to_dry_basis(as_is, return as_is / (1.0 - moisture_content) -def sg_from_dry_basis(dbcg, - moisture_content=MOISTURE_FINISHED_MALT, - moisture_correction=MOISTURE_CORRECTION, - brew_house_efficiency=0.90): +def sg_from_dry_basis( + dbcg, + moisture_content=MOISTURE_FINISHED_MALT, + moisture_correction=MOISTURE_CORRECTION, + brew_house_efficiency=0.90, +): """ Specific Gravity from Dry Basis Percentage @@ -199,15 +199,20 @@ def sg_from_dry_basis(dbcg, validate_percentage(moisture_content) validate_percentage(moisture_correction) validate_percentage(brew_house_efficiency) - gu = ((dbcg - moisture_content - moisture_correction) * - brew_house_efficiency * SUCROSE_PPG) + gu = ( + (dbcg - moisture_content - moisture_correction) + * brew_house_efficiency + * SUCROSE_PPG + ) return gu_to_sg(gu) -def plato_from_dry_basis(dbcg, - moisture_content=MOISTURE_FINISHED_MALT, - moisture_correction=MOISTURE_CORRECTION, - brew_house_efficiency=0.90): +def plato_from_dry_basis( + dbcg, + moisture_content=MOISTURE_FINISHED_MALT, + moisture_correction=MOISTURE_CORRECTION, + brew_house_efficiency=0.90, +): """ Degrees Plato from Dry Basis Percentage @@ -222,8 +227,11 @@ def plato_from_dry_basis(dbcg, validate_percentage(moisture_content) validate_percentage(moisture_correction) validate_percentage(brew_house_efficiency) - return ((dbcg - moisture_content - moisture_correction) * - brew_house_efficiency * SUCROSE_PLATO) + return ( + (dbcg - moisture_content - moisture_correction) + * brew_house_efficiency + * SUCROSE_PLATO + ) def basis_to_hwe(basis_percentage): diff --git a/brew/utilities/sugar.py b/brew/utilities/sugar.py index 6709030..9e2b886 100644 --- a/brew/utilities/sugar.py +++ b/brew/utilities/sugar.py @@ -7,17 +7,17 @@ from .temperature import celsius_to_fahrenheit __all__ = [ - u'sg_to_gu', - u'gu_to_sg', - u'plato_to_sg', - u'sg_to_plato', - u'brix_to_sg', - u'sg_to_brix', - u'brix_to_plato', - u'plato_to_brix', - u'apparent_extract_to_real_extract', - u'hydrometer_adjustment', - u'refractometer_adjustment', + u"sg_to_gu", + u"gu_to_sg", + u"plato_to_sg", + u"sg_to_plato", + u"brix_to_sg", + u"sg_to_brix", + u"brix_to_plato", + u"plato_to_brix", + u"apparent_extract_to_real_extract", + u"hydrometer_adjustment", + u"refractometer_adjustment", ] @@ -118,7 +118,7 @@ def sg_to_brix(sg): """ if sg > 1.17874: raise SugarException(u"Above 40 degBx this function no longer works") - return (((182.4601 * sg - 775.6821) * sg + 1262.7794) * sg - 669.5622) + return ((182.4601 * sg - 775.6821) * sg + 1262.7794) * sg - 669.5622 def brix_to_plato(brix): @@ -169,7 +169,9 @@ def apparent_extract_to_real_extract(original_extract, apparent_extract): * Formula from Balling: De Clerck, Jean, A Textbook Of Brewing, Chapman & Hall Ltd., 1958 """ # noqa attenuation_coeff = 0.22 + 0.001 * original_extract - real_extract = (attenuation_coeff * original_extract + apparent_extract) / (1 + attenuation_coeff) # noqa + real_extract = (attenuation_coeff * original_extract + apparent_extract) / ( + 1 + attenuation_coeff + ) # noqa return real_extract @@ -201,18 +203,25 @@ def hydrometer_adjustment(sg, temp, units=IMPERIAL_UNITS): validate_units(units) if units == SI_UNITS: if temp < 0.0 or 100.0 < temp: - raise SugarException(u"Correction does not work outside temps 0 - 100C") # noqa + raise SugarException( + u"Correction does not work outside temps 0 - 100C" + ) # noqa temp = celsius_to_fahrenheit(temp) elif units == IMPERIAL_UNITS: if temp < 0.0 or 212.0 < temp: - raise SugarException(u"Correction does not work outside temps 0 - 212F") # noqa + raise SugarException( + u"Correction does not work outside temps 0 - 212F" + ) # noqa if temp == HYDROMETER_ADJUSTMENT_TEMP: return sg - correction = (1.313454 - 0.132674 * (temp ** 1) + - (2.057793 * 10 ** -3) * (temp ** 2) - - (2.627634 * 10 ** -6) * (temp ** 3)) + correction = ( + 1.313454 + - 0.132674 * (temp ** 1) + + (2.057793 * 10 ** -3) * (temp ** 2) + - (2.627634 * 10 ** -6) * (temp ** 3) + ) return sg + (correction * 0.001) @@ -236,8 +245,13 @@ def refractometer_adjustment(og, fg, wort_correction_factor=1.04): og_brix = sg_to_brix(og) / wort_correction_factor fg_brix = sg_to_brix(fg) / wort_correction_factor - new_fg = (1.0000 - - 0.0044993 * og_brix + 0.0117741 * fg_brix + - 0.000275806 * (og_brix ** 2) - 0.00127169 * (fg_brix ** 2) - - 0.00000727999 * (og_brix ** 3) + 0.0000632929 * (fg_brix ** 3)) + new_fg = ( + 1.0000 + - 0.0044993 * og_brix + + 0.0117741 * fg_brix + + 0.000275806 * (og_brix ** 2) + - 0.00127169 * (fg_brix ** 2) + - 0.00000727999 * (og_brix ** 3) + + 0.0000632929 * (fg_brix ** 3) + ) return new_fg diff --git a/brew/utilities/temperature.py b/brew/utilities/temperature.py index f72c7f2..0c5eed1 100644 --- a/brew/utilities/temperature.py +++ b/brew/utilities/temperature.py @@ -3,11 +3,11 @@ import math __all__ = [ - u'fahrenheit_to_celsius', - u'celsius_to_fahrenheit', - u'strike_temp', - u'mash_infusion', - u'boiling_point', + u"fahrenheit_to_celsius", + u"celsius_to_fahrenheit", + u"strike_temp", + u"mash_infusion", + u"boiling_point", ] @@ -30,7 +30,7 @@ def celsius_to_fahrenheit(temp): :return: The temperature in Fahrenheit :rtype: float """ - return(temp * 1.8) + 32.0 + return (temp * 1.8) + 32.0 def strike_temp(target_temp, initial_temp, liquor_to_grist_ratio=1.5): @@ -47,12 +47,12 @@ def strike_temp(target_temp, initial_temp, liquor_to_grist_ratio=1.5): :return: The strike water temperature :rtype: float """ # noqa - return (0.2 / liquor_to_grist_ratio) \ - * (target_temp - initial_temp) + target_temp + return (0.2 / liquor_to_grist_ratio) * (target_temp - initial_temp) + target_temp -def mash_infusion(target_temp, initial_temp, - grain_weight, water_volume, infusion_temp=212): +def mash_infusion( + target_temp, initial_temp, grain_weight, water_volume, infusion_temp=212 +): """ Get Volume of water to infuse into mash to reach scheduled temperature @@ -68,9 +68,11 @@ def mash_infusion(target_temp, initial_temp, :return: The volume of water to add to the mash (qt) :rtype: float """ - return (target_temp - initial_temp) \ - * (0.2 * grain_weight + water_volume) \ + return ( + (target_temp - initial_temp) + * (0.2 * grain_weight + water_volume) / (infusion_temp - target_temp) + ) def boiling_point(altitude): diff --git a/brew/utilities/yeast.py b/brew/utilities/yeast.py index 5580fb8..dd8aef8 100644 --- a/brew/utilities/yeast.py +++ b/brew/utilities/yeast.py @@ -15,11 +15,11 @@ from .sugar import sg_to_plato __all__ = [ - u'PITCH_RATE_MAP', - u'pitch_rate_conversion', - u'YeastModel', - u'KaiserYeastModel', - u'WhiteYeastModel', + u"PITCH_RATE_MAP", + u"pitch_rate_conversion", + u"YeastModel", + u"KaiserYeastModel", + u"WhiteYeastModel", ] @@ -34,14 +34,14 @@ # Pitch rate in M / ml / P PITCH_RATE_MAP = { - u'MFG Recommended (Ale, fresh yeast only)': 0.35, - u'MFG Recommended+ (Ale, fresh yeast only)': 0.55, - u'Pro Brewer (Ale, LG)': 0.75, - u'Pro Brewer (Ale)': 1.0, - u'Pro Brewer (Ale, HG)': 1.25, - u'Pro Brewer (Lager, LG)': 1.5, - u'Pro Brewer (Lager)': 1.75, - u'Pro Brewer (Lager, HG)': 2.0, + u"MFG Recommended (Ale, fresh yeast only)": 0.35, + u"MFG Recommended+ (Ale, fresh yeast only)": 0.55, + u"Pro Brewer (Ale, LG)": 0.75, + u"Pro Brewer (Ale)": 1.0, + u"Pro Brewer (Ale, HG)": 1.25, + u"Pro Brewer (Lager, LG)": 1.5, + u"Pro Brewer (Lager)": 1.75, + u"Pro Brewer (Lager, HG)": 2.0, } @@ -63,16 +63,13 @@ def pitch_rate_conversion(pitch_rate, units=IMPERIAL_UNITS): class YeastModel(object): - METHOD_TO_GROWTH_ADJ = { - u'no agitation': 0.0, - u'shaking': 0.0, - u'stir plate': 0.0, - } + METHOD_TO_GROWTH_ADJ = {u"no agitation": 0.0, u"shaking": 0.0, u"stir plate": 0.0} def __init__(self, method, units=IMPERIAL_UNITS): if method not in self.METHOD_TO_GROWTH_ADJ.keys(): - raise YeastException(u"Method '{}' not allowed for yeast model".format( # noqa - method)) + raise YeastException( + u"Method '{}' not allowed for yeast model".format(method) # noqa + ) self.method = method self.adjustment = self.METHOD_TO_GROWTH_ADJ[method] self.set_units(units) @@ -100,14 +97,16 @@ def get_viability(self, days_since_manufacture): return 0.0 return viability - def get_yeast_pitch_rate(self, - original_gravity=1.050, - final_volume=5.0, - target_pitch_rate=1.42, - yeast_type=u'liquid', - cells_per_pack=100, - num_packs=1, - days_since_manufacture=30): + def get_yeast_pitch_rate( + self, + original_gravity=1.050, + final_volume=5.0, + target_pitch_rate=1.42, + yeast_type=u"liquid", + cells_per_pack=100, + num_packs=1, + days_since_manufacture=30, + ): """ Determine yeast pitch rate @@ -144,49 +143,56 @@ def get_yeast_pitch_rate(self, else: required_growth_rate = pitch_rate_cells / cells - return {u'original_gravity': original_gravity, - u'final_volume': final_volume, - u'target_pitch_rate': target_pitch_rate, - u'viability': round(viability, 2), - u'cells': round(cells, 2), - u'pitch_rate_as_is': round(pitch_rate_as_is, 2), - u'pitch_rate_cells': round(pitch_rate_cells, 2), - u'cells_needed': round(pitch_rate_cells - cells, 2), - u'required_growth_rate': round(required_growth_rate, 2), - u'units': self.units, - } - - def get_starter_volume(self, - available_cells, - starter_volume=2.0 * GAL_PER_LITER, - original_gravity=1.036): + return { + u"original_gravity": original_gravity, + u"final_volume": final_volume, + u"target_pitch_rate": target_pitch_rate, + u"viability": round(viability, 2), + u"cells": round(cells, 2), + u"pitch_rate_as_is": round(pitch_rate_as_is, 2), + u"pitch_rate_cells": round(pitch_rate_cells, 2), + u"cells_needed": round(pitch_rate_cells - cells, 2), + u"required_growth_rate": round(required_growth_rate, 2), + u"units": self.units, + } + + def get_starter_volume( + self, + available_cells, + starter_volume=2.0 * GAL_PER_LITER, + original_gravity=1.036, + ): """ Calculate the number of cells given a stater volume and gravity """ - GPL = 2.845833 # g/P/L grams of extract per point of gravity per liter of starter # noqa + GPL = ( + 2.845833 + ) # g/P/L grams of extract per point of gravity per liter of starter # noqa dme = GPL * sg_to_gu(original_gravity) * starter_volume # in grams if self.units == IMPERIAL_UNITS: - inoculation_rate = available_cells / (starter_volume * LITER_PER_GAL) # noqa + inoculation_rate = available_cells / ( + starter_volume * LITER_PER_GAL + ) # noqa dme = dme * OZ_PER_G * LITER_PER_GAL elif self.units == SI_UNITS: inoculation_rate = available_cells / starter_volume growth_rate = self.get_growth_rate(inoculation_rate) end_cell_count = available_cells * (growth_rate + 1) - return {u'available_cells': round(available_cells, 2), - u'starter_volume': round(starter_volume, 2), - u'original_gravity': original_gravity, - u'dme': round(dme, 2), - u'inoculation_rate': round(inoculation_rate, 2), - u'growth_rate': round(growth_rate, 2), - u'end_cell_count': round(end_cell_count, 2), - u'units': self.units, - } - - def get_resulting_pitch_rate(self, - starter_cell_count, - original_gravity=1.036, - final_volume=5.0): + return { + u"available_cells": round(available_cells, 2), + u"starter_volume": round(starter_volume, 2), + u"original_gravity": original_gravity, + u"dme": round(dme, 2), + u"inoculation_rate": round(inoculation_rate, 2), + u"growth_rate": round(growth_rate, 2), + u"end_cell_count": round(end_cell_count, 2), + u"units": self.units, + } + + def get_resulting_pitch_rate( + self, starter_cell_count, original_gravity=1.036, final_volume=5.0 + ): if self.units == IMPERIAL_UNITS: modifier = sg_to_gu(original_gravity) elif self.units == SI_UNITS: @@ -205,11 +211,10 @@ class KaiserYeastModel(YeastModel): * http://braukaiser.com/blog/blog/2012/11/03/estimating-yeast-growth/ """ - METHOD_TO_GROWTH_ADJ = { - u'stir plate': 0.0, - } - def __init__(self, method=u'stir plate', units=IMPERIAL_UNITS): + METHOD_TO_GROWTH_ADJ = {u"stir plate": 0.0} + + def __init__(self, method=u"stir plate", units=IMPERIAL_UNITS): return super(KaiserYeastModel, self).__init__(method, units=units) def get_inoculation_rate(self, growth_rate): @@ -240,13 +245,9 @@ class WhiteYeastModel(YeastModel): # Linear Regression Least Squares INOCULATION_CONST = [-0.999499, 12.547938, -0.459486] - METHOD_TO_GROWTH_ADJ = { - u'no agitation': 0.0, - u'shaking': 0.5, - u'stir plate': 1.0, - } + METHOD_TO_GROWTH_ADJ = {u"no agitation": 0.0, u"shaking": 0.5, u"stir plate": 1.0} - def __init__(self, method=u'no agitation', units=IMPERIAL_UNITS): + def __init__(self, method=u"no agitation", units=IMPERIAL_UNITS): return super(WhiteYeastModel, self).__init__(method, units=units) def get_inoculation_rate(self, growth_rate): diff --git a/brew/validators.py b/brew/validators.py index e2068e8..8a0f2d7 100644 --- a/brew/validators.py +++ b/brew/validators.py @@ -6,12 +6,12 @@ from .exceptions import ValidatorException __all__ = [ - u'validate_grain_type', - u'validate_hop_type', - u'validate_percentage', - u'validate_units', - u'validate_required_fields', - u'validate_optional_fields', + u"validate_grain_type", + u"validate_hop_type", + u"validate_percentage", + u"validate_units", + u"validate_required_fields", + u"validate_optional_fields", ] @@ -26,8 +26,11 @@ def validate_grain_type(grain_type): """ if grain_type in GRAIN_TYPE_LIST: return grain_type - raise ValidatorException(u"Unkown grain type '{}', must use {}".format( - grain_type, u', '.join(GRAIN_TYPE_LIST))) + raise ValidatorException( + u"Unkown grain type '{}', must use {}".format( + grain_type, u", ".join(GRAIN_TYPE_LIST) + ) + ) def validate_hop_type(hop_type): @@ -41,8 +44,9 @@ def validate_hop_type(hop_type): """ if hop_type in HOP_TYPE_LIST: return hop_type - raise ValidatorException(u"Unkown hop type '{}', must use {}".format( - hop_type, u', '.join(HOP_TYPE_LIST))) + raise ValidatorException( + u"Unkown hop type '{}', must use {}".format(hop_type, u", ".join(HOP_TYPE_LIST)) + ) def validate_percentage(percent): @@ -70,8 +74,9 @@ def validate_units(units): """ if units in [IMPERIAL_UNITS, SI_UNITS]: return units - raise ValidatorException(u"Unkown units '{}', must use {} or {}".format( - units, IMPERIAL_UNITS, SI_UNITS)) + raise ValidatorException( + u"Unkown units '{}', must use {} or {}".format(units, IMPERIAL_UNITS, SI_UNITS) + ) def validate_required_fields(data, required_fields): @@ -90,19 +95,23 @@ def validate_required_fields(data, required_fields): """ for field, field_type in required_fields: if field not in data: - raise ValidatorException(u"Required field '{}' missing from data".format( # noqa - field)) + raise ValidatorException( + u"Required field '{}' missing from data".format(field) # noqa + ) if field_type == str: try: field_type = unicode except NameError: field_type = str if not isinstance(data[field], field_type): - raise ValidatorException(u"Required field '{}' is not of type '{}'".format( # noqa - field, field_type)) + raise ValidatorException( + u"Required field '{}' is not of type '{}'".format( # noqa + field, field_type + ) + ) -def validate_optional_fields(data, optional_fields, data_field=u'data'): +def validate_optional_fields(data, optional_fields, data_field=u"data"): """ Validate fields which are optional as part of the data. @@ -129,5 +138,8 @@ def validate_optional_fields(data, optional_fields, data_field=u'data'): # With optional fields only check the type as they are overrides # and not all overrides need to be present if not isinstance(data[data_field][field], field_type): - raise ValidatorException(u"Optional field '{}' in '{}' is not of type '{}'".format( # noqa - field, data_field, field_type)) + raise ValidatorException( + u"Optional field '{}' in '{}' is not of type '{}'".format( # noqa + field, data_field, field_type + ) + ) diff --git a/brew/yeasts.py b/brew/yeasts.py index f6141a8..c370860 100644 --- a/brew/yeasts.py +++ b/brew/yeasts.py @@ -8,7 +8,7 @@ from .validators import validate_percentage from .validators import validate_required_fields -__all__ = [u'Yeast'] +__all__ = [u"Yeast"] class Yeast(object): @@ -16,41 +16,42 @@ class Yeast(object): A representation of a type of Yeast as added to a Recipe. """ - def __init__(self, name, - percent_attenuation=0.75): + def __init__(self, name, percent_attenuation=0.75): """ :param float percent_attenuation: The percentage the yeast is expected to attenuate the sugar in the yeast to create alcohol :raises YeastException: If percent_attenuation is not provided """ # noqa self.name = name if percent_attenuation is None: - raise YeastException(u"{}: Must provide percent attenuation".format( # noqa - self.name)) + raise YeastException( + u"{}: Must provide percent attenuation".format(self.name) # noqa + ) self.percent_attenuation = validate_percentage(percent_attenuation) def __str__(self): if sys.version_info[0] >= 3: return self.__unicode__() else: - return self.__unicode__().encode(u'utf8') + return self.__unicode__().encode(u"utf8") def __unicode__(self): - return u"{0}, attenuation {1:0.1%}".format(self.name.capitalize(), - self.percent_attenuation) + return u"{0}, attenuation {1:0.1%}".format( + self.name.capitalize(), self.percent_attenuation + ) def __repr__(self): out = u"{0}('{1}'".format(type(self).__name__, self.name) if self.percent_attenuation: - out = u"{0}, percent_attenuation={1}".format( - out, self.percent_attenuation) + out = u"{0}, percent_attenuation={1}".format(out, self.percent_attenuation) out = u"{0})".format(out) return out def __eq__(self, other): if not isinstance(other, self.__class__): return False - if (self.name == other.name) and \ - (self.percent_attenuation == other.percent_attenuation): + if (self.name == other.name) and ( + self.percent_attenuation == other.percent_attenuation + ): return True return False @@ -58,28 +59,28 @@ def __ne__(self, other): return not self.__eq__(other) def to_dict(self): - return {u'name': self.name, - u'data': { - u'percent_attenuation': self.percent_attenuation, - }, - } + return { + u"name": self.name, + u"data": {u"percent_attenuation": self.percent_attenuation}, + } def to_json(self): return json.dumps(self.to_dict(), sort_keys=True) @classmethod def validate(cls, yeast_data): - required_fields = [(u'name', str), - ] - optional_fields = [(u'percent_attenuation', float), - ] + required_fields = [(u"name", str)] + optional_fields = [(u"percent_attenuation", float)] validate_required_fields(yeast_data, required_fields) validate_optional_fields(yeast_data, optional_fields) def format(self): - msg = textwrap.dedent(u"""\ + msg = textwrap.dedent( + u"""\ {name} Yeast ----------------------------------- Attenuation: {data[percent_attenuation]:0.1%}""".format( - **self.to_dict())) + **self.to_dict() + ) + ) return msg diff --git a/charts/ray_daniels/designing_great_beers/appendix_two_course_grind_potential_extract.py b/charts/ray_daniels/designing_great_beers/appendix_two_course_grind_potential_extract.py index 74d0923..2129b48 100644 --- a/charts/ray_daniels/designing_great_beers/appendix_two_course_grind_potential_extract.py +++ b/charts/ray_daniels/designing_great_beers/appendix_two_course_grind_potential_extract.py @@ -25,9 +25,8 @@ def get_chart(): chart = [] for dbcg in range(5000, 7600, 100) + range(7600, 8025, 25): sg = sg_from_dry_basis( - dbcg / 10000.0, - moisture_content=mc, - brew_house_efficiency=bhe) + dbcg / 10000.0, moisture_content=mc, brew_house_efficiency=bhe + ) gu = sg_to_gu(sg) chart.append([round(dbcg / 100.0, 2), round(gu, 2), round(sg, 4)]) return chart diff --git a/charts/ray_daniels/designing_great_beers/appendix_two_course_grind_potential_extract_modified.py b/charts/ray_daniels/designing_great_beers/appendix_two_course_grind_potential_extract_modified.py index 21aef4a..61e52b8 100644 --- a/charts/ray_daniels/designing_great_beers/appendix_two_course_grind_potential_extract_modified.py +++ b/charts/ray_daniels/designing_great_beers/appendix_two_course_grind_potential_extract_modified.py @@ -27,9 +27,8 @@ def get_chart(): chart = [] for dbcg in range(5000, 7600, 100) + range(7600, 8025, 25): sg = sg_from_dry_basis( - dbcg / 10000.0, - moisture_content=mc, - brew_house_efficiency=bhe) + dbcg / 10000.0, moisture_content=mc, brew_house_efficiency=bhe + ) gu = sg_to_gu(sg) chart.append([round(dbcg / 100.0, 2), round(gu, 2), round(sg, 4)]) return chart diff --git a/docs/source/conf.py b/docs/source/conf.py index c9e7f63..1d5c98e 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -15,56 +15,56 @@ import os import sys -on_rtd = os.environ.get('READTHEDOCS', None) == 'True' +on_rtd = os.environ.get("READTHEDOCS", None) == "True" # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -#sys.path.insert(0, os.path.abspath('.')) +# sys.path.insert(0, os.path.abspath('.')) # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. -#needs_sphinx = '1.0' +# needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.coverage', + "sphinx.ext.autodoc", + "sphinx.ext.coverage", # 'sphinx.ext.pngmath', - 'sphinx.ext.mathjax', - 'sphinx.ext.viewcode', + "sphinx.ext.mathjax", + "sphinx.ext.viewcode", ] # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # source_suffix = ['.rst', '.md'] -source_suffix = '.rst' +source_suffix = ".rst" # The encoding of source files. -#source_encoding = 'utf-8-sig' +# source_encoding = 'utf-8-sig' # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = u'Brewday' -copyright = u'2016, Chris Gilmer' -author = u'Chris Gilmer' +project = u"Brewday" +copyright = u"2016, Chris Gilmer" +author = u"Chris Gilmer" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = u'1.0.0' +version = u"1.0.0" # The full version, including alpha/beta/rc tags. -release = u'1.0.0' +release = u"1.0.0" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -75,9 +75,9 @@ # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: -#today = '' +# today = '' # Else, today_fmt is used as the format for a strftime call. -#today_fmt = '%B %d, %Y' +# today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. @@ -85,27 +85,27 @@ # The reST default role (used for this markup: `text`) to use for all # documents. -#default_role = None +# default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. -#add_function_parentheses = True +# add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). -#add_module_names = True +# add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. -#show_authors = False +# show_authors = False # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] +# modindex_common_prefix = [] # If true, keep warnings as "system message" paragraphs in the built documents. -#keep_warnings = False +# keep_warnings = False # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False @@ -115,160 +115,154 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -#html_theme = 'alabaster' +# html_theme = 'alabaster' if not on_rtd: # only import and set the theme if we're building docs locally import sphinx_rtd_theme - html_theme = 'sphinx_rtd_theme' + + html_theme = "sphinx_rtd_theme" html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. -#html_theme_options = {} +# html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. -#html_theme_path = [] +# html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". -#html_title = None +# html_title = None # A shorter title for the navigation bar. Default is the same as html_title. -#html_short_title = None +# html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. -#html_logo = None +# html_logo = None # The name of an image file (relative to this directory) to use as a favicon of # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. -#html_favicon = None +# html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -#html_static_path = ['_static'] +# html_static_path = ['_static'] # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied # directly to the root of the documentation. -#html_extra_path = [] +# html_extra_path = [] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. -#html_last_updated_fmt = '%b %d, %Y' +# html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. -#html_use_smartypants = True +# html_use_smartypants = True # Custom sidebar templates, maps document names to template names. -#html_sidebars = {} +# html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. -#html_additional_pages = {} +# html_additional_pages = {} # If false, no module index is generated. -#html_domain_indices = True +# html_domain_indices = True # If false, no index is generated. -#html_use_index = True +# html_use_index = True # If true, the index is split into individual pages for each letter. -#html_split_index = False +# html_split_index = False # If true, links to the reST sources are added to the pages. -#html_show_sourcelink = True +# html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -#html_show_sphinx = True +# html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -#html_show_copyright = True +# html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. -#html_use_opensearch = '' +# html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). -#html_file_suffix = None +# html_file_suffix = None # Language to be used for generating the HTML full-text search index. # Sphinx supports the following languages: # 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' # 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr' -#html_search_language = 'en' +# html_search_language = 'en' # A dictionary with options for the search language support, empty by default. # Now only 'ja' uses this config value -#html_search_options = {'type': 'default'} +# html_search_options = {'type': 'default'} # The name of a javascript file (relative to the configuration directory) that # implements a search results scorer. If empty, the default will be used. -#html_search_scorer = 'scorer.js' +# html_search_scorer = 'scorer.js' # Output file base name for HTML help builder. -htmlhelp_basename = 'Brewdaydoc' +htmlhelp_basename = "Brewdaydoc" # -- Options for LaTeX output --------------------------------------------- latex_elements = { -# The paper size ('letterpaper' or 'a4paper'). -#'papersize': 'letterpaper', - -# The font size ('10pt', '11pt' or '12pt'). -#'pointsize': '10pt', - -# Additional stuff for the LaTeX preamble. -#'preamble': '', - -# Latex figure (float) alignment -#'figure_align': 'htbp', + # The paper size ('letterpaper' or 'a4paper'). + #'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + #'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + #'preamble': '', + # Latex figure (float) alignment + #'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'Brewday.tex', u'Brewday Documentation', - u'Chris Gilmer', 'manual'), + (master_doc, "Brewday.tex", u"Brewday Documentation", u"Chris Gilmer", "manual") ] # The name of an image file (relative to this directory) to place at the top of # the title page. -#latex_logo = None +# latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. -#latex_use_parts = False +# latex_use_parts = False # If true, show page references after internal links. -#latex_show_pagerefs = False +# latex_show_pagerefs = False # If true, show URL addresses after external links. -#latex_show_urls = False +# latex_show_urls = False # Documents to append as an appendix to all manuals. -#latex_appendices = [] +# latex_appendices = [] # If false, no module index is generated. -#latex_domain_indices = True +# latex_domain_indices = True # -- Options for manual page output --------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). -man_pages = [ - (master_doc, 'brewday', u'BrewDay Documentation', - [author], 1) -] +man_pages = [(master_doc, "brewday", u"BrewDay Documentation", [author], 1)] # If true, show URL addresses after external links. -#man_show_urls = False +# man_show_urls = False # -- Options for Texinfo output ------------------------------------------- @@ -277,25 +271,33 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'BrewDay', u'Brewday Documentation', - author, 'Brewday', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "BrewDay", + u"Brewday Documentation", + author, + "Brewday", + "One line description of project.", + "Miscellaneous", + ) ] # Documents to append as an appendix to all manuals. -#texinfo_appendices = [] +# texinfo_appendices = [] # If false, no module index is generated. -#texinfo_domain_indices = True +# texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. -#texinfo_show_urls = 'footnote' +# texinfo_show_urls = 'footnote' # If true, do not generate a @detailmenu in the "Top" node's menu. -#texinfo_no_detailmenu = False +# texinfo_no_detailmenu = False # -- Additional Config ---------------------------------------------------- -autoclass_content = 'both' -mathjax_path = 'https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML' # noqa +autoclass_content = "both" +mathjax_path = ( + "https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML" +) # noqa diff --git a/examples/brewing_classic_styles/biere_de_linde_dict.py b/examples/brewing_classic_styles/biere_de_linde_dict.py index 27304b6..c29de22 100644 --- a/examples/brewing_classic_styles/biere_de_linde_dict.py +++ b/examples/brewing_classic_styles/biere_de_linde_dict.py @@ -35,70 +35,64 @@ def main(): recipe = { - u'name': u"Biere de l'Inde (Extract)", - u'start_volume': 7.0, - u'final_volume': 6.0, - u'grains': [ - {u'name': u'English Pale Ale Liquid Extract', - u'data': { - u'color': 3.5, - u'ppg': 37, - }, - u'weight': 8.7, - u'grain_type': u'lme'}, - {u'name': u'wheat liquid extract', - u'data': { - u'color': 4.0, - u'ppg': 37, - }, - u'weight': 0.5, - u'grain_type': u'lme'}, - {u'name': u'biscuit malt', - u'data': { - u'color': 25.0, - }, - u'weight': 0.5, - u'grain_type': u'specialty'}, - {u'name': u'caramel crystal malt 40l', - u'weight': 0.5, - u'grain_type': u'specialty'}, - {u'name': u'caramel crystal malt 120l', - u'weight': 0.375, - u'grain_type': u'specialty'}, - ], - u'hops': [ - {u'name': u'challenger', - u'data': { - u'percent_alpha_acids': 0.08, - }, - u'weight': 1.43, - u'boil_time': 60.0}, - {u'name': u'fuggle', - u'data': { - u'percent_alpha_acids': 0.05, - }, - u'weight': 1.5, - u'boil_time': 10.0}, - {u'name': u'east kent golding', - u'data': { - u'percent_alpha_acids': 0.05, - }, - u'weight': 1.5, - u'boil_time': 0.0}, + u"name": u"Biere de l'Inde (Extract)", + u"start_volume": 7.0, + u"final_volume": 6.0, + u"grains": [ + { + u"name": u"English Pale Ale Liquid Extract", + u"data": {u"color": 3.5, u"ppg": 37}, + u"weight": 8.7, + u"grain_type": u"lme", + }, + { + u"name": u"wheat liquid extract", + u"data": {u"color": 4.0, u"ppg": 37}, + u"weight": 0.5, + u"grain_type": u"lme", + }, + { + u"name": u"biscuit malt", + u"data": {u"color": 25.0}, + u"weight": 0.5, + u"grain_type": u"specialty", + }, + { + u"name": u"caramel crystal malt 40l", + u"weight": 0.5, + u"grain_type": u"specialty", + }, + { + u"name": u"caramel crystal malt 120l", + u"weight": 0.375, + u"grain_type": u"specialty", + }, ], - u'yeast': { - u'name': u'Wyeast 1028', - u'data': { - u'percent_attenuation': 0.74, + u"hops": [ + { + u"name": u"challenger", + u"data": {u"percent_alpha_acids": 0.08}, + u"weight": 1.43, + u"boil_time": 60.0, + }, + { + u"name": u"fuggle", + u"data": {u"percent_alpha_acids": 0.05}, + u"weight": 1.5, + u"boil_time": 10.0, }, - }, - u'data': { - u'brew_house_yield': 0.70, - u'units': u'imperial', - }, + { + u"name": u"east kent golding", + u"data": {u"percent_alpha_acids": 0.05}, + u"weight": 1.5, + u"boil_time": 0.0, + }, + ], + u"yeast": {u"name": u"Wyeast 1028", u"data": {u"percent_attenuation": 0.74}}, + u"data": {u"brew_house_yield": 0.70, u"units": u"imperial"}, } - data_dir = os.path.abspath(os.path.join(os.getcwd(), 'data/')) + data_dir = os.path.abspath(os.path.join(os.getcwd(), "data/")) loader = JSONDataLoader(data_dir) beer = parse_recipe(recipe, loader) print(beer.format()) diff --git a/examples/brewing_classic_styles/munich_madness_dict.py b/examples/brewing_classic_styles/munich_madness_dict.py index 673d341..3497165 100644 --- a/examples/brewing_classic_styles/munich_madness_dict.py +++ b/examples/brewing_classic_styles/munich_madness_dict.py @@ -35,56 +35,39 @@ def main(): recipe = { - u'name': u"Munich Madness (All Grain)", - u'start_volume': 7.0, - u'final_volume': 6.0, - u'grains': [ - {u'name': u'Pilsner 2 row Ger', - u'data': { - u'color': 2.3, - }, - u'weight': 5.0}, - {u'name': u'Munich Malt 10L', - u'data': { - u'color': 9.0, - }, - u'weight': 4.0}, - {u'name': u'Vienna Malt', - u'weight': 3.0}, - {u'name': u'Caramunich Malt', - u'data': { - u'color': 60.0, - }, - u'weight': 1.0, - u'grain_type': u'specialty'}, - ], - u'hops': [ - {u'name': u'Hallertau US', - u'data': { - u'percent_alpha_acids': 0.04, - }, - u'weight': 1.5, - u'boil_time': 60.0}, - {u'name': u'Hallertau US', - u'data': { - u'percent_alpha_acids': 0.04, - }, - u'weight': 0.5, - u'boil_time': 20.0}, + u"name": u"Munich Madness (All Grain)", + u"start_volume": 7.0, + u"final_volume": 6.0, + u"grains": [ + {u"name": u"Pilsner 2 row Ger", u"data": {u"color": 2.3}, u"weight": 5.0}, + {u"name": u"Munich Malt 10L", u"data": {u"color": 9.0}, u"weight": 4.0}, + {u"name": u"Vienna Malt", u"weight": 3.0}, + { + u"name": u"Caramunich Malt", + u"data": {u"color": 60.0}, + u"weight": 1.0, + u"grain_type": u"specialty", + }, ], - u'yeast': { - u'name': u'Wyeast 2206', - u'data': { - u'percent_attenuation': 0.73, + u"hops": [ + { + u"name": u"Hallertau US", + u"data": {u"percent_alpha_acids": 0.04}, + u"weight": 1.5, + u"boil_time": 60.0, }, - }, - u'data': { - u'brew_house_yield': 0.70, - u'units': u'imperial', - }, + { + u"name": u"Hallertau US", + u"data": {u"percent_alpha_acids": 0.04}, + u"weight": 0.5, + u"boil_time": 20.0, + }, + ], + u"yeast": {u"name": u"Wyeast 2206", u"data": {u"percent_attenuation": 0.73}}, + u"data": {u"brew_house_yield": 0.70, u"units": u"imperial"}, } - data_dir = os.path.abspath(os.path.join(os.getcwd(), 'data/')) + data_dir = os.path.abspath(os.path.join(os.getcwd(), "data/")) loader = JSONDataLoader(data_dir) beer = parse_recipe(recipe, loader) print(beer.format()) diff --git a/examples/brewing_classic_styles/raison_de_saison_dict.py b/examples/brewing_classic_styles/raison_de_saison_dict.py index b8318c5..7156710 100644 --- a/examples/brewing_classic_styles/raison_de_saison_dict.py +++ b/examples/brewing_classic_styles/raison_de_saison_dict.py @@ -35,68 +35,55 @@ def main(): recipe = { - u'name': u"Raison de Saison (Extract)", - u'start_volume': 7.0, - u'final_volume': 6.0, - u'grains': [ - {u'name': u'Pilsner Liquid Extract', - u'data': { - u'color': 2.3, - u'ppg': 37, - }, - u'weight': 7.7, - u'grain_type': u'lme'}, - {u'name': u'Cane Beet Sugar', - u'weight': 1.0, - u'grain_type': u'dme'}, - {u'name': u'Wheat Liquid Extract', - u'data': { - u'color': 4.0, - u'ppg': 37, - }, - u'weight': 0.75, - u'grain_type': u'lme'}, - {u'name': u'munich liquid malt extract', - u'data': { - u'color': 9.0, - u'ppg': 37, - }, - u'weight': 0.5, - u'grain_type': u'lme'}, - {u'name': u'Caramunich Malt', - u'data': { - u'color': 60.0, - }, - u'weight': 0.125, - u'grain_type': u'specialty'}, - ], - u'hops': [ - {u'name': u'Hallertau US', - u'data': { - u'percent_alpha_acids': 0.05, - }, - u'weight': 1.7, - u'boil_time': 60.0}, - {u'name': u'Hallertau US', - u'data': { - u'percent_alpha_acids': 0.05, - }, - u'weight': 0.75, - u'boil_time': 0.0}, + u"name": u"Raison de Saison (Extract)", + u"start_volume": 7.0, + u"final_volume": 6.0, + u"grains": [ + { + u"name": u"Pilsner Liquid Extract", + u"data": {u"color": 2.3, u"ppg": 37}, + u"weight": 7.7, + u"grain_type": u"lme", + }, + {u"name": u"Cane Beet Sugar", u"weight": 1.0, u"grain_type": u"dme"}, + { + u"name": u"Wheat Liquid Extract", + u"data": {u"color": 4.0, u"ppg": 37}, + u"weight": 0.75, + u"grain_type": u"lme", + }, + { + u"name": u"munich liquid malt extract", + u"data": {u"color": 9.0, u"ppg": 37}, + u"weight": 0.5, + u"grain_type": u"lme", + }, + { + u"name": u"Caramunich Malt", + u"data": {u"color": 60.0}, + u"weight": 0.125, + u"grain_type": u"specialty", + }, ], - u'yeast': { - u'name': u'Wyeast 3724', - u'data': { - u'percent_attenuation': 0.86, + u"hops": [ + { + u"name": u"Hallertau US", + u"data": {u"percent_alpha_acids": 0.05}, + u"weight": 1.7, + u"boil_time": 60.0, + }, + { + u"name": u"Hallertau US", + u"data": {u"percent_alpha_acids": 0.05}, + u"weight": 0.75, + u"boil_time": 0.0, }, - }, - u'data': { - u'brew_house_yield': 0.70, - u'units': u'imperial', - }, + ], + u"yeast": {u"name": u"Wyeast 3724", u"data": {u"percent_attenuation": 0.86}}, + u"data": {u"brew_house_yield": 0.70, u"units": u"imperial"}, } - data_dir = os.path.abspath(os.path.join(os.getcwd(), 'data/')) + data_dir = os.path.abspath(os.path.join(os.getcwd(), "data/")) loader = JSONDataLoader(data_dir) beer = parse_recipe(recipe, loader) print(beer.format()) diff --git a/examples/enzymatic_rests.py b/examples/enzymatic_rests.py index 6130cd7..eb3e47d 100644 --- a/examples/enzymatic_rests.py +++ b/examples/enzymatic_rests.py @@ -19,12 +19,16 @@ def main(): target_temp = 110 initial_temp = 70 # grain temperature without water - sk_temp = strike_temp(target_temp, initial_temp, - liquor_to_grist_ratio=liquor_to_grist_ratio) + sk_temp = strike_temp( + target_temp, initial_temp, liquor_to_grist_ratio=liquor_to_grist_ratio + ) print("") - print("Bring {} qts of water to {} degF before adding grains".format( - water_volume, round(sk_temp, 1))) # noqa + print( + "Bring {} qts of water to {} degF before adding grains".format( + water_volume, round(sk_temp, 1) + ) + ) # noqa print("Your temperature should then reach {} degF".format(target_temp)) print("Keep your temperature here for 20 minutes") @@ -32,12 +36,18 @@ def main(): target_temp = 140 infusion_temp = 210 - infusion_volume = mash_infusion(target_temp, initial_temp, - grain_weight, water_volume, - infusion_temp=infusion_temp) + infusion_volume = mash_infusion( + target_temp, + initial_temp, + grain_weight, + water_volume, + infusion_temp=infusion_temp, + ) print("") - print("Add {} qts of {} degF water".format(round(infusion_volume, 1), infusion_temp)) # noqa + print( + "Add {} qts of {} degF water".format(round(infusion_volume, 1), infusion_temp) + ) # noqa print("Your temperature should then reach {} degF".format(target_temp)) print("Keep your temperature here for 40 minutes") @@ -46,12 +56,18 @@ def main(): infusion_temp = 210 water_volume += infusion_volume - infusion_volume = mash_infusion(target_temp, initial_temp, - grain_weight, water_volume, - infusion_temp=infusion_temp) + infusion_volume = mash_infusion( + target_temp, + initial_temp, + grain_weight, + water_volume, + infusion_temp=infusion_temp, + ) print("") - print("Add {} qts of {} degF water".format(round(infusion_volume, 1), infusion_temp)) # noqa + print( + "Add {} qts of {} degF water".format(round(infusion_volume, 1), infusion_temp) + ) # noqa print("Your temperature should then reach {} degF".format(target_temp)) print("Keep your temperature here for 20 minutes") print("") diff --git a/examples/oak_barrel_winecraft/kolsch_ale_dict.py b/examples/oak_barrel_winecraft/kolsch_ale_dict.py index fc47d9b..8d2fc47 100644 --- a/examples/oak_barrel_winecraft/kolsch_ale_dict.py +++ b/examples/oak_barrel_winecraft/kolsch_ale_dict.py @@ -34,45 +34,41 @@ def main(): recipe = { - u'name': u"Kölsch Ale (Extract)", - u'start_volume': 2.5, - u'final_volume': 5.0, - u'grains': [ - {u'name': u'Pilsner Liquid Extract', - u'weight': 3.25, - u'grain_type': u'lme'}, - {u'name': u'Munich Liquid Extract', - u'data': { - u'color': 10.0, - u'ppg': 36, - }, - u'weight': 3.25, - u'grain_type': u'lme'}, - {u'name': u'White Wheat Malt', - u'weight': 0.25, - u'grain_type': u'specialty'}, - {u'name': u'Caramel Crystal Malt 10l', - u'weight': 0.25, - u'grain_type': u'specialty'}, + u"name": u"Kölsch Ale (Extract)", + u"start_volume": 2.5, + u"final_volume": 5.0, + u"grains": [ + { + u"name": u"Pilsner Liquid Extract", + u"weight": 3.25, + u"grain_type": u"lme", + }, + { + u"name": u"Munich Liquid Extract", + u"data": {u"color": 10.0, u"ppg": 36}, + u"weight": 3.25, + u"grain_type": u"lme", + }, + { + u"name": u"White Wheat Malt", + u"weight": 0.25, + u"grain_type": u"specialty", + }, + { + u"name": u"Caramel Crystal Malt 10l", + u"weight": 0.25, + u"grain_type": u"specialty", + }, ], - u'hops': [ - {u'name': u'Vanguard', - u'weight': 1.0, - u'boil_time': 60.0}, - {u'name': u'hersbrucker', - u'weight': 1.0, - u'boil_time': 0.0}, + u"hops": [ + {u"name": u"Vanguard", u"weight": 1.0, u"boil_time": 60.0}, + {u"name": u"hersbrucker", u"weight": 1.0, u"boil_time": 0.0}, ], - u'yeast': { - u'name': u'White Labs Wlp029', - }, - u'data': { - u'brew_house_yield': 0.70, - u'units': u'imperial', - }, + u"yeast": {u"name": u"White Labs Wlp029"}, + u"data": {u"brew_house_yield": 0.70, u"units": u"imperial"}, } - data_dir = os.path.abspath(os.path.join(os.getcwd(), 'data/')) + data_dir = os.path.abspath(os.path.join(os.getcwd(), "data/")) loader = JSONDataLoader(data_dir) beer = parse_recipe(recipe, loader) print(beer.format()) diff --git a/examples/pale_ale_builder.py b/examples/pale_ale_builder.py index ba06dfb..bee319c 100644 --- a/examples/pale_ale_builder.py +++ b/examples/pale_ale_builder.py @@ -12,38 +12,33 @@ def main(): # Define Grains - pale = Grain(u'pale 2-row', - color=2.0, - ppg=37.0) - crystal = Grain(u'crystal C20', - color=20.0, - ppg=35.0) + pale = Grain(u"pale 2-row", color=2.0, ppg=37.0) + crystal = Grain(u"crystal C20", color=20.0, ppg=35.0) grain_list = [pale, crystal] # Define Hops - centennial = Hop(name=u'centennial', - percent_alpha_acids=0.14) - cascade = Hop(name=u'cascade', - percent_alpha_acids=0.07) + centennial = Hop(name=u"centennial", percent_alpha_acids=0.14) + cascade = Hop(name=u"cascade", percent_alpha_acids=0.07) hop_list = [centennial, cascade] # Define Builder - builder = RecipeBuilder(name=u'Pale Ale', - grain_list=grain_list, - hop_list=hop_list, - target_ibu=33.0, - target_og=1.0761348, - brew_house_yield=0.70, - start_volume=7.0, - final_volume=5.0, - ) + builder = RecipeBuilder( + name=u"Pale Ale", + grain_list=grain_list, + hop_list=hop_list, + target_ibu=33.0, + target_og=1.0761348, + brew_house_yield=0.70, + start_volume=7.0, + final_volume=5.0, + ) # Get Grain Bill percent_list = [0.95, 0.05] grain_additions = builder.get_grain_additions(percent_list) for grain_add in grain_additions: print(grain_add.format()) - print(u'') + print(u"") # Get Hop Bill percent_list = [0.8827, 0.1173] @@ -51,7 +46,7 @@ def main(): hop_additions = builder.get_hop_additions(percent_list, boil_time_list) for hop_add in hop_additions: print(hop_add.format()) - print(u'') + print(u"") if __name__ == "__main__": diff --git a/examples/pale_ale_builder2.py b/examples/pale_ale_builder2.py index 78ab406..3cdf344 100644 --- a/examples/pale_ale_builder2.py +++ b/examples/pale_ale_builder2.py @@ -12,38 +12,33 @@ def main(): # Define Grains - pale = Grain(u'pale 2-row', - color=2.0, - ppg=37.0) - crystal = Grain(u'crystal C20', - color=20.0, - ppg=35.0) + pale = Grain(u"pale 2-row", color=2.0, ppg=37.0) + crystal = Grain(u"crystal C20", color=20.0, ppg=35.0) grain_list = [pale, crystal] # Define Hops - centennial = Hop(name=u'centennial', - percent_alpha_acids=0.14) - cascade = Hop(name=u'cascade', - percent_alpha_acids=0.07) + centennial = Hop(name=u"centennial", percent_alpha_acids=0.14) + cascade = Hop(name=u"cascade", percent_alpha_acids=0.07) hop_list = [centennial, cascade] # Define Builder - builder = RecipeBuilder(name=u'Pale Ale', - grain_list=grain_list, - hop_list=hop_list, - target_ibu=33.0, - target_og=1.05, - brew_house_yield=0.70, - start_volume=7.0, - final_volume=5.0, - ) + builder = RecipeBuilder( + name=u"Pale Ale", + grain_list=grain_list, + hop_list=hop_list, + target_ibu=33.0, + target_og=1.05, + brew_house_yield=0.70, + start_volume=7.0, + final_volume=5.0, + ) # Get Grain Bill percent_list = [0.90, 0.10] grain_additions = builder.get_grain_additions(percent_list) for grain_add in grain_additions: print(grain_add.format()) - print(u'') + print(u"") # Get Hop Bill percent_list = [0.8827, 0.1173] @@ -51,7 +46,7 @@ def main(): hop_additions = builder.get_hop_additions(percent_list, boil_time_list) for hop_add in hop_additions: print(hop_add.format()) - print(u'') + print(u"") if __name__ == "__main__": diff --git a/examples/pale_ale_parser.py b/examples/pale_ale_parser.py index 0235df9..767b921 100644 --- a/examples/pale_ale_parser.py +++ b/examples/pale_ale_parser.py @@ -14,50 +14,40 @@ def main(): recipe = { - u'name': u'Pale Ale', - u'start_volume': 7.0, - u'final_volume': 5.0, - u'grains': [ - {u'name': u'pale malt 2-row us', - u'data': { - u'color': 1.8, - u'ppg': 37, - }, - u'weight': 13.96}, - {u'name': u'caramel crystal malt 20l', - u'data': { - u'color': 20.0, - u'ppg': 35, - }, - u'weight': 0.78}, - ], - u'hops': [ - {u'name': u'centennial', - u'data': { - u'percent_alpha_acids': 0.14, - }, - u'weight': 0.57, - u'boil_time': 60.0}, - {u'name': u'cascade us', - u'data': { - u'percent_alpha_acids': 0.07, - }, - u'weight': 0.76, - u'boil_time': 5.0}, + u"name": u"Pale Ale", + u"start_volume": 7.0, + u"final_volume": 5.0, + u"grains": [ + { + u"name": u"pale malt 2-row us", + u"data": {u"color": 1.8, u"ppg": 37}, + u"weight": 13.96, + }, + { + u"name": u"caramel crystal malt 20l", + u"data": {u"color": 20.0, u"ppg": 35}, + u"weight": 0.78, + }, ], - u'yeast': { - u'name': u'Wyeast 1056', - u'data': { - u'percent_attenuation': 0.75, + u"hops": [ + { + u"name": u"centennial", + u"data": {u"percent_alpha_acids": 0.14}, + u"weight": 0.57, + u"boil_time": 60.0, }, - }, - u'data': { - u'brew_house_yield': 0.70, - u'units': u'imperial', - }, + { + u"name": u"cascade us", + u"data": {u"percent_alpha_acids": 0.07}, + u"weight": 0.76, + u"boil_time": 5.0, + }, + ], + u"yeast": {u"name": u"Wyeast 1056", u"data": {u"percent_attenuation": 0.75}}, + u"data": {u"brew_house_yield": 0.70, u"units": u"imperial"}, } - data_dir = os.path.abspath(os.path.join(os.getcwd(), 'data/')) + data_dir = os.path.abspath(os.path.join(os.getcwd(), "data/")) loader = JSONDataLoader(data_dir) beer = parse_recipe(recipe, loader) print(beer.format()) diff --git a/examples/pale_ale_recipe.py b/examples/pale_ale_recipe.py index 907f126..0c8f1af 100644 --- a/examples/pale_ale_recipe.py +++ b/examples/pale_ale_recipe.py @@ -15,43 +15,32 @@ def main(): # Define Grains - pale = Grain(u'Pale Malt (2 Row) US', - color=1.8, - ppg=37) - pale_add = GrainAddition(pale, - weight=13.96) - crystal = Grain(u'Caramel/Crystal Malt - 20L', - color=20.0, - ppg=35) - crystal_add = GrainAddition(crystal, - weight=0.78) + pale = Grain(u"Pale Malt (2 Row) US", color=1.8, ppg=37) + pale_add = GrainAddition(pale, weight=13.96) + crystal = Grain(u"Caramel/Crystal Malt - 20L", color=20.0, ppg=35) + crystal_add = GrainAddition(crystal, weight=0.78) grain_additions = [pale_add, crystal_add] # Define Hops - centennial = Hop(u'Centennial', - percent_alpha_acids=0.14) - centennial_add = HopAddition(centennial, - weight=0.57, - boil_time=60.0) - cascade = Hop(u'Cascade (US)', - percent_alpha_acids=0.07) - cascade_add = HopAddition(cascade, - weight=0.76, - boil_time=5.0) + centennial = Hop(u"Centennial", percent_alpha_acids=0.14) + centennial_add = HopAddition(centennial, weight=0.57, boil_time=60.0) + cascade = Hop(u"Cascade (US)", percent_alpha_acids=0.07) + cascade_add = HopAddition(cascade, weight=0.76, boil_time=5.0) hop_additions = [centennial_add, cascade_add] # Define Yeast - yeast = Yeast(u'Wyeast 1056') + yeast = Yeast(u"Wyeast 1056") # Define Recipe - beer = Recipe(u'pale ale', - grain_additions=grain_additions, - hop_additions=hop_additions, - yeast=yeast, - brew_house_yield=0.70, # % - start_volume=7.0, # G - final_volume=5.0, # G - ) + beer = Recipe( + u"pale ale", + grain_additions=grain_additions, + hop_additions=hop_additions, + yeast=yeast, + brew_house_yield=0.70, # % + start_volume=7.0, # G + final_volume=5.0, # G + ) print(beer.format()) diff --git a/examples/styles.py b/examples/styles.py index d4de85b..37894a9 100644 --- a/examples/styles.py +++ b/examples/styles.py @@ -12,8 +12,8 @@ def main(): - data_dir = os.path.abspath(os.path.join(os.getcwd(), 'data/')) - factory = StyleFactory(os.path.join(data_dir, 'bjcp', 'styles.json')) + data_dir = os.path.abspath(os.path.join(os.getcwd(), "data/")) + factory = StyleFactory(os.path.join(data_dir, "bjcp", "styles.json")) print(factory.format()) diff --git a/examples/the_brew_shop/10_pound_stout.py b/examples/the_brew_shop/10_pound_stout.py index b68d3cd..3abc832 100644 --- a/examples/the_brew_shop/10_pound_stout.py +++ b/examples/the_brew_shop/10_pound_stout.py @@ -35,44 +35,33 @@ def main(): recipe = { - u'name': u"10 Pound Stout (Extract)", - u'start_volume': 4.0, - u'final_volume': 5.0, - u'grains': [ - {u'name': u'Amber Liquid Extract', - u'weight': 7.0, - u'grain_type': u'lme'}, - {u'name': u'Dark Dry Extract', - u'weight': 3.0, - u'grain_type': u'dme'}, - {u'name': u'Caramel Crystal Malt 120l', - u'weight': 1.0, - u'grain_type': u'specialty'}, - {u'name': u'Black Barley Stout', - u'weight': 0.5, - u'grain_type': u'specialty'}, - {u'name': u'Roasted Barley', - u'weight': 0.5, - u'grain_type': u'specialty'}, + u"name": u"10 Pound Stout (Extract)", + u"start_volume": 4.0, + u"final_volume": 5.0, + u"grains": [ + {u"name": u"Amber Liquid Extract", u"weight": 7.0, u"grain_type": u"lme"}, + {u"name": u"Dark Dry Extract", u"weight": 3.0, u"grain_type": u"dme"}, + { + u"name": u"Caramel Crystal Malt 120l", + u"weight": 1.0, + u"grain_type": u"specialty", + }, + { + u"name": u"Black Barley Stout", + u"weight": 0.5, + u"grain_type": u"specialty", + }, + {u"name": u"Roasted Barley", u"weight": 0.5, u"grain_type": u"specialty"}, ], - u'hops': [ - {u'name': u'Columbus', - u'weight': 1.0, - u'boil_time': 60.0}, - {u'name': u'Columbus', - u'weight': 1.0, - u'boil_time': 5.0}, + u"hops": [ + {u"name": u"Columbus", u"weight": 1.0, u"boil_time": 60.0}, + {u"name": u"Columbus", u"weight": 1.0, u"boil_time": 5.0}, ], - u'yeast': { - u'name': u'Wyeast 1084', - }, - u'data': { - u'brew_house_yield': 0.80, - u'units': u'imperial', - }, + u"yeast": {u"name": u"Wyeast 1084"}, + u"data": {u"brew_house_yield": 0.80, u"units": u"imperial"}, } - data_dir = os.path.abspath(os.path.join(os.getcwd(), 'data/')) + data_dir = os.path.abspath(os.path.join(os.getcwd(), "data/")) loader = JSONDataLoader(data_dir) beer = parse_recipe(recipe, loader) print(beer.format()) diff --git a/examples/the_brew_shop/irish_red.py b/examples/the_brew_shop/irish_red.py index a6b85b6..d9f4f32 100644 --- a/examples/the_brew_shop/irish_red.py +++ b/examples/the_brew_shop/irish_red.py @@ -34,44 +34,37 @@ def main(): recipe = { - u'name': u"Lunar Eclipse Red (Extract)", - u'start_volume': 4.0, - u'final_volume': 5.0, - u'grains': [ - {u'name': u'Pale Liquid Extract', - u'weight': 7.0, - u'grain_type': u'lme'}, - {u'name': u'Munich Malt', - u'weight': 1.0, - u'grain_type': u'specialty'}, - {u'name': u'Caramel Crystal Malt 10l', - u'weight': 1.0, - u'grain_type': u'specialty'}, - {u'name': u'Caramel Crystal Malt 60l', - u'weight': 1.0, - u'grain_type': u'specialty'}, - {u'name': u'Caramel Crystal Malt 80l', - u'weight': 1.0, - u'grain_type': u'specialty'}, + u"name": u"Lunar Eclipse Red (Extract)", + u"start_volume": 4.0, + u"final_volume": 5.0, + u"grains": [ + {u"name": u"Pale Liquid Extract", u"weight": 7.0, u"grain_type": u"lme"}, + {u"name": u"Munich Malt", u"weight": 1.0, u"grain_type": u"specialty"}, + { + u"name": u"Caramel Crystal Malt 10l", + u"weight": 1.0, + u"grain_type": u"specialty", + }, + { + u"name": u"Caramel Crystal Malt 60l", + u"weight": 1.0, + u"grain_type": u"specialty", + }, + { + u"name": u"Caramel Crystal Malt 80l", + u"weight": 1.0, + u"grain_type": u"specialty", + }, ], - u'hops': [ - {u'name': u'Chinook', - u'weight': 1.0, - u'boil_time': 60.0}, - {u'name': u'Chinook', - u'weight': 1.0, - u'boil_time': 15.0}, + u"hops": [ + {u"name": u"Chinook", u"weight": 1.0, u"boil_time": 60.0}, + {u"name": u"Chinook", u"weight": 1.0, u"boil_time": 15.0}, ], - u'yeast': { - u'name': u'Wyeast 1084', - }, - u'data': { - u'brew_house_yield': 0.7, - u'units': u'imperial', - }, + u"yeast": {u"name": u"Wyeast 1084"}, + u"data": {u"brew_house_yield": 0.7, u"units": u"imperial"}, } - data_dir = os.path.abspath(os.path.join(os.getcwd(), 'data/')) + data_dir = os.path.abspath(os.path.join(os.getcwd(), "data/")) loader = JSONDataLoader(data_dir) beer = parse_recipe(recipe, loader) print(beer.format()) diff --git a/examples/the_brew_shop/scottish_amber.py b/examples/the_brew_shop/scottish_amber.py index c56f858..efffb26 100644 --- a/examples/the_brew_shop/scottish_amber.py +++ b/examples/the_brew_shop/scottish_amber.py @@ -35,44 +35,34 @@ def main(): recipe = { - u'name': u"Scottish Amber (Extract)", - u'start_volume': 5.0, - u'final_volume': 5.0, - u'grains': [ - {u'name': u'Pale Liquid Extract', - u'weight': 7.0, - u'grain_type': u'lme'}, - {u'name': u'Caramel Crystal Malt 80l', - u'weight': 1.0, - u'grain_type': u'specialty'}, - {u'name': u'Smoked Malt', - # Rausch means "Smoked" - u'weight': 1.0, - u'data': { - u'color': 6.0}, - u'grain_type': u'specialty'}, - {u'name': u'Victory Malt', - u'weight': 1.0, - u'grain_type': u'specialty'}, + u"name": u"Scottish Amber (Extract)", + u"start_volume": 5.0, + u"final_volume": 5.0, + u"grains": [ + {u"name": u"Pale Liquid Extract", u"weight": 7.0, u"grain_type": u"lme"}, + { + u"name": u"Caramel Crystal Malt 80l", + u"weight": 1.0, + u"grain_type": u"specialty", + }, + { + u"name": u"Smoked Malt", + # Rausch means "Smoked" + u"weight": 1.0, + u"data": {u"color": 6.0}, + u"grain_type": u"specialty", + }, + {u"name": u"Victory Malt", u"weight": 1.0, u"grain_type": u"specialty"}, ], - u'hops': [ - {u'name': u'Perle', - u'weight': 1.0, - u'boil_time': 60.0}, - {u'name': u'Perle', - u'weight': 1.0, - u'boil_time': 30.0}, + u"hops": [ + {u"name": u"Perle", u"weight": 1.0, u"boil_time": 60.0}, + {u"name": u"Perle", u"weight": 1.0, u"boil_time": 30.0}, ], - u'yeast': { - u'name': u'Wyeast 1728', - }, - u'data': { - u'brew_house_yield': 0.458, - u'units': u'imperial', - }, + u"yeast": {u"name": u"Wyeast 1728"}, + u"data": {u"brew_house_yield": 0.458, u"units": u"imperial"}, } - data_dir = os.path.abspath(os.path.join(os.getcwd(), 'data/')) + data_dir = os.path.abspath(os.path.join(os.getcwd(), "data/")) loader = JSONDataLoader(data_dir) beer = parse_recipe(recipe, loader) print(beer.format()) diff --git a/examples/the_brew_shop/yellow_moon_ipa.py b/examples/the_brew_shop/yellow_moon_ipa.py index 47562c0..d878a40 100644 --- a/examples/the_brew_shop/yellow_moon_ipa.py +++ b/examples/the_brew_shop/yellow_moon_ipa.py @@ -35,47 +35,34 @@ def main(): recipe = { - u'name': u"Yellow Moon IPA (Extract)", - u'start_volume': 4.0, - u'final_volume': 5.0, - u'grains': [ - {u'name': u'Pale Liquid Extract', - u'weight': 7.0, - u'grain_type': u'lme'}, - {u'name': u'Caramel Crystal Malt 20l', - u'weight': 1.0, - u'grain_type': u'specialty'}, - {u'name': u'Munich Malt', - u'weight': 0.5, - u'grain_type': u'specialty'}, - {u'name': u'Cara Pils Dextrine', - u'weight': 0.5, - u'grain_type': u'specialty'}, + u"name": u"Yellow Moon IPA (Extract)", + u"start_volume": 4.0, + u"final_volume": 5.0, + u"grains": [ + {u"name": u"Pale Liquid Extract", u"weight": 7.0, u"grain_type": u"lme"}, + { + u"name": u"Caramel Crystal Malt 20l", + u"weight": 1.0, + u"grain_type": u"specialty", + }, + {u"name": u"Munich Malt", u"weight": 0.5, u"grain_type": u"specialty"}, + { + u"name": u"Cara Pils Dextrine", + u"weight": 0.5, + u"grain_type": u"specialty", + }, ], - u'hops': [ - {u'name': u'Centennial', - u'weight': 1.0, - u'boil_time': 60.0}, - {u'name': u'Centennial', - u'weight': 1.0, - u'boil_time': 30.0}, - {u'name': u'Cascade US', - u'weight': 1.0, - u'boil_time': 10.0}, - {u'name': u'Cascade US', - u'weight': 1.0, - u'boil_time': 0.0}, + u"hops": [ + {u"name": u"Centennial", u"weight": 1.0, u"boil_time": 60.0}, + {u"name": u"Centennial", u"weight": 1.0, u"boil_time": 30.0}, + {u"name": u"Cascade US", u"weight": 1.0, u"boil_time": 10.0}, + {u"name": u"Cascade US", u"weight": 1.0, u"boil_time": 0.0}, ], - u'yeast': { - u'name': u'Wyeast 1056', - }, - u'data': { - u'brew_house_yield': 0.425, - u'units': u'imperial', - }, + u"yeast": {u"name": u"Wyeast 1056"}, + u"data": {u"brew_house_yield": 0.425, u"units": u"imperial"}, } - data_dir = os.path.abspath(os.path.join(os.getcwd(), 'data/')) + data_dir = os.path.abspath(os.path.join(os.getcwd(), "data/")) loader = JSONDataLoader(data_dir) beer = parse_recipe(recipe, loader) print(beer.format()) diff --git a/requirements-dev.txt b/requirements-dev.txt index d75eb80..0ec012a 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,6 +1,9 @@ # Coverage coverage==4.1 +# Formatting +black==19.3b0 + # Lint flake8==3.3.0 mccabe==0.6.1 diff --git a/setup.py b/setup.py index 4959682..454a763 100644 --- a/setup.py +++ b/setup.py @@ -2,58 +2,57 @@ from setuptools import setup -VERSION = '1.0.0' +VERSION = "1.0.0" setup( - name='brewday', + name="brewday", version=VERSION, - author='Chris Gilmer', - author_email='chris.gilmer@gmail.com', - maintainer='Chris Gilmer', - maintainer_email='chris.gilmer@gmail.com', + author="Chris Gilmer", + author_email="chris.gilmer@gmail.com", + maintainer="Chris Gilmer", + maintainer_email="chris.gilmer@gmail.com", license="MIT", - description='Brew Day Tools', - url='https://github.com/chrisgilmerproj/brewday', - download_url='https://github.com/chrisgilmerproj/brewday/tarball/{}'.format(VERSION), # noqa - packages=find_packages(exclude=["*.tests", - "*.tests.*", - "tests.*", - "tests"]), + description="Brew Day Tools", + url="https://github.com/chrisgilmerproj/brewday", + download_url="https://github.com/chrisgilmerproj/brewday/tarball/{}".format( + VERSION + ), # noqa + packages=find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"]), entry_points={ - 'console_scripts': [ - 'abv = brew.cli.abv:main', - 'gv = brew.cli.gravity_volume:main', - 'sugar = brew.cli.sugar:main', - 'temp = brew.cli.temp:main', - 'yeast = brew.cli.yeast:main', - ], + "console_scripts": [ + "abv = brew.cli.abv:main", + "gv = brew.cli.gravity_volume:main", + "sugar = brew.cli.sugar:main", + "temp = brew.cli.temp:main", + "yeast = brew.cli.yeast:main", + ] }, include_package_data=True, zip_safe=True, tests_require=[ - 'mock==2.0.0', - 'nose==1.3.1', - 'pluggy==0.3.1', - 'py==1.4.31', - 'tox==2.3.1', + "mock==2.0.0", + "nose==1.3.1", + "pluggy==0.3.1", + "py==1.4.31", + "tox==2.3.1", ], - keywords='brew brewing beer grain hops yeast alcohol', + keywords="brew brewing beer grain hops yeast alcohol", classifiers=[ - 'Development Status :: 3 - Alpha', - 'Intended Audience :: Developers', - 'Intended Audience :: Education', - 'Intended Audience :: Science/Research', - 'Intended Audience :: Other Audience', - 'License :: OSI Approved :: MIT License', - 'Operating System :: OS Independent', - 'Programming Language :: Python', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', - 'Topic :: Software Development :: Libraries :: Python Modules', + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "Intended Audience :: Education", + "Intended Audience :: Science/Research", + "Intended Audience :: Other Audience", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 2", + "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.3", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", + "Topic :: Software Development :: Libraries :: Python Modules", ], ) diff --git a/tests/fixtures.py b/tests/fixtures.py index d3a7552..7b4af2d 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -12,42 +12,30 @@ # Define Grains ppg_pale = 37.0 -pale = Grain(u'pale 2-row', - color=2.0, - ppg=ppg_pale) +pale = Grain(u"pale 2-row", color=2.0, ppg=ppg_pale) pale_lme = pale.convert_to_lme() pale_dme = pale.convert_to_dme() ppg_crystal = 35.0 -crystal = Grain(u'crystal C20', - color=20.0, - ppg=ppg_crystal) +crystal = Grain(u"crystal C20", color=20.0, ppg=ppg_crystal) grain_list = [pale, crystal] -pale_add = GrainAddition(pale, - weight=13.96) +pale_add = GrainAddition(pale, weight=13.96) pale_add_lme = pale_add.convert_to_lme(brew_house_yield=BHY) pale_add_dme = pale_add.convert_to_dme(brew_house_yield=BHY) -crystal_add = GrainAddition(crystal, - weight=0.78) +crystal_add = GrainAddition(crystal, weight=0.78) grain_additions = [pale_add, crystal_add] grain_additions_lme = [pale_add_lme, crystal_add] grain_additions_dme = [pale_add_dme, crystal_add] # Define Hops -centennial = Hop(name=u'centennial', - percent_alpha_acids=0.14) -cascade = Hop(name=u'cascade', - percent_alpha_acids=0.07) +centennial = Hop(name=u"centennial", percent_alpha_acids=0.14) +cascade = Hop(name=u"cascade", percent_alpha_acids=0.07) hop_list = [centennial, cascade] -centennial_add = HopAddition(centennial, - boil_time=60.0, - weight=0.57) -cascade_add = HopAddition(cascade, - boil_time=5.0, - weight=0.76) +centennial_add = HopAddition(centennial, boil_time=60.0, weight=0.57) +cascade_add = HopAddition(cascade, boil_time=5.0, weight=0.76) hop_additions = [centennial_add, cascade_add] # Define Yeast @@ -55,7 +43,7 @@ # Define Recipes recipe = Recipe( - name=u'pale ale', + name=u"pale ale", grain_additions=grain_additions, hop_additions=hop_additions, yeast=yeast, @@ -65,7 +53,7 @@ ) recipe_lme = Recipe( - name=u'pale ale lme', + name=u"pale ale lme", grain_additions=grain_additions_lme, hop_additions=hop_additions, yeast=yeast, @@ -75,7 +63,7 @@ ) recipe_dme = Recipe( - name=u'pale ale dme', + name=u"pale ale dme", grain_additions=grain_additions_dme, hop_additions=hop_additions, yeast=yeast, @@ -85,31 +73,36 @@ ) # Define Recipe Builder -builder = RecipeBuilder(name=u'pale ale', - grain_list=grain_list, - hop_list=hop_list, - target_ibu=33.0, - target_og=1.0761348, - brew_house_yield=0.70, - start_volume=7.0, - final_volume=5.0, - ) +builder = RecipeBuilder( + name=u"pale ale", + grain_list=grain_list, + hop_list=hop_list, + target_ibu=33.0, + target_og=1.0761348, + brew_house_yield=0.70, + start_volume=7.0, + final_volume=5.0, +) # Define a Style -american_pale_ale_style = Style(u'American Pale Ale', - category=u'18', - subcategory=u'B', - og=[1.045, 1.06], - fg=[1.010, 1.015], - abv=[0.045, 0.062], - ibu=[30, 50], - color=[5, 10]) +american_pale_ale_style = Style( + u"American Pale Ale", + category=u"18", + subcategory=u"B", + og=[1.045, 1.06], + fg=[1.010, 1.015], + abv=[0.045, 0.062], + ibu=[30, 50], + color=[5, 10], +) -english_pale_ale_style = Style(u'Ordinary Bitter', - category=u'11', - subcategory=u'A', - og=[1.030, 1.039], - fg=[1.007, 1.011], - abv=[0.032, 0.038], - ibu=[25, 35], - color=[8, 14]) +english_pale_ale_style = Style( + u"Ordinary Bitter", + category=u"11", + subcategory=u"A", + og=[1.030, 1.039], + fg=[1.007, 1.011], + abv=[0.032, 0.038], + ibu=[25, 35], + color=[8, 14], +) diff --git a/tests/test_cli_abv.py b/tests/test_cli_abv.py index 9bdbd87..c07b3b1 100644 --- a/tests/test_cli_abv.py +++ b/tests/test_cli_abv.py @@ -10,7 +10,6 @@ class TestCliAbv(unittest.TestCase): - def setUp(self): self.og = 1.057 self.fg = 1.013 @@ -33,7 +32,7 @@ def test_get_abv_og_fg_reversed_raises(self): def test_get_abv_bad_units_raises(self): with self.assertRaises(Exception): - get_abv(self.og, self.og, units=u'bad') + get_abv(self.og, self.og, units=u"bad") def test_get_abv_units_imperial(self): abv = get_abv(self.og, self.fg, units=IMPERIAL_UNITS) @@ -57,19 +56,20 @@ def test_get_abv_alternative_refractometer(self): def test_get_abv_verbose(self): out = get_abv(self.og, self.fg, verbose=True) - expected = textwrap.dedent(u"""\ + expected = textwrap.dedent( + u"""\ OG : 1.057 OG Adj : 1.057 OG Temp: 59.00 F FG : 1.013 FG Adj : 1.013 FG Temp: 59.00 F - ABV : 5.78%""") + ABV : 5.78%""" + ) self.assertEquals(out, expected) class TestCliArgparserAbv(unittest.TestCase): - def setUp(self): self.parser = get_parser() @@ -79,107 +79,113 @@ def test_get_parser_required_og_and_fg(self): def test_get_parser_required_og(self): with self.assertRaises(SystemExit): - self.parser.parse_args([u'-f', u'1.010']) + self.parser.parse_args([u"-f", u"1.010"]) def test_get_parser_required_fg(self): with self.assertRaises(SystemExit): - self.parser.parse_args([u'-o', u'1.060']) + self.parser.parse_args([u"-o", u"1.060"]) def test_get_parser_og_and_fg(self): - args = [u'-o', u'1.060', u'-f', u'1.010'] + args = [u"-o", u"1.060", u"-f", u"1.010"] out = self.parser.parse_args(args) expected = { - u'alternative': False, - u'fg': 1.01, - u'fg_temp': 59.0, - u'og': 1.06, - u'og_temp': 59.0, - u'refractometer': False, - u'units': u'imperial', - u'verbose': False, + u"alternative": False, + u"fg": 1.01, + u"fg_temp": 59.0, + u"og": 1.06, + u"og_temp": 59.0, + u"refractometer": False, + u"units": u"imperial", + u"verbose": False, } self.assertEquals(out.__dict__, expected) def test_get_parser_update_temp(self): - args = [u'-o', u'1.060', u'-f', u'1.010', - u'--og-temp', u'61.0', - u'--fg-temp', u'61.0'] + args = [ + u"-o", + u"1.060", + u"-f", + u"1.010", + u"--og-temp", + u"61.0", + u"--fg-temp", + u"61.0", + ] out = self.parser.parse_args(args) expected = { - u'alternative': False, - u'fg': 1.01, - u'fg_temp': 61.0, - u'og': 1.06, - u'og_temp': 61.0, - u'refractometer': False, - u'units': u'imperial', - u'verbose': False, + u"alternative": False, + u"fg": 1.01, + u"fg_temp": 61.0, + u"og": 1.06, + u"og_temp": 61.0, + u"refractometer": False, + u"units": u"imperial", + u"verbose": False, } self.assertEquals(out.__dict__, expected) def test_get_parser_alternative(self): - args = [u'-o', u'1.060', u'-f', u'1.010', u'--alternative'] + args = [u"-o", u"1.060", u"-f", u"1.010", u"--alternative"] out = self.parser.parse_args(args) expected = { - u'alternative': True, - u'fg': 1.01, - u'fg_temp': 59.0, - u'og': 1.06, - u'og_temp': 59.0, - u'refractometer': False, - u'units': u'imperial', - u'verbose': False, + u"alternative": True, + u"fg": 1.01, + u"fg_temp": 59.0, + u"og": 1.06, + u"og_temp": 59.0, + u"refractometer": False, + u"units": u"imperial", + u"verbose": False, } self.assertEquals(out.__dict__, expected) def test_get_parser_refractometer(self): - args = [u'-o', u'1.060', u'-f', u'1.010', u'--refractometer'] + args = [u"-o", u"1.060", u"-f", u"1.010", u"--refractometer"] out = self.parser.parse_args(args) expected = { - u'alternative': False, - u'fg': 1.01, - u'fg_temp': 59.0, - u'og': 1.06, - u'og_temp': 59.0, - u'refractometer': True, - u'units': u'imperial', - u'verbose': False, + u"alternative": False, + u"fg": 1.01, + u"fg_temp": 59.0, + u"og": 1.06, + u"og_temp": 59.0, + u"refractometer": True, + u"units": u"imperial", + u"verbose": False, } self.assertEquals(out.__dict__, expected) def test_get_parser_units(self): - args = [u'-o', u'1.060', u'-f', u'1.010', u'--units', u'si'] + args = [u"-o", u"1.060", u"-f", u"1.010", u"--units", u"si"] out = self.parser.parse_args(args) expected = { - u'alternative': False, - u'fg': 1.01, - u'fg_temp': 59.0, - u'og': 1.06, - u'og_temp': 59.0, - u'refractometer': False, - u'units': u'si', - u'verbose': False, + u"alternative": False, + u"fg": 1.01, + u"fg_temp": 59.0, + u"og": 1.06, + u"og_temp": 59.0, + u"refractometer": False, + u"units": u"si", + u"verbose": False, } self.assertEquals(out.__dict__, expected) def test_get_parser_verbose(self): - args = [u'-o', u'1.060', u'-f', u'1.010', u'-v'] + args = [u"-o", u"1.060", u"-f", u"1.010", u"-v"] out = self.parser.parse_args(args) expected = { - u'alternative': False, - u'fg': 1.01, - u'fg_temp': 59.0, - u'og': 1.06, - u'og_temp': 59.0, - u'refractometer': False, - u'units': u'imperial', - u'verbose': True, + u"alternative": False, + u"fg": 1.01, + u"fg_temp": 59.0, + u"og": 1.06, + u"og_temp": 59.0, + u"refractometer": False, + u"units": u"imperial", + u"verbose": True, } self.assertEquals(out.__dict__, expected) class TestCliMainAbv(unittest.TestCase): - def setUp(self): class Parser(object): def __init__(self, output): @@ -188,6 +194,7 @@ def __init__(self, output): def parse_args(self): class Args(object): pass + args = Args() if self.output: for k, v in self.output.items(): @@ -196,6 +203,7 @@ class Args(object): def g_parser(output=None): return Parser(output) + self.parser_fn = g_parser self.main = main @@ -204,25 +212,31 @@ def test_main_no_kwargs(self): self.main(parser_fn=self.parser_fn) def test_main_with_args(self): - args = {u'output': {u'og': 1.060, - u'fg': 1.010, - u'og_temp': 59.0, - u'fg_temp': 59.0, - u'alternative': False, - u'refractometer': False, - u'units': u'imperial', - u'verbose': False}} - self.main(parser_fn=self.parser_fn, - parser_kwargs=args) + args = { + u"output": { + u"og": 1.060, + u"fg": 1.010, + u"og_temp": 59.0, + u"fg_temp": 59.0, + u"alternative": False, + u"refractometer": False, + u"units": u"imperial", + u"verbose": False, + } + } + self.main(parser_fn=self.parser_fn, parser_kwargs=args) def test_main_verbose(self): - args = {u'output': {u'og': 1.060, - u'fg': 1.010, - u'og_temp': 59.0, - u'fg_temp': 59.0, - u'alternative': False, - u'refractometer': False, - u'units': u'imperial', - u'verbose': True}} - self.main(parser_fn=self.parser_fn, - parser_kwargs=args) + args = { + u"output": { + u"og": 1.060, + u"fg": 1.010, + u"og_temp": 59.0, + u"fg_temp": 59.0, + u"alternative": False, + u"refractometer": False, + u"units": u"imperial", + u"verbose": True, + } + } + self.main(parser_fn=self.parser_fn, parser_kwargs=args) diff --git a/tests/test_cli_gravity_volume.py b/tests/test_cli_gravity_volume.py index 24946fd..4e3bb7e 100644 --- a/tests/test_cli_gravity_volume.py +++ b/tests/test_cli_gravity_volume.py @@ -7,7 +7,6 @@ class TestCliTemp(unittest.TestCase): - def setUp(self): self.ov = 3 self.fv = 10 @@ -19,23 +18,17 @@ def test_get_gravity(self): class TestCliArgparserTemp(unittest.TestCase): - def setUp(self): self.parser = get_parser() def test_get_parser(self): - args = [u'-o', u'3.0', u'-f', u'10.0', u'-g', u'1.050'] + args = [u"-o", u"3.0", u"-f", u"10.0", u"-g", u"1.050"] out = self.parser.parse_args(args) - expected = { - u'original_volume': 3.0, - u'final_volume': 10.0, - u'gravity': 1.050, - } + expected = {u"original_volume": 3.0, u"final_volume": 10.0, u"gravity": 1.050} self.assertEquals(out.__dict__, expected) class TestCliMainTemp(unittest.TestCase): - def setUp(self): class Parser(object): def __init__(self, output): @@ -44,6 +37,7 @@ def __init__(self, output): def parse_args(self): class Args(object): pass + args = Args() if self.output: for k, v in self.output.items(): @@ -52,24 +46,31 @@ class Args(object): def g_parser(output=None): return Parser(output) + self.parser_fn = g_parser self.main = main def test_main_no_args(self): - args = {u'output': {u'original_volume': None, - u'final_volume': None, - u'gravity': None}} + args = { + u"output": { + u"original_volume": None, + u"final_volume": None, + u"gravity": None, + } + } with self.assertRaises(SystemExit): - self.main(parser_fn=self.parser_fn, - parser_kwargs=args) + self.main(parser_fn=self.parser_fn, parser_kwargs=args) def test_main_no_kwargs(self): with self.assertRaises(AttributeError): self.main(parser_fn=self.parser_fn) def test_main_all_args(self): - args = {u'output': {u'original_volume': 3.0, - u'final_volume': 10.0, - u'gravity': 1.050}} - self.main(parser_fn=self.parser_fn, - parser_kwargs=args) + args = { + u"output": { + u"original_volume": 3.0, + u"final_volume": 10.0, + u"gravity": 1.050, + } + } + self.main(parser_fn=self.parser_fn, parser_kwargs=args) diff --git a/tests/test_cli_sugar.py b/tests/test_cli_sugar.py index c5dda33..2e9705c 100644 --- a/tests/test_cli_sugar.py +++ b/tests/test_cli_sugar.py @@ -7,116 +7,93 @@ class TestCliSugar(unittest.TestCase): - def setUp(self): self.brix = 22.0 self.plato = 22.0 self.sg = 1.092 def test_get_sugar_conversion_brix_to_brix(self): - out = get_sugar_conversion(self.brix, None, None, u'b') + out = get_sugar_conversion(self.brix, None, None, u"b") self.assertEquals(round(out, 1), self.brix) def test_get_sugar_conversion_brix_to_plato(self): - out = get_sugar_conversion(self.brix, None, None, u'p') + out = get_sugar_conversion(self.brix, None, None, u"p") self.assertEquals(round(out, 1), self.plato) def test_get_sugar_conversion_brix_to_sg(self): - out = get_sugar_conversion(self.brix, None, None, u's') + out = get_sugar_conversion(self.brix, None, None, u"s") self.assertEquals(round(out, 3), self.sg) def test_get_sugar_conversion_plato_to_brix(self): - out = get_sugar_conversion(None, self.plato, None, u'b') + out = get_sugar_conversion(None, self.plato, None, u"b") self.assertEquals(round(out, 1), self.brix) def test_get_sugar_conversion_plato_to_plato(self): - out = get_sugar_conversion(None, self.plato, None, u'p') + out = get_sugar_conversion(None, self.plato, None, u"p") self.assertEquals(round(out, 1), self.plato) def test_get_sugar_conversion_plato_to_sg(self): - out = get_sugar_conversion(None, self.plato, None, u's') + out = get_sugar_conversion(None, self.plato, None, u"s") self.assertEquals(round(out, 3), self.sg) def test_get_sugar_conversion_sg_to_brix(self): - out = get_sugar_conversion(None, None, self.sg, u'b') + out = get_sugar_conversion(None, None, self.sg, u"b") self.assertEquals(round(out, 1), self.brix) def test_get_sugar_conversion_sg_to_plato(self): - out = get_sugar_conversion(None, None, self.sg, u'p') + out = get_sugar_conversion(None, None, self.sg, u"p") self.assertEquals(round(out, 1), self.plato) def test_get_sugar_conversion_sg_to_sg(self): - out = get_sugar_conversion(None, None, self.sg, u's') + out = get_sugar_conversion(None, None, self.sg, u"s") self.assertEquals(round(out, 3), self.sg) def test_get_sugar_conversion_all_brix(self): out = get_sugar_conversion(self.brix, None, None, None) - expected = u'SG\tPlato\tBrix\n1.092\t22.0\t22.0' + expected = u"SG\tPlato\tBrix\n1.092\t22.0\t22.0" self.assertEquals(out, expected) def test_get_sugar_conversion_all_plato(self): out = get_sugar_conversion(None, self.plato, None, None) - expected = u'SG\tPlato\tBrix\n1.092\t22.0\t22.0' + expected = u"SG\tPlato\tBrix\n1.092\t22.0\t22.0" self.assertEquals(out, expected) def test_get_sugar_conversion_all_sg(self): out = get_sugar_conversion(None, None, self.sg, None) - expected = u'SG\tPlato\tBrix\n1.092\t22.0\t22.0' + expected = u"SG\tPlato\tBrix\n1.092\t22.0\t22.0" self.assertEquals(out, expected) class TestCliArgparserSugar(unittest.TestCase): - def setUp(self): self.parser = get_parser() def test_get_parser_brix_in_none_out(self): - args = [u'-b', u'22.0'] + args = [u"-b", u"22.0"] out = self.parser.parse_args(args) - expected = { - u'brix': 22.0, - u'plato': None, - u'sg': None, - u'out': None, - } + expected = {u"brix": 22.0, u"plato": None, u"sg": None, u"out": None} self.assertEquals(out.__dict__, expected) def test_get_parser_plato_in_none_out(self): - args = [u'-p', u'22.0'] + args = [u"-p", u"22.0"] out = self.parser.parse_args(args) - expected = { - u'brix': None, - u'plato': 22.0, - u'sg': None, - u'out': None, - } + expected = {u"brix": None, u"plato": 22.0, u"sg": None, u"out": None} self.assertEquals(out.__dict__, expected) def test_get_parser_sg_in_none_out(self): - args = [u'-s', u'1.060'] + args = [u"-s", u"1.060"] out = self.parser.parse_args(args) - expected = { - u'brix': None, - u'plato': None, - u'sg': 1.060, - u'out': None, - } + expected = {u"brix": None, u"plato": None, u"sg": 1.060, u"out": None} self.assertEquals(out.__dict__, expected) def test_get_parser_sg_in_brix_out(self): - args = [u'-s', u'1.060', u'-o', u'b'] + args = [u"-s", u"1.060", u"-o", u"b"] out = self.parser.parse_args(args) - expected = { - u'brix': None, - u'plato': None, - u'sg': 1.060, - u'out': u'b', - } + expected = {u"brix": None, u"plato": None, u"sg": 1.060, u"out": u"b"} self.assertEquals(out.__dict__, expected) class TestCliMainSugar(unittest.TestCase): - def setUp(self): class Parser(object): def __init__(self, output): @@ -125,6 +102,7 @@ def __init__(self, output): def parse_args(self): class Args(object): pass + args = Args() if self.output: for k, v in self.output.items(): @@ -133,35 +111,24 @@ class Args(object): def g_parser(output=None): return Parser(output) + self.parser_fn = g_parser self.main = main def test_main_no_args(self): - args = {u'output': {u'brix': None, - u'plato': None, - u'sg': None, - u'out': None}} + args = {u"output": {u"brix": None, u"plato": None, u"sg": None, u"out": None}} with self.assertRaises(SystemExit): - self.main(parser_fn=self.parser_fn, - parser_kwargs=args) + self.main(parser_fn=self.parser_fn, parser_kwargs=args) def test_main_no_kwargs(self): with self.assertRaises(AttributeError): self.main(parser_fn=self.parser_fn) def test_main_two_args(self): - args = {u'output': {u'brix': 22.0, - u'plato': 22.0, - u'sg': None, - u'out': None}} + args = {u"output": {u"brix": 22.0, u"plato": 22.0, u"sg": None, u"out": None}} with self.assertRaises(SystemExit): - self.main(parser_fn=self.parser_fn, - parser_kwargs=args) + self.main(parser_fn=self.parser_fn, parser_kwargs=args) def test_main_one_arg(self): - args = {u'output': {u'brix': 22.0, - u'plato': None, - u'sg': None, - u'out': None}} - self.main(parser_fn=self.parser_fn, - parser_kwargs=args) + args = {u"output": {u"brix": 22.0, u"plato": None, u"sg": None, u"out": None}} + self.main(parser_fn=self.parser_fn, parser_kwargs=args) diff --git a/tests/test_cli_temp.py b/tests/test_cli_temp.py index 324b101..26bd32b 100644 --- a/tests/test_cli_temp.py +++ b/tests/test_cli_temp.py @@ -7,7 +7,6 @@ class TestCliTemp(unittest.TestCase): - def setUp(self): self.c = 15.6 self.f = 60.1 @@ -22,31 +21,23 @@ def test_get_sugar_conversion_celsius(self): class TestCliArgparserTemp(unittest.TestCase): - def setUp(self): self.parser = get_parser() def test_get_parser_celsius(self): - args = [u'-c', u'25.0'] + args = [u"-c", u"25.0"] out = self.parser.parse_args(args) - expected = { - u'celsius': 25.0, - u'fahrenheit': None, - } + expected = {u"celsius": 25.0, u"fahrenheit": None} self.assertEquals(out.__dict__, expected) def test_get_parser_fahrenheit(self): - args = [u'-f', u'62.0'] + args = [u"-f", u"62.0"] out = self.parser.parse_args(args) - expected = { - u'celsius': None, - u'fahrenheit': 62.0, - } + expected = {u"celsius": None, u"fahrenheit": 62.0} self.assertEquals(out.__dict__, expected) class TestCliMainTemp(unittest.TestCase): - def setUp(self): class Parser(object): def __init__(self, output): @@ -55,6 +46,7 @@ def __init__(self, output): def parse_args(self): class Args(object): pass + args = Args() if self.output: for k, v in self.output.items(): @@ -63,35 +55,28 @@ class Args(object): def g_parser(output=None): return Parser(output) + self.parser_fn = g_parser self.main = main def test_main_no_args(self): - args = {u'output': {u'celsius': None, - u'fahrenheit': None}} + args = {u"output": {u"celsius": None, u"fahrenheit": None}} with self.assertRaises(SystemExit): - self.main(parser_fn=self.parser_fn, - parser_kwargs=args) + self.main(parser_fn=self.parser_fn, parser_kwargs=args) def test_main_both_args(self): - args = {u'output': {u'celsius': 25.0, - u'fahrenheit': 62.0}} + args = {u"output": {u"celsius": 25.0, u"fahrenheit": 62.0}} with self.assertRaises(SystemExit): - self.main(parser_fn=self.parser_fn, - parser_kwargs=args) + self.main(parser_fn=self.parser_fn, parser_kwargs=args) def test_main_no_kwargs(self): with self.assertRaises(AttributeError): self.main(parser_fn=self.parser_fn) def test_main_celsius(self): - args = {u'output': {u'celsius': 25.0, - u'fahrenheit': None}} - self.main(parser_fn=self.parser_fn, - parser_kwargs=args) + args = {u"output": {u"celsius": 25.0, u"fahrenheit": None}} + self.main(parser_fn=self.parser_fn, parser_kwargs=args) def test_main_fahrenheit(self): - args = {u'output': {u'celsius': None, - u'fahrenheit': 62.0}} - self.main(parser_fn=self.parser_fn, - parser_kwargs=args) + args = {u"output": {u"celsius": None, u"fahrenheit": 62.0}} + self.main(parser_fn=self.parser_fn, parser_kwargs=args) diff --git a/tests/test_cli_yeast.py b/tests/test_cli_yeast.py index 967cae1..7cf0036 100644 --- a/tests/test_cli_yeast.py +++ b/tests/test_cli_yeast.py @@ -5,22 +5,22 @@ class TestCliArgparserTemp(unittest.TestCase): - def setUp(self): self.parser = get_parser() self.default_args = { - 'cells': 100, - 'days': 0, - 'fv': 5.0, - 'method': 'stir plate', - 'model': 'white', - 'num': 1, - 'og': 1.05, - 'sg': 1.036, - 'sv': 0.5283443537159779, - 'target_pitch_rate': 1.42, - 'type': 'liquid', - 'units': 'imperial'} + "cells": 100, + "days": 0, + "fv": 5.0, + "method": "stir plate", + "model": "white", + "num": 1, + "og": 1.05, + "sg": 1.036, + "sv": 0.5283443537159779, + "target_pitch_rate": 1.42, + "type": "liquid", + "units": "imperial", + } def test_get_parser_(self): args = [] diff --git a/tests/test_grains.py b/tests/test_grains.py index 05a142d..9261c5d 100644 --- a/tests/test_grains.py +++ b/tests/test_grains.py @@ -24,23 +24,20 @@ class TestGrains(unittest.TestCase): - def setUp(self): self.grain = pale def test_str(self): out = str(self.grain) - self.assertEquals(out, u'pale 2-row') + self.assertEquals(out, u"pale 2-row") def test_unicode(self): - grain = Grain(u'château pilsen 2rs', - color=3.0, - ppg=ppg_pale) + grain = Grain(u"château pilsen 2rs", color=3.0, ppg=ppg_pale) out = str(grain) if sys.version_info[0] >= 3: - self.assertEquals(out, u'château pilsen 2rs') + self.assertEquals(out, u"château pilsen 2rs") else: - self.assertEquals(out, u'château pilsen 2rs'.encode('utf8')) + self.assertEquals(out, u"château pilsen 2rs".encode("utf8")) def test_repr(self): out = repr(self.grain) @@ -48,12 +45,14 @@ def test_repr(self): def test_format(self): out = self.grain.format() - msg = textwrap.dedent(u"""\ + msg = textwrap.dedent( + u"""\ pale 2-row Grain ----------------------------------- Color: 2.0 degL PPG: 37.00 - Hot Water Extract: 308.78""") + Hot Water Extract: 308.78""" + ) self.assertEquals(out, msg) def test_get_working_yield(self): @@ -61,69 +60,45 @@ def test_get_working_yield(self): self.assertEquals(round(wy, 2), 0.56) def test_grain_hwe(self): - pale = Grain(u'pale 2-row', - color=2.0, - hwe=308.0) + pale = Grain(u"pale 2-row", color=2.0, hwe=308.0) self.assertEquals(pale.hwe, 308.0) self.assertEquals(round(pale.ppg, 2), 36.91) def test_grain_no_color_raises(self): with self.assertRaises(GrainException) as ctx: - Grain(u'pale 2-row', - ppg=ppg_pale) - self.assertEquals(str(ctx.exception), - u'pale 2-row: Must provide color value') + Grain(u"pale 2-row", ppg=ppg_pale) + self.assertEquals(str(ctx.exception), u"pale 2-row: Must provide color value") def test_grain_no_ppg_or_hwe_raises(self): with self.assertRaises(GrainException) as ctx: - Grain(u'pale 2-row', - color=2.0) - self.assertEquals(str(ctx.exception), - u'pale 2-row: Must provide ppg or hwe') + Grain(u"pale 2-row", color=2.0) + self.assertEquals(str(ctx.exception), u"pale 2-row: Must provide ppg or hwe") def test_grain_ppg_hwe_raises(self): with self.assertRaises(GrainException) as ctx: - Grain(u'pale 2-row', - color=2.0, - ppg=ppg_pale, - hwe=308.0) - self.assertEquals(str(ctx.exception), - u'pale 2-row: Cannot provide both ppg and hwe') + Grain(u"pale 2-row", color=2.0, ppg=ppg_pale, hwe=308.0) + self.assertEquals( + str(ctx.exception), u"pale 2-row: Cannot provide both ppg and hwe" + ) def test_eq(self): - grain1 = Grain(u'pale 2-row', - color=2.0, - ppg=ppg_pale) - grain2 = Grain(u'pale 2-row', - color=2.0, - ppg=ppg_pale) + grain1 = Grain(u"pale 2-row", color=2.0, ppg=ppg_pale) + grain2 = Grain(u"pale 2-row", color=2.0, ppg=ppg_pale) self.assertEquals(grain1, grain2) def test_ne_name(self): - grain1 = Grain(u'pale 2-row', - color=2.0, - ppg=ppg_pale) - grain2 = Grain(u'pale row', - color=2.0, - ppg=ppg_pale) + grain1 = Grain(u"pale 2-row", color=2.0, ppg=ppg_pale) + grain2 = Grain(u"pale row", color=2.0, ppg=ppg_pale) self.assertTrue(grain1 != grain2) def test_ne_color(self): - grain1 = Grain(u'pale 2-row', - color=2.0, - ppg=ppg_pale) - grain2 = Grain(u'pale 2-row', - color=4.0, - ppg=ppg_pale) + grain1 = Grain(u"pale 2-row", color=2.0, ppg=ppg_pale) + grain2 = Grain(u"pale 2-row", color=4.0, ppg=ppg_pale) self.assertTrue(grain1 != grain2) def test_ne_ppg(self): - grain1 = Grain(u'pale 2-row', - color=2.0, - ppg=ppg_pale) - grain2 = Grain(u'pale 2-row', - color=2.0, - ppg=35.0) + grain1 = Grain(u"pale 2-row", color=2.0, ppg=ppg_pale) + grain2 = Grain(u"pale 2-row", color=2.0, ppg=35.0) self.assertTrue(grain1 != grain2) def test_ne_grain_add_class(self): @@ -131,16 +106,19 @@ def test_ne_grain_add_class(self): def test_to_dict(self): out = self.grain.to_dict() - expected = {u'name': u'pale 2-row', - u'color': 2.0, - u'ppg': ppg_pale, - u'hwe': 308.78, - } + expected = { + u"name": u"pale 2-row", + u"color": 2.0, + u"ppg": ppg_pale, + u"hwe": 308.78, + } self.assertEquals(out, expected) def test_to_json(self): out = self.grain.to_json() - expected = u'{"color": 2.0, "hwe": 308.78, "name": "pale 2-row", "ppg": 37.0}' # noqa + expected = ( + u'{"color": 2.0, "hwe": 308.78, "name": "pale 2-row", "ppg": 37.0}' + ) # noqa self.assertEquals(out, expected) def test_convert_to_cereal(self): @@ -151,8 +129,7 @@ def test_convert_to_cereal(self): def test_convert_to_cereal_raises(self): with self.assertRaises(GrainException) as ctx: pale_lme.convert_to_cereal() - self.assertEquals(str(ctx.exception), - u'Must provide PPG to convert to cereal') + self.assertEquals(str(ctx.exception), u"Must provide PPG to convert to cereal") def test_convert_to_lme(self): ga_lme = self.grain.convert_to_lme(ppg=PPG_LME) @@ -164,33 +141,33 @@ def test_convert_to_dme(self): class TestGrainAdditions(unittest.TestCase): - def setUp(self): self.grain_add = pale_add def test_str(self): out = str(self.grain_add) - self.assertEquals(out, u'pale 2-row, weight 13.96 lbs') + self.assertEquals(out, u"pale 2-row, weight 13.96 lbs") def test_unicode(self): - grain = Grain(u'château pilsen 2rs', - color=3.0, - ppg=ppg_pale) - grain_add = GrainAddition(grain, - weight=0.78) + grain = Grain(u"château pilsen 2rs", color=3.0, ppg=ppg_pale) + grain_add = GrainAddition(grain, weight=0.78) out = str(grain_add) if sys.version_info[0] >= 3: - self.assertEquals(out, u'château pilsen 2rs, weight 0.78 lbs') # noqa + self.assertEquals(out, u"château pilsen 2rs, weight 0.78 lbs") # noqa else: - self.assertEquals(out, u'château pilsen 2rs, weight 0.78 lbs'.encode('utf8')) # noqa + self.assertEquals( + out, u"château pilsen 2rs, weight 0.78 lbs".encode("utf8") + ) # noqa def test_repr(self): out = repr(self.grain_add) - self.assertEquals(out, u"GrainAddition(Grain('pale 2-row', color=2.0, hwe=308.78), weight=13.96, grain_type='cereal', units='imperial')") # noqa + self.assertEquals( + out, + u"GrainAddition(Grain('pale 2-row', color=2.0, hwe=308.78), weight=13.96, grain_type='cereal', units='imperial')", + ) # noqa def test_get_weight_cereal(self): - grain_add = GrainAddition(pale, weight=13.96, - grain_type=GRAIN_TYPE_CEREAL) + grain_add = GrainAddition(pale, weight=13.96, grain_type=GRAIN_TYPE_CEREAL) self.assertEquals(grain_add.grain_type, GRAIN_TYPE_CEREAL) out = grain_add.get_cereal_weight(ppg=ppg_pale) self.assertEqual(round(out, 2), 13.96) @@ -200,8 +177,7 @@ def test_get_weight_cereal(self): self.assertEqual(round(out, 2), 11.74) def test_get_weight_lme(self): - grain_add = GrainAddition(pale_lme, weight=14.35, - grain_type=GRAIN_TYPE_LME) + grain_add = GrainAddition(pale_lme, weight=14.35, grain_type=GRAIN_TYPE_LME) self.assertEquals(grain_add.grain_type, GRAIN_TYPE_LME) out = grain_add.get_cereal_weight(ppg=ppg_pale) self.assertEqual(round(out, 2), 13.96) @@ -211,8 +187,7 @@ def test_get_weight_lme(self): self.assertEqual(round(out, 2), 11.74) def test_get_weight_dme(self): - grain_add = GrainAddition(pale_dme, weight=11.74, - grain_type=GRAIN_TYPE_DME) + grain_add = GrainAddition(pale_dme, weight=11.74, grain_type=GRAIN_TYPE_DME) self.assertEquals(grain_add.grain_type, GRAIN_TYPE_DME) out = grain_add.get_cereal_weight(ppg=ppg_pale) self.assertEqual(round(out, 2), 13.96) @@ -222,8 +197,7 @@ def test_get_weight_dme(self): self.assertEqual(round(out, 2), 11.74) def test_get_weight_specialty(self): - grain_add = GrainAddition(pale, weight=13.96, - grain_type=GRAIN_TYPE_SPECIALTY) + grain_add = GrainAddition(pale, weight=13.96, grain_type=GRAIN_TYPE_SPECIALTY) self.assertEquals(grain_add.grain_type, GRAIN_TYPE_SPECIALTY) out = grain_add.get_cereal_weight(ppg=ppg_pale) self.assertEqual(round(out, 2), 13.96) @@ -234,19 +208,12 @@ def test_get_weight_specialty(self): def test_get_weight_map(self): out = self.grain_add.get_weight_map() - expected = { - u'grain_weight': 13.96, - u'lme_weight': 14.35, - u'dry_weight': 11.74, - } + expected = {u"grain_weight": 13.96, u"lme_weight": 14.35, u"dry_weight": 11.74} self.assertEquals(out, expected) def test_convert_to_cereal(self): - grain_add = GrainAddition(pale, - weight=1.0, - grain_type=GRAIN_TYPE_CEREAL) - ga_cereal = grain_add.convert_to_cereal(ppg=ppg_pale, - brew_house_yield=BHY) + grain_add = GrainAddition(pale, weight=1.0, grain_type=GRAIN_TYPE_CEREAL) + ga_cereal = grain_add.convert_to_cereal(ppg=ppg_pale, brew_house_yield=BHY) ga_lme = grain_add.convert_to_lme(ppg=PPG_LME, brew_house_yield=BHY) ga_dme = grain_add.convert_to_dme(ppg=PPG_DME, brew_house_yield=BHY) @@ -255,20 +222,14 @@ def test_convert_to_cereal(self): self.assertEquals(round(ga_dme.weight, 2), 0.59) def test_convert_to_cereal_raises(self): - grain_add = GrainAddition(pale_lme, - weight=1.0, - grain_type=GRAIN_TYPE_LME) + grain_add = GrainAddition(pale_lme, weight=1.0, grain_type=GRAIN_TYPE_LME) with self.assertRaises(GrainException) as ctx: grain_add.convert_to_cereal(brew_house_yield=BHY) - self.assertEquals(str(ctx.exception), - u'Must provide PPG to convert to cereal') + self.assertEquals(str(ctx.exception), u"Must provide PPG to convert to cereal") def test_convert_to_lme(self): - grain_add = GrainAddition(pale_lme, - weight=1.0, - grain_type=GRAIN_TYPE_LME) - ga_cereal = grain_add.convert_to_cereal(ppg=ppg_pale, - brew_house_yield=BHY) + grain_add = GrainAddition(pale_lme, weight=1.0, grain_type=GRAIN_TYPE_LME) + ga_cereal = grain_add.convert_to_cereal(ppg=ppg_pale, brew_house_yield=BHY) ga_lme = grain_add.convert_to_lme(ppg=PPG_LME, brew_house_yield=BHY) ga_dme = grain_add.convert_to_dme(ppg=PPG_DME, brew_house_yield=BHY) @@ -277,11 +238,8 @@ def test_convert_to_lme(self): self.assertEquals(round(ga_dme.weight, 2), 0.82) def test_convert_to_dme(self): - grain_add = GrainAddition(pale_dme, - weight=1.0, - grain_type=GRAIN_TYPE_DME) - ga_cereal = grain_add.convert_to_cereal(ppg=ppg_pale, - brew_house_yield=BHY) + grain_add = GrainAddition(pale_dme, weight=1.0, grain_type=GRAIN_TYPE_DME) + ga_cereal = grain_add.convert_to_cereal(ppg=ppg_pale, brew_house_yield=BHY) ga_lme = grain_add.convert_to_lme(ppg=PPG_LME, brew_house_yield=BHY) ga_dme = grain_add.convert_to_dme(ppg=PPG_DME, brew_house_yield=BHY) @@ -306,14 +264,12 @@ def test_ne_weight(self): def test_ne_grain_type(self): grain_add1 = GrainAddition(pale, weight=13.96) - grain_add2 = GrainAddition(pale, weight=13.96, - grain_type=GRAIN_TYPE_DME) + grain_add2 = GrainAddition(pale, weight=13.96, grain_type=GRAIN_TYPE_DME) self.assertTrue(grain_add1 != grain_add2) def test_ne_units(self): grain_add1 = GrainAddition(pale, weight=13.96) - grain_add2 = GrainAddition(pale, weight=13.96, - units=SI_UNITS) + grain_add2 = GrainAddition(pale, weight=13.96, units=SI_UNITS) self.assertTrue(grain_add1 != grain_add2) def test_ne_grain_class(self): @@ -331,16 +287,13 @@ def test_get_gravity_units(self): def test_to_dict(self): out = self.grain_add.to_dict() - expected = {u'name': u'pale 2-row', - u'data': { - u'color': 2.0, - u'ppg': ppg_pale, - u'hwe': 308.78, - }, - u'grain_type': u'cereal', - u'weight': 13.96, - u'units': u'imperial', - } + expected = { + u"name": u"pale 2-row", + u"data": {u"color": 2.0, u"ppg": ppg_pale, u"hwe": 308.78}, + u"grain_type": u"cereal", + u"weight": 13.96, + u"units": u"imperial", + } self.assertEquals(out, expected) def test_to_json(self): @@ -354,11 +307,13 @@ def test_validate(self): def test_format(self): out = self.grain_add.format() - msg = textwrap.dedent(u"""\ + msg = textwrap.dedent( + u"""\ pale 2-row Addition ----------------------------------- Grain Type: cereal - Weight: 13.96 lbs""") + Weight: 13.96 lbs""" + ) self.assertEquals(out, msg) def test_grain_change_units_imperial_to_si(self): diff --git a/tests/test_hops.py b/tests/test_hops.py index b74cb69..10cf160 100644 --- a/tests/test_hops.py +++ b/tests/test_hops.py @@ -16,7 +16,6 @@ class TestHops(unittest.TestCase): - def setUp(self): # Define Hops @@ -24,40 +23,33 @@ def setUp(self): def test_str(self): out = str(self.hop) - self.assertEquals(out, u'Centennial, alpha 14.0%') + self.assertEquals(out, u"Centennial, alpha 14.0%") def test_unicode(self): - hop = Hop(u'Galaxy ®', - percent_alpha_acids=0.11) + hop = Hop(u"Galaxy ®", percent_alpha_acids=0.11) out = str(hop) if sys.version_info[0] >= 3: - self.assertEquals(out, u'Galaxy ®, alpha 11.0%') + self.assertEquals(out, u"Galaxy ®, alpha 11.0%") else: - self.assertEquals(out, u'Galaxy ®, alpha 11.0%'.encode('utf8')) + self.assertEquals(out, u"Galaxy ®, alpha 11.0%".encode("utf8")) def test_repr(self): out = repr(self.hop) self.assertEquals(out, u"Hop('centennial', percent_alpha_acids=0.14)") def test_eq(self): - hop1 = Hop(u'cascade', - percent_alpha_acids=0.07) - hop2 = Hop(u'cascade', - percent_alpha_acids=0.07) + hop1 = Hop(u"cascade", percent_alpha_acids=0.07) + hop2 = Hop(u"cascade", percent_alpha_acids=0.07) self.assertEquals(hop1, hop2) def test_ne_name(self): - hop1 = Hop(u'cascade', - percent_alpha_acids=0.07) - hop2 = Hop(u'centennial', - percent_alpha_acids=0.07) + hop1 = Hop(u"cascade", percent_alpha_acids=0.07) + hop2 = Hop(u"centennial", percent_alpha_acids=0.07) self.assertTrue(hop1 != hop2) def test_ne_percent_alpha_acids(self): - hop1 = Hop(u'cascade', - percent_alpha_acids=0.07) - hop2 = Hop(u'cascade', - percent_alpha_acids=0.14) + hop1 = Hop(u"cascade", percent_alpha_acids=0.07) + hop2 = Hop(u"cascade", percent_alpha_acids=0.14) self.assertTrue(hop1 != hop2) def test_ne_hop_add_class(self): @@ -65,9 +57,7 @@ def test_ne_hop_add_class(self): def test_to_dict(self): out = self.hop.to_dict() - expected = {u'name': u'centennial', - u'percent_alpha_acids': 0.14, - } + expected = {u"name": u"centennial", u"percent_alpha_acids": 0.14} self.assertEquals(out, expected) def test_to_json(self): @@ -77,42 +67,42 @@ def test_to_json(self): def test_format(self): out = self.hop.format() - msg = textwrap.dedent(u"""\ + msg = textwrap.dedent( + u"""\ centennial Hops ----------------------------------- - Alpha Acids: 14.0%""") + Alpha Acids: 14.0%""" + ) self.assertEquals(out, msg) def test_hop_no_percent_alpha_acids(self): with self.assertRaises(HopException) as ctx: - Hop(u'centennial') - self.assertEquals(str(ctx.exception), - u'centennial: Must provide percent alpha acids') + Hop(u"centennial") + self.assertEquals( + str(ctx.exception), u"centennial: Must provide percent alpha acids" + ) class TestHopAdditions(unittest.TestCase): - def setUp(self): self.hop1 = centennial self.hop2 = cascade self.addition_kwargs = [ { - u'boil_time': 60.0, - u'weight': 0.57, - u'utilization_cls_kwargs': {u'units': IMPERIAL_UNITS}, + u"boil_time": 60.0, + u"weight": 0.57, + u"utilization_cls_kwargs": {u"units": IMPERIAL_UNITS}, }, { - u'boil_time': 5.0, - u'weight': 0.76, - u'utilization_cls_kwargs': {u'units': IMPERIAL_UNITS}, + u"boil_time": 5.0, + u"weight": 0.76, + u"utilization_cls_kwargs": {u"units": IMPERIAL_UNITS}, }, ] # Additions - self.hop_addition1 = HopAddition(self.hop1, - **self.addition_kwargs[0]) - self.hop_addition2 = HopAddition(self.hop2, - **self.addition_kwargs[1]) + self.hop_addition1 = HopAddition(self.hop1, **self.addition_kwargs[0]) + self.hop_addition2 = HopAddition(self.hop2, **self.addition_kwargs[1]) # Define Hops self.plato = 14.0 @@ -131,30 +121,34 @@ def test_change_units(self): def test_str(self): out = str(self.hop_addition1) - self.assertEquals( - out, u'Centennial, alpha 14.0%, 0.57 oz, 60.0 min, pellet') + self.assertEquals(out, u"Centennial, alpha 14.0%, 0.57 oz, 60.0 min, pellet") def test_unicode(self): - hop = Hop(u'Galaxy ®', - percent_alpha_acids=0.11) - hop_add = HopAddition(hop, - boil_time=60.0, - weight=0.57) + hop = Hop(u"Galaxy ®", percent_alpha_acids=0.11) + hop_add = HopAddition(hop, boil_time=60.0, weight=0.57) out = str(hop_add) if sys.version_info[0] >= 3: - self.assertEquals(out, u'Galaxy ®, alpha 11.0%, 0.57 oz, 60.0 min, pellet') # noqa + self.assertEquals( + out, u"Galaxy ®, alpha 11.0%, 0.57 oz, 60.0 min, pellet" + ) # noqa else: - self.assertEquals(out, u'Galaxy ®, alpha 11.0%, 0.57 oz, 60.0 min, pellet'.encode('utf8')) # noqa + self.assertEquals( + out, u"Galaxy ®, alpha 11.0%, 0.57 oz, 60.0 min, pellet".encode("utf8") + ) # noqa def test_repr(self): out = repr(self.hop_addition1) try: st_type = unicode # noqa self.assertEquals( - out, u"HopAddition(Hop('centennial', percent_alpha_acids=0.14), weight=0.57, boil_time=60.0, hop_type='pellet', utilization_cls=HopsUtilizationGlennTinseth, utilization_cls_kwargs={u'units': u'imperial'}, units='imperial')") # noqa + out, + u"HopAddition(Hop('centennial', percent_alpha_acids=0.14), weight=0.57, boil_time=60.0, hop_type='pellet', utilization_cls=HopsUtilizationGlennTinseth, utilization_cls_kwargs={u'units': u'imperial'}, units='imperial')", + ) # noqa except NameError: self.assertEquals( - out, u"HopAddition(Hop('centennial', percent_alpha_acids=0.14), weight=0.57, boil_time=60.0, hop_type='pellet', utilization_cls=HopsUtilizationGlennTinseth, utilization_cls_kwargs={'units': 'imperial'}, units='imperial')") # noqa + out, + u"HopAddition(Hop('centennial', percent_alpha_acids=0.14), weight=0.57, boil_time=60.0, hop_type='pellet', utilization_cls=HopsUtilizationGlennTinseth, utilization_cls_kwargs={'units': 'imperial'}, units='imperial')", + ) # noqa def test_eq(self): hop_add1 = HopAddition(cascade, boil_time=5.0, weight=0.76) @@ -173,14 +167,14 @@ def test_ne_weight(self): def test_ne_hop_type(self): hop_add1 = HopAddition(cascade, boil_time=5.0, weight=0.76) - hop_add2 = HopAddition(cascade, boil_time=5.0, weight=0.76, - hop_type=HOP_TYPE_WHOLE) + hop_add2 = HopAddition( + cascade, boil_time=5.0, weight=0.76, hop_type=HOP_TYPE_WHOLE + ) self.assertTrue(hop_add1 != hop_add2) def test_ne_units(self): hop_add1 = HopAddition(cascade, boil_time=5.0, weight=0.76) - hop_add2 = HopAddition(cascade, boil_time=5.0, weight=0.76, - units=SI_UNITS) + hop_add2 = HopAddition(cascade, boil_time=5.0, weight=0.76, units=SI_UNITS) self.assertTrue(hop_add1 != hop_add2) def test_ne_hop_class(self): @@ -188,15 +182,16 @@ def test_ne_hop_class(self): def test_to_dict(self): out = self.hop_addition1.to_dict() - expected = {u'name': u'centennial', - u'data': {u'percent_alpha_acids': 0.14}, - u'weight': 0.57, - u'boil_time': 60.0, - u'hop_type': u'pellet', - u'utilization_cls': u'Glenn Tinseth', - u'utilization_cls_kwargs': {u'units': u'imperial'}, - u'units': u'imperial', - } + expected = { + u"name": u"centennial", + u"data": {u"percent_alpha_acids": 0.14}, + u"weight": 0.57, + u"boil_time": 60.0, + u"hop_type": u"pellet", + u"utilization_cls": u"Glenn Tinseth", + u"utilization_cls_kwargs": {u"units": u"imperial"}, + u"units": u"imperial", + } self.assertEquals(out, expected) def test_to_json(self): @@ -210,13 +205,15 @@ def test_validate(self): def test_format(self): out = self.hop_addition1.format() - msg = textwrap.dedent(u"""\ + msg = textwrap.dedent( + u"""\ centennial Addition ----------------------------------- Hop Type: pellet AA %: 14.0% Weight: 0.57 oz - Boil Time: 60.0 min""") + Boil Time: 60.0 min""" + ) self.assertEquals(out, msg) def test_get_alpha_acid_units(self): diff --git a/tests/test_parsers.py b/tests/test_parsers.py index b139868..f2ebff6 100644 --- a/tests/test_parsers.py +++ b/tests/test_parsers.py @@ -22,94 +22,96 @@ class CerealsLoader(DataLoader): def get_item(self, dir_suffix, item_name): grain_add = pale_add.to_dict() - grain_add.update(grain_add.pop(u'data')) + grain_add.update(grain_add.pop(u"data")) return grain_add class HopsLoader(DataLoader): def get_item(self, dir_suffix, item_name): hop_add = cascade_add.to_dict() - hop_add.update(hop_add.pop(u'data')) + hop_add.update(hop_add.pop(u"data")) return hop_add class YeastLoader(DataLoader): def get_item(self, dir_suffix, item_name): yst = yeast.to_dict() - yst.update(yst.pop(u'data')) + yst.update(yst.pop(u"data")) return yst class TestDataLoader(unittest.TestCase): - def setUp(self): - self.loader = DataLoader('./') + self.loader = DataLoader("./") self.loader.DATA = {} - self.loader.EXT = 'json' + self.loader.EXT = "json" def test_data_dir_does_not_exist(self): with self.assertRaises(DataLoaderException) as ctx: - DataLoader('./baddirectory') - self.assertEquals(str(ctx.exception), - u"Directory './baddirectory' does not exist") + DataLoader("./baddirectory") + self.assertEquals( + str(ctx.exception), u"Directory './baddirectory' does not exist" + ) def test_read_data_raises(self): with self.assertRaises(NotImplementedError): - self.loader.read_data('filename') + self.loader.read_data("filename") - @mock.patch('glob.glob') + @mock.patch("glob.glob") def test_get_item(self, mock_glob): def read_data(item_filename): - return 'data' + return "data" + self.loader.read_data = read_data - mock_glob.return_value = ['cereals/crystal_20.json'] - out = self.loader.get_item('/', 'crystal 20') - expected = 'data' + mock_glob.return_value = ["cereals/crystal_20.json"] + out = self.loader.get_item("/", "crystal 20") + expected = "data" self.assertEquals(out, expected) - @mock.patch('glob.glob') + @mock.patch("glob.glob") def test_get_item_dir_does_not_exist(self, mock_glob): with self.assertRaises(DataLoaderException) as ctx: - self.loader.get_item('baditemdir/', 'crystal 20') - self.assertEquals(str(ctx.exception), - u"Item directory './baditemdir/' does not exist") + self.loader.get_item("baditemdir/", "crystal 20") + self.assertEquals( + str(ctx.exception), u"Item directory './baditemdir/' does not exist" + ) - @mock.patch('glob.glob') + @mock.patch("glob.glob") def test_get_item_warns(self, mock_glob): def read_data(item_filename): - return 'data' + return "data" + self.loader.read_data = read_data - mock_glob.return_value = ['cereals/crystal_40.json'] + mock_glob.return_value = ["cereals/crystal_40.json"] with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") - self.loader.get_item('/', 'crystal 20') + self.loader.get_item("/", "crystal 20") self.assertEqual(len(w), 1) self.assertTrue(issubclass(w[-1].category, Warning)) - self.assertTrue('dir not found' in str(w[-1].message)) + self.assertTrue("dir not found" in str(w[-1].message)) class TestJSONDataLoader(unittest.TestCase): - def setUp(self): - self.loader = JSONDataLoader('./') + self.loader = JSONDataLoader("./") def test_format_name(self): - name_list = [(u'pale malt 2-row us', u'pale_malt_2_row_us'), - (u'caramel crystal malt 20l', u'caramel_crystal_malt_20l'), # noqa - (u'centennial', u'centennial'), - (u'cascade us', u'cascade_us'), - (u'Wyeast 1056', u'wyeast_1056'), - ] + name_list = [ + (u"pale malt 2-row us", u"pale_malt_2_row_us"), + (u"caramel crystal malt 20l", u"caramel_crystal_malt_20l"), # noqa + (u"centennial", u"centennial"), + (u"cascade us", u"cascade_us"), + (u"Wyeast 1056", u"wyeast_1056"), + ] for name, expected in name_list: out = self.loader.format_name(name) self.assertEquals(out, expected) class TestCerealParser(unittest.TestCase): - def setUp(self): self.grain_add = pale_add.to_dict() - self.loader = CerealsLoader('./') + self.loader = CerealsLoader("./") def test_parse_cereals(self): out = parse_cereals(self.grain_add, self.loader) @@ -118,14 +120,15 @@ def test_parse_cereals(self): def test_parse_cereals_loader_returns_no_data(self): def get_item(dir_suffix, item_name): return {} + self.loader.get_item = get_item out = parse_cereals(self.grain_add, self.loader) self.assertEquals(out, pale_add) def test_parse_cereals_no_color(self): grain_add = pale_add.to_dict() - grain_add[u'data'].pop(u'color') - grain_add.update(grain_add.pop(u'data')) + grain_add[u"data"].pop(u"color") + grain_add.update(grain_add.pop(u"data")) out = parse_cereals(grain_add, self.loader) self.assertEquals(out, pale_add) @@ -133,21 +136,21 @@ def test_parse_cereals_no_color_data(self): class Loader(DataLoader): def get_item(self, dir_suffix, item_name): grain_add = pale_add.to_dict() - grain_add[u'data'].pop(u'color') - grain_add.update(grain_add.pop(u'data')) + grain_add[u"data"].pop(u"color") + grain_add.update(grain_add.pop(u"data")) return grain_add + grain_add = pale_add.to_dict() - grain_add[u'data'].pop(u'color') - grain_add.update(grain_add.pop(u'data')) + grain_add[u"data"].pop(u"color") + grain_add.update(grain_add.pop(u"data")) with self.assertRaises(GrainException) as ctx: - parse_cereals(grain_add, Loader('./')) - self.assertEquals(str(ctx.exception), - u"pale 2-row: Must provide color value") + parse_cereals(grain_add, Loader("./")) + self.assertEquals(str(ctx.exception), u"pale 2-row: Must provide color value") def test_parse_cereals_no_ppg(self): grain_add = pale_add.to_dict() - grain_add[u'data'].pop(u'ppg') - grain_add.update(grain_add.pop(u'data')) + grain_add[u"data"].pop(u"ppg") + grain_add.update(grain_add.pop(u"data")) out = parse_cereals(grain_add, self.loader) self.assertEquals(out, pale_add) @@ -155,23 +158,22 @@ def test_parse_cereals_no_ppg_data(self): class Loader(DataLoader): def get_item(self, dir_suffix, item_name): grain_add = pale_add.to_dict() - grain_add[u'data'].pop(u'ppg') - grain_add.update(grain_add.pop(u'data')) + grain_add[u"data"].pop(u"ppg") + grain_add.update(grain_add.pop(u"data")) return grain_add + grain_add = pale_add.to_dict() - grain_add[u'data'].pop(u'ppg') - grain_add.update(grain_add.pop(u'data')) + grain_add[u"data"].pop(u"ppg") + grain_add.update(grain_add.pop(u"data")) with self.assertRaises(GrainException) as ctx: - parse_cereals(grain_add, Loader('./')) - self.assertEquals(str(ctx.exception), - u"pale 2-row: Must provide ppg or hwe") + parse_cereals(grain_add, Loader("./")) + self.assertEquals(str(ctx.exception), u"pale 2-row: Must provide ppg or hwe") class TestHopsParser(unittest.TestCase): - def setUp(self): self.hop_add = cascade_add.to_dict() - self.loader = HopsLoader('./') + self.loader = HopsLoader("./") def test_parse_hops(self): out = parse_hops(self.hop_add, self.loader) @@ -180,14 +182,15 @@ def test_parse_hops(self): def test_parse_hops_loader_returns_no_data(self): def get_item(dir_suffix, item_name): return {} + self.loader.get_item = get_item out = parse_hops(self.hop_add, self.loader) self.assertEquals(out, cascade_add) def test_parse_hops_no_percent_alpha_acids(self): hop_add = cascade_add.to_dict() - hop_add[u'data'].pop(u'percent_alpha_acids') - hop_add.update(hop_add.pop(u'data')) + hop_add[u"data"].pop(u"percent_alpha_acids") + hop_add.update(hop_add.pop(u"data")) out = parse_hops(hop_add, self.loader) self.assertEquals(out, cascade_add) @@ -195,23 +198,24 @@ def test_parse_hops_no_percent_alpha_acids_data(self): class Loader(DataLoader): def get_item(self, dir_suffix, item_name): hop_add = cascade_add.to_dict() - hop_add[u'data'].pop(u'percent_alpha_acids') - hop_add.update(hop_add.pop(u'data')) + hop_add[u"data"].pop(u"percent_alpha_acids") + hop_add.update(hop_add.pop(u"data")) return hop_add + hop_add = cascade_add.to_dict() - hop_add[u'data'].pop(u'percent_alpha_acids') - hop_add.update(hop_add.pop(u'data')) + hop_add[u"data"].pop(u"percent_alpha_acids") + hop_add.update(hop_add.pop(u"data")) with self.assertRaises(HopException) as ctx: - parse_hops(hop_add, Loader('./')) - self.assertEquals(str(ctx.exception), - u"cascade: Must provide percent alpha acids") + parse_hops(hop_add, Loader("./")) + self.assertEquals( + str(ctx.exception), u"cascade: Must provide percent alpha acids" + ) class TestYeastParser(unittest.TestCase): - def setUp(self): self.yeast = yeast.to_dict() - self.loader = YeastLoader('./') + self.loader = YeastLoader("./") def test_parse_yeast(self): out = parse_yeast(self.yeast, self.loader) @@ -220,14 +224,15 @@ def test_parse_yeast(self): def test_parse_yeast_loader_returns_no_data(self): def get_item(dir_suffix, item_name): return {} + self.loader.get_item = get_item out = parse_yeast(self.yeast, self.loader) self.assertEquals(out, yeast) def test_parse_yeast_no_percent_attenuation(self): yst = yeast.to_dict() - yst[u'data'].pop(u'percent_attenuation') - yst.update(yst.pop(u'data')) + yst[u"data"].pop(u"percent_attenuation") + yst.update(yst.pop(u"data")) out = parse_yeast(yst, self.loader) self.assertEquals(out, yeast) @@ -235,46 +240,54 @@ def test_parse_yeast_no_percent_attenuation_data(self): class Loader(DataLoader): def get_item(self, dir_suffix, item_name): yst = yeast.to_dict() - yst[u'data'].pop(u'percent_attenuation') - yst.update(yst.pop(u'data')) + yst[u"data"].pop(u"percent_attenuation") + yst.update(yst.pop(u"data")) return yst + yst = yeast.to_dict() - yst[u'data'].pop(u'percent_attenuation') - yst.update(yst.pop(u'data')) + yst[u"data"].pop(u"percent_attenuation") + yst.update(yst.pop(u"data")) with self.assertRaises(YeastException) as ctx: - parse_yeast(yst, Loader('./')) - self.assertEquals(str(ctx.exception), - u"Wyeast 1056: Must provide percent attenuation") + parse_yeast(yst, Loader("./")) + self.assertEquals( + str(ctx.exception), u"Wyeast 1056: Must provide percent attenuation" + ) class TestRecipeParser(unittest.TestCase): - def setUp(self): # A special recipe is needed since the loaders only return # pre-chosen additions - self.recipe = Recipe(name=u'pale ale', - grain_additions=[pale_add, pale_add], - hop_additions=[cascade_add, cascade_add], - yeast=yeast, - brew_house_yield=0.70, # % - start_volume=7.0, # G - final_volume=5.0, # G - ) + self.recipe = Recipe( + name=u"pale ale", + grain_additions=[pale_add, pale_add], + hop_additions=[cascade_add, cascade_add], + yeast=yeast, + brew_house_yield=0.70, # % + start_volume=7.0, # G + final_volume=5.0, # G + ) self.recipe_data = self.recipe.to_dict() - self.cereals_loader = CerealsLoader('./') - self.hops_loader = HopsLoader('./') - self.yeast_loader = YeastLoader('./') + self.cereals_loader = CerealsLoader("./") + self.hops_loader = HopsLoader("./") + self.yeast_loader = YeastLoader("./") def test_parse_recipe(self): - out = parse_recipe(self.recipe_data, None, - cereals_loader=self.cereals_loader, - hops_loader=self.hops_loader, - yeast_loader=self.yeast_loader) + out = parse_recipe( + self.recipe_data, + None, + cereals_loader=self.cereals_loader, + hops_loader=self.hops_loader, + yeast_loader=self.yeast_loader, + ) self.assertEquals(out, self.recipe) def test_parse_recipe_default_loader(self): - out = parse_recipe(self.recipe_data, DataLoader('./'), - cereals_dir_suffix='/', - hops_dir_suffix='/', - yeast_dir_suffix='/') + out = parse_recipe( + self.recipe_data, + DataLoader("./"), + cereals_dir_suffix="/", + hops_dir_suffix="/", + yeast_dir_suffix="/", + ) self.assertEquals(out, self.recipe) diff --git a/tests/test_recipes.py b/tests/test_recipes.py index bf1f5a1..94d1afc 100644 --- a/tests/test_recipes.py +++ b/tests/test_recipes.py @@ -22,7 +22,6 @@ class TestRecipe(unittest.TestCase): - def setUp(self): # Define Grains self.grain_additions = grain_additions @@ -39,84 +38,74 @@ def setUp(self): def test_str(self): out = str(self.recipe) - self.assertEquals(out, u'pale ale') + self.assertEquals(out, u"pale ale") def test_unicode(self): - recipe = Recipe(name=u'Kölsch Ale', - grain_additions=grain_additions, - hop_additions=hop_additions, - yeast=yeast, - brew_house_yield=0.70, - start_volume=7.0, - final_volume=5.0, - ) + recipe = Recipe( + name=u"Kölsch Ale", + grain_additions=grain_additions, + hop_additions=hop_additions, + yeast=yeast, + brew_house_yield=0.70, + start_volume=7.0, + final_volume=5.0, + ) out = str(recipe) if sys.version_info[0] >= 3: - self.assertEquals(out, u'Kölsch Ale') + self.assertEquals(out, u"Kölsch Ale") else: - self.assertEquals(out, u'Kölsch Ale'.encode('utf8')) + self.assertEquals(out, u"Kölsch Ale".encode("utf8")) def test_repr(self): out = repr(self.recipe) - self.assertEquals(out, u"Recipe('pale ale', grain_additions=[GrainAddition(Grain('pale 2-row', color=2.0, hwe=308.78), weight=13.96, grain_type='cereal', units='imperial'), GrainAddition(Grain('crystal C20', color=20.0, hwe=292.09), weight=0.78, grain_type='cereal', units='imperial')], hop_additions=[HopAddition(Hop('centennial', percent_alpha_acids=0.14), weight=0.57, boil_time=60.0, hop_type='pellet', utilization_cls=HopsUtilizationGlennTinseth, units='imperial'), HopAddition(Hop('cascade', percent_alpha_acids=0.07), weight=0.76, boil_time=5.0, hop_type='pellet', utilization_cls=HopsUtilizationGlennTinseth, units='imperial')], yeast=Yeast('Wyeast 1056', percent_attenuation=0.75), brew_house_yield=0.7, start_volume=7.0, final_volume=5.0, units=imperial)") # noqa + self.assertEquals( + out, + u"Recipe('pale ale', grain_additions=[GrainAddition(Grain('pale 2-row', color=2.0, hwe=308.78), weight=13.96, grain_type='cereal', units='imperial'), GrainAddition(Grain('crystal C20', color=20.0, hwe=292.09), weight=0.78, grain_type='cereal', units='imperial')], hop_additions=[HopAddition(Hop('centennial', percent_alpha_acids=0.14), weight=0.57, boil_time=60.0, hop_type='pellet', utilization_cls=HopsUtilizationGlennTinseth, units='imperial'), HopAddition(Hop('cascade', percent_alpha_acids=0.07), weight=0.76, boil_time=5.0, hop_type='pellet', utilization_cls=HopsUtilizationGlennTinseth, units='imperial')], yeast=Yeast('Wyeast 1056', percent_attenuation=0.75), brew_house_yield=0.7, start_volume=7.0, final_volume=5.0, units=imperial)", + ) # noqa def test_eq(self): - recipe1 = Recipe(u'pale ale') - recipe2 = Recipe(u'pale ale') + recipe1 = Recipe(u"pale ale") + recipe2 = Recipe(u"pale ale") self.assertEquals(recipe1, recipe2) def test_ne_name(self): - recipe1 = Recipe(u'pale ale') - recipe2 = Recipe(u'ipa') + recipe1 = Recipe(u"pale ale") + recipe2 = Recipe(u"ipa") self.assertTrue(recipe1 != recipe2) def test_ne_grain_additions(self): - recipe1 = Recipe(u'pale ale', - grain_additions=grain_additions) - recipe2 = Recipe(u'pale ale', - grain_additions=[grain_additions[0]]) + recipe1 = Recipe(u"pale ale", grain_additions=grain_additions) + recipe2 = Recipe(u"pale ale", grain_additions=[grain_additions[0]]) self.assertTrue(recipe1 != recipe2) def test_ne_hop_additions(self): - recipe1 = Recipe(u'pale ale', - hop_additions=hop_additions) - recipe2 = Recipe(u'pale ale', - hop_additions=[hop_additions[0]]) + recipe1 = Recipe(u"pale ale", hop_additions=hop_additions) + recipe2 = Recipe(u"pale ale", hop_additions=[hop_additions[0]]) self.assertTrue(recipe1 != recipe2) def test_ne_yeast(self): - recipe1 = Recipe(u'pale ale', - yeast=yeast) - recipe2 = Recipe(u'pale ale', - yeast=None) + recipe1 = Recipe(u"pale ale", yeast=yeast) + recipe2 = Recipe(u"pale ale", yeast=None) self.assertTrue(recipe1 != recipe2) def test_ne_brew_house_yield(self): - recipe1 = Recipe(u'pale ale', - brew_house_yield=0.70) - recipe2 = Recipe(u'pale ale', - brew_house_yield=0.65) + recipe1 = Recipe(u"pale ale", brew_house_yield=0.70) + recipe2 = Recipe(u"pale ale", brew_house_yield=0.65) self.assertTrue(recipe1 != recipe2) def test_ne_start_volume(self): - recipe1 = Recipe(u'pale ale', - start_volume=7.0) - recipe2 = Recipe(u'pale ale', - start_volume=6.5) + recipe1 = Recipe(u"pale ale", start_volume=7.0) + recipe2 = Recipe(u"pale ale", start_volume=6.5) self.assertTrue(recipe1 != recipe2) def test_ne_final_volume(self): - recipe1 = Recipe(u'pale ale', - final_volume=6.0) - recipe2 = Recipe(u'pale ale', - final_volume=5.5) + recipe1 = Recipe(u"pale ale", final_volume=6.0) + recipe2 = Recipe(u"pale ale", final_volume=5.5) self.assertTrue(recipe1 != recipe2) def test_ne_units(self): - recipe1 = Recipe(u'pale ale', - units=IMPERIAL_UNITS) - recipe2 = Recipe(u'pale ale', - units=SI_UNITS) + recipe1 = Recipe(u"pale ale", units=IMPERIAL_UNITS) + recipe2 = Recipe(u"pale ale", units=SI_UNITS) self.assertTrue(recipe1 != recipe2) def test_ne_recipe_class(self): @@ -131,32 +120,44 @@ def test_set_units(self): def test_set_raises(self): with self.assertRaises(ValidatorException) as ctx: # noqa - self.recipe.set_units(u'bad') + self.recipe.set_units(u"bad") def test_grains_units_mismatch_raises(self): grain_additions = [g.change_units() for g in self.grain_additions] with self.assertRaises(RecipeException) as ctx: - Recipe(name=u'pale ale', - grain_additions=grain_additions, - hop_additions=self.hop_additions, - yeast=self.yeast) - self.assertEquals(str(ctx.exception), - u"pale ale: Grain addition units must be in 'imperial' not 'metric'") # noqa + Recipe( + name=u"pale ale", + grain_additions=grain_additions, + hop_additions=self.hop_additions, + yeast=self.yeast, + ) + self.assertEquals( + str(ctx.exception), + u"pale ale: Grain addition units must be in 'imperial' not 'metric'", + ) # noqa def test_hops_units_mismatch_raises(self): hop_additions = [h.change_units() for h in self.hop_additions] with self.assertRaises(RecipeException) as ctx: - Recipe(name=u'pale ale', - grain_additions=self.grain_additions, - hop_additions=hop_additions, - yeast=self.yeast) - self.assertEquals(str(ctx.exception), - u"pale ale: Hop addition units must be in 'imperial' not 'metric'") # noqa + Recipe( + name=u"pale ale", + grain_additions=self.grain_additions, + hop_additions=hop_additions, + yeast=self.yeast, + ) + self.assertEquals( + str(ctx.exception), + u"pale ale: Hop addition units must be in 'imperial' not 'metric'", + ) # noqa def test_get_grain_additions_by_type(self): - grain_additions = self.recipe.get_grain_additions_by_type(GRAIN_TYPE_CEREAL) # noqa + grain_additions = self.recipe.get_grain_additions_by_type( + GRAIN_TYPE_CEREAL + ) # noqa self.assertEquals(grain_additions, self.recipe.grain_additions) - grain_additions = self.recipe.get_grain_additions_by_type(GRAIN_TYPE_LME) # noqa + grain_additions = self.recipe.get_grain_additions_by_type( + GRAIN_TYPE_LME + ) # noqa self.assertEquals(grain_additions, []) def test_get_hop_additions_by_type(self): @@ -167,7 +168,6 @@ def test_get_hop_additions_by_type(self): class TestRecipeBuilder(unittest.TestCase): - def setUp(self): # Define Grains self.grain_list = grain_list @@ -178,62 +178,53 @@ def setUp(self): def test_str(self): out = str(self.builder) - self.assertEquals(out, u'pale ale') + self.assertEquals(out, u"pale ale") def test_repr(self): out = repr(self.builder) - self.assertEquals(out, u"RecipeBuilder('pale ale', grain_list=[Grain('pale 2-row', color=2.0, hwe=308.78), Grain('crystal C20', color=20.0, hwe=292.09)], hop_list=[Hop('centennial', percent_alpha_acids=0.14), Hop('cascade', percent_alpha_acids=0.07)], target_og=1.0761348, brew_house_yield=0.7, start_volume=7.0, final_volume=5.0, units=imperial)") # noqa + self.assertEquals( + out, + u"RecipeBuilder('pale ale', grain_list=[Grain('pale 2-row', color=2.0, hwe=308.78), Grain('crystal C20', color=20.0, hwe=292.09)], hop_list=[Hop('centennial', percent_alpha_acids=0.14), Hop('cascade', percent_alpha_acids=0.07)], target_og=1.0761348, brew_house_yield=0.7, start_volume=7.0, final_volume=5.0, units=imperial)", + ) # noqa def test_eq(self): - builder1 = RecipeBuilder(u'pale ale') - builder2 = RecipeBuilder(u'pale ale') + builder1 = RecipeBuilder(u"pale ale") + builder2 = RecipeBuilder(u"pale ale") self.assertEquals(builder1, builder2) def test_ne_name(self): - builder1 = RecipeBuilder(u'pale ale') - builder2 = RecipeBuilder(u'ipa') + builder1 = RecipeBuilder(u"pale ale") + builder2 = RecipeBuilder(u"ipa") self.assertTrue(builder1 != builder2) def test_ne_grain_list(self): - builder1 = RecipeBuilder(u'pale ale', - grain_list=grain_list) - builder2 = RecipeBuilder(u'pale ale', - grain_list=[grain_list[0]]) + builder1 = RecipeBuilder(u"pale ale", grain_list=grain_list) + builder2 = RecipeBuilder(u"pale ale", grain_list=[grain_list[0]]) self.assertTrue(builder1 != builder2) def test_ne_hop_list(self): - builder1 = RecipeBuilder(u'pale ale', - hop_list=hop_list) - builder2 = RecipeBuilder(u'pale ale', - hop_list=[hop_list[0]]) + builder1 = RecipeBuilder(u"pale ale", hop_list=hop_list) + builder2 = RecipeBuilder(u"pale ale", hop_list=[hop_list[0]]) self.assertTrue(builder1 != builder2) def test_ne_brew_house_yield(self): - builder1 = RecipeBuilder(u'pale ale', - brew_house_yield=0.70) - builder2 = RecipeBuilder(u'pale ale', - brew_house_yield=0.65) + builder1 = RecipeBuilder(u"pale ale", brew_house_yield=0.70) + builder2 = RecipeBuilder(u"pale ale", brew_house_yield=0.65) self.assertTrue(builder1 != builder2) def test_ne_start_volume(self): - builder1 = RecipeBuilder(u'pale ale', - start_volume=7.0) - builder2 = RecipeBuilder(u'pale ale', - start_volume=6.5) + builder1 = RecipeBuilder(u"pale ale", start_volume=7.0) + builder2 = RecipeBuilder(u"pale ale", start_volume=6.5) self.assertTrue(builder1 != builder2) def test_ne_final_volume(self): - builder1 = RecipeBuilder(u'pale ale', - final_volume=6.0) - builder2 = RecipeBuilder(u'pale ale', - final_volume=5.5) + builder1 = RecipeBuilder(u"pale ale", final_volume=6.0) + builder2 = RecipeBuilder(u"pale ale", final_volume=5.5) self.assertTrue(builder1 != builder2) def test_ne_units(self): - builder1 = RecipeBuilder(u'pale ale', - units=IMPERIAL_UNITS) - builder2 = RecipeBuilder(u'pale ale', - units=SI_UNITS) + builder1 = RecipeBuilder(u"pale ale", units=IMPERIAL_UNITS) + builder2 = RecipeBuilder(u"pale ale", units=SI_UNITS) self.assertTrue(builder1 != builder2) def test_ne_builder_class(self): @@ -248,4 +239,4 @@ def test_set_units(self): def test_set_raises(self): with self.assertRaises(ValidatorException): - self.builder.set_units(u'bad') + self.builder.set_units(u"bad") diff --git a/tests/test_recipes_extract.py b/tests/test_recipes_extract.py index a817467..53b6183 100644 --- a/tests/test_recipes_extract.py +++ b/tests/test_recipes_extract.py @@ -8,7 +8,6 @@ class TestRecipeExtract(unittest.TestCase): - def setUp(self): # Define Recipes self.recipe = recipe @@ -19,27 +18,21 @@ def setUp(self): self.assertEquals(self.recipe_dme.units, IMPERIAL_UNITS) def test_recipe_is_recipe_lme(self): - recipe_data = self.recipe.to_dict()[u'data'] - recipe_data_lme = self.recipe_lme.to_dict()[u'data'] + recipe_data = self.recipe.to_dict()[u"data"] + recipe_data_lme = self.recipe_lme.to_dict()[u"data"] for key in recipe_data.keys(): # TODO: The colors are withing 0.1 of each other # but its hard to test in this way. Write another test. - if key == u'total_wort_color_map': + if key == u"total_wort_color_map": continue - self.assertEqual( - recipe_data[key], - recipe_data_lme[key], - msg=key) + self.assertEqual(recipe_data[key], recipe_data_lme[key], msg=key) def test_recipe_is_recipe_dme(self): - recipe_data = self.recipe.to_dict()[u'data'] - recipe_data_dme = self.recipe_dme.to_dict()[u'data'] + recipe_data = self.recipe.to_dict()[u"data"] + recipe_data_dme = self.recipe_dme.to_dict()[u"data"] for key in recipe_data.keys(): # TODO: The colors are withing 0.1 of each other # but its hard to test in this way. Write another test. - if key == u'total_wort_color_map': + if key == u"total_wort_color_map": continue - self.assertEquals( - recipe_data[key], - recipe_data_dme[key], - msg=key) + self.assertEquals(recipe_data[key], recipe_data_dme[key], msg=key) diff --git a/tests/test_recipes_imperial.py b/tests/test_recipes_imperial.py index 467197f..0c8dbfa 100644 --- a/tests/test_recipes_imperial.py +++ b/tests/test_recipes_imperial.py @@ -23,7 +23,6 @@ class TestRecipeImperialUnits(unittest.TestCase): - def setUp(self): # Define Grains self.grain_additions = grain_additions @@ -52,29 +51,31 @@ def test_get_total_points(self): self.assertEquals(round(out, 2), 380.67) def test_get_total_points_lme(self): - pale_lme_add = GrainAddition(pale_lme, - weight=14.35, - grain_type=GRAIN_TYPE_LME, - units=IMPERIAL_UNITS) - recipe = Recipe(u'lme', - grain_additions=[pale_lme_add], - hop_additions=self.hop_additions, - yeast=self.yeast, - units=IMPERIAL_UNITS) + pale_lme_add = GrainAddition( + pale_lme, weight=14.35, grain_type=GRAIN_TYPE_LME, units=IMPERIAL_UNITS + ) + recipe = Recipe( + u"lme", + grain_additions=[pale_lme_add], + hop_additions=self.hop_additions, + yeast=self.yeast, + units=IMPERIAL_UNITS, + ) out = recipe.get_total_points() self.assertEquals(round(out, 1), 516.6) def test_get_total_points_dme(self): - pale_dme_add = GrainAddition(pale_dme, - weight=11.74, - grain_type=GRAIN_TYPE_DME, - units=IMPERIAL_UNITS) - recipe = Recipe(u'dme', - grain_additions=[pale_dme_add], - hop_additions=self.hop_additions, - yeast=self.yeast, - units=IMPERIAL_UNITS) + pale_dme_add = GrainAddition( + pale_dme, weight=11.74, grain_type=GRAIN_TYPE_DME, units=IMPERIAL_UNITS + ) + recipe = Recipe( + u"dme", + grain_additions=[pale_dme_add], + hop_additions=self.hop_additions, + yeast=self.yeast, + units=IMPERIAL_UNITS, + ) out = recipe.get_total_points() self.assertEquals(round(out, 1), 516.6) @@ -145,29 +146,31 @@ def test_get_grain_add_dry_weight(self): self.assertEquals(round(out, 2), 0.62) def test_get_grain_add_dry_weight_lme(self): - pale_lme_add = GrainAddition(pale_lme, - weight=14.35, - grain_type=GRAIN_TYPE_LME, - units=IMPERIAL_UNITS) - recipe = Recipe(u'lme', - grain_additions=[pale_lme_add], - hop_additions=self.hop_additions, - yeast=self.yeast, - units=IMPERIAL_UNITS) + pale_lme_add = GrainAddition( + pale_lme, weight=14.35, grain_type=GRAIN_TYPE_LME, units=IMPERIAL_UNITS + ) + recipe = Recipe( + u"lme", + grain_additions=[pale_lme_add], + hop_additions=self.hop_additions, + yeast=self.yeast, + units=IMPERIAL_UNITS, + ) out = recipe.get_grain_add_dry_weight(pale_lme_add) self.assertEquals(round(out, 2), 11.74) def test_get_grain_add_dry_weight_dme(self): - pale_dme_add = GrainAddition(pale_dme, - weight=11.74, - grain_type=GRAIN_TYPE_DME, - units=IMPERIAL_UNITS) - recipe = Recipe(u'dme', - grain_additions=[pale_dme_add], - hop_additions=self.hop_additions, - yeast=self.yeast, - units=IMPERIAL_UNITS) + pale_dme_add = GrainAddition( + pale_dme, weight=11.74, grain_type=GRAIN_TYPE_DME, units=IMPERIAL_UNITS + ) + recipe = Recipe( + u"dme", + grain_additions=[pale_dme_add], + hop_additions=self.hop_additions, + yeast=self.yeast, + units=IMPERIAL_UNITS, + ) out = recipe.get_grain_add_dry_weight(pale_dme_add) self.assertEquals(round(out, 2), 11.74) @@ -177,41 +180,43 @@ def test_get_total_dry_weight(self): self.assertEquals(round(out, 2), 12.36) def test_get_grain_add_cereal_weight(self): - out = self.recipe.get_grain_add_cereal_weight(self.grain_additions[0], - ppg=ppg_pale) + out = self.recipe.get_grain_add_cereal_weight( + self.grain_additions[0], ppg=ppg_pale + ) self.assertEquals(round(out, 2), 13.96) - out = self.recipe.get_grain_add_cereal_weight(self.grain_additions[1], - ppg=ppg_crystal) + out = self.recipe.get_grain_add_cereal_weight( + self.grain_additions[1], ppg=ppg_crystal + ) self.assertEquals(round(out, 2), 0.78) def test_get_grain_add_cereal_weight_lme(self): - pale_lme_add = GrainAddition(pale_lme, - weight=14.35, - grain_type=GRAIN_TYPE_LME, - units=IMPERIAL_UNITS) - recipe = Recipe(u'lme', - grain_additions=[pale_lme_add], - hop_additions=self.hop_additions, - yeast=self.yeast, - units=IMPERIAL_UNITS) - - out = recipe.get_grain_add_cereal_weight(pale_lme_add, - ppg=ppg_pale) + pale_lme_add = GrainAddition( + pale_lme, weight=14.35, grain_type=GRAIN_TYPE_LME, units=IMPERIAL_UNITS + ) + recipe = Recipe( + u"lme", + grain_additions=[pale_lme_add], + hop_additions=self.hop_additions, + yeast=self.yeast, + units=IMPERIAL_UNITS, + ) + + out = recipe.get_grain_add_cereal_weight(pale_lme_add, ppg=ppg_pale) self.assertEquals(round(out, 2), 13.96) def test_get_grain_add_cereal_weight_dme(self): - pale_dme_add = GrainAddition(pale_dme, - weight=11.74, - grain_type=GRAIN_TYPE_DME, - units=IMPERIAL_UNITS) - recipe = Recipe(u'dme', - grain_additions=[pale_dme_add], - hop_additions=self.hop_additions, - yeast=self.yeast, - units=IMPERIAL_UNITS) - - out = recipe.get_grain_add_cereal_weight(pale_dme_add, - ppg=ppg_pale) + pale_dme_add = GrainAddition( + pale_dme, weight=11.74, grain_type=GRAIN_TYPE_DME, units=IMPERIAL_UNITS + ) + recipe = Recipe( + u"dme", + grain_additions=[pale_dme_add], + hop_additions=self.hop_additions, + yeast=self.yeast, + units=IMPERIAL_UNITS, + ) + + out = recipe.get_grain_add_cereal_weight(pale_dme_add, ppg=ppg_pale) self.assertEquals(round(out, 2), 13.96) def test_get_total_grain_weight(self): @@ -258,8 +263,8 @@ def test_color(self): def test_get_total_wort_color_map(self): wort_map = self.recipe.get_total_wort_color_map() expected = { - u'srm': {u'daniels': u'N/A', u'morey': 6.6, u'mosher': 7.3}, - u'ebc': {u'daniels': u'N/A', u'morey': 13.0, u'mosher': 14.4}, + u"srm": {u"daniels": u"N/A", u"morey": 6.6, u"mosher": 7.3}, + u"ebc": {u"daniels": u"N/A", u"morey": 13.0, u"mosher": 14.4}, } self.assertEquals(wort_map, expected) @@ -272,7 +277,8 @@ def test_to_json(self): def test_format(self): self.assertEquals(self.recipe.units, IMPERIAL_UNITS) out = self.recipe.format() - expected = textwrap.dedent(u"""\ + expected = textwrap.dedent( + u"""\ pale ale =================================== @@ -339,7 +345,8 @@ def test_format(self): Wyeast 1056 Yeast ----------------------------------- - Attenuation: 75.0%""") + Attenuation: 75.0%""" + ) self.assertEquals(out, expected) def test_validate(self): @@ -348,7 +355,6 @@ def test_validate(self): class TestRecipeBuilderImperialUnits(unittest.TestCase): - def setUp(self): # Define Grains self.grain_list = grain_list @@ -373,15 +379,16 @@ def test_get_grain_additions_raises_percent_sum_invalid(self): percent_list = [0.90, 0.05] with self.assertRaises(RecipeException) as ctx: self.builder.get_grain_additions(percent_list) - self.assertEquals(str(ctx.exception), - u"Percentages must sum to 1.0") + self.assertEquals(str(ctx.exception), u"Percentages must sum to 1.0") def test_get_grain_additions_raises_percent_length_mismatch(self): percent_list = [0.90, 0.05, 0.05] with self.assertRaises(RecipeException) as ctx: self.builder.get_grain_additions(percent_list) - self.assertEquals(str(ctx.exception), - u"The length of percent_list must equal length of self.grain_list") # noqa + self.assertEquals( + str(ctx.exception), + u"The length of percent_list must equal length of self.grain_list", + ) # noqa def test_get_hop_additions(self): percent_list = [0.8827, 0.1173] @@ -395,24 +402,27 @@ def test_get_hop_additions_raises_percent_sum_invalid(self): boil_time_list = [60.0, 5.0] with self.assertRaises(RecipeException) as ctx: self.builder.get_hop_additions(percent_list, boil_time_list) - self.assertEquals(str(ctx.exception), - u"Percentages must sum to 1.0") + self.assertEquals(str(ctx.exception), u"Percentages must sum to 1.0") def test_get_hop_additions_raises_percent_length_mismatch(self): percent_list = [0.8827, 0.0173, 0.10] boil_time_list = [60.0, 5.0] with self.assertRaises(RecipeException) as ctx: self.builder.get_hop_additions(percent_list, boil_time_list) - self.assertEquals(str(ctx.exception), - u"The length of percent_list must equal length of self.grain_list") # noqa + self.assertEquals( + str(ctx.exception), + u"The length of percent_list must equal length of self.grain_list", + ) # noqa def test_get_hop_additions_raises_boil_time_length_mismatch(self): percent_list = [0.8827, 0.1173] boil_time_list = [60.0, 5.0, 5.0] with self.assertRaises(RecipeException) as ctx: self.builder.get_hop_additions(percent_list, boil_time_list) - self.assertEquals(str(ctx.exception), - u"The length of boil_time_list must equal length of self.hop_list") # noqa + self.assertEquals( + str(ctx.exception), + u"The length of boil_time_list must equal length of self.hop_list", + ) # noqa def test_get_yeast_attenuation(self): abv = 0.0749 diff --git a/tests/test_recipes_si.py b/tests/test_recipes_si.py index 717a50b..4d31e43 100644 --- a/tests/test_recipes_si.py +++ b/tests/test_recipes_si.py @@ -24,15 +24,12 @@ class TestRecipeSIUnits(unittest.TestCase): - def setUp(self): # Define Grains - self.grain_additions = [ga.change_units() for ga in - grain_additions] + self.grain_additions = [ga.change_units() for ga in grain_additions] # Define Hops - self.hop_additions = [ha.change_units() for ha in - hop_additions] + self.hop_additions = [ha.change_units() for ha in hop_additions] # Define Yeast self.yeast = yeast @@ -47,8 +44,12 @@ def test_change_units(self): self.assertEquals(round(self.recipe.final_volume, 2), 18.93) self.assertEquals(round(self.recipe.grain_additions[0].weight, 2), 6.33) # noqa self.assertEquals(round(self.recipe.grain_additions[1].weight, 2), 0.35) # noqa - self.assertEquals(round(self.recipe.hop_additions[0].weight, 2), 16159.21) # noqa - self.assertEquals(round(self.recipe.hop_additions[1].weight, 2), 21545.62) # noqa + self.assertEquals( + round(self.recipe.hop_additions[0].weight, 2), 16159.21 + ) # noqa + self.assertEquals( + round(self.recipe.hop_additions[1].weight, 2), 21545.62 + ) # noqa for grain_add in self.recipe.grain_additions: self.assertEquals(grain_add.units, SI_UNITS) for hop_add in self.recipe.hop_additions: @@ -63,29 +64,31 @@ def test_get_total_points(self): self.assertEquals(round(out, 2), 1441.01) def test_get_total_points_lme(self): - pale_lme_add = GrainAddition(pale_lme, - weight=6.51, - grain_type=GRAIN_TYPE_LME, - units=SI_UNITS) - recipe = Recipe(u'lme', - grain_additions=[pale_lme_add], - hop_additions=self.hop_additions, - yeast=self.yeast, - units=SI_UNITS) + pale_lme_add = GrainAddition( + pale_lme, weight=6.51, grain_type=GRAIN_TYPE_LME, units=SI_UNITS + ) + recipe = Recipe( + u"lme", + grain_additions=[pale_lme_add], + hop_additions=self.hop_additions, + yeast=self.yeast, + units=SI_UNITS, + ) out = recipe.get_total_points() self.assertEquals(round(out, 1), 1955.8) def test_get_total_points_dme(self): - pale_dme_add = GrainAddition(pale_dme, - weight=5.33, - grain_type=GRAIN_TYPE_DME, - units=SI_UNITS) - recipe = Recipe(u'dme', - grain_additions=[pale_dme_add], - hop_additions=self.hop_additions, - yeast=self.yeast, - units=SI_UNITS) + pale_dme_add = GrainAddition( + pale_dme, weight=5.33, grain_type=GRAIN_TYPE_DME, units=SI_UNITS + ) + recipe = Recipe( + u"dme", + grain_additions=[pale_dme_add], + hop_additions=self.hop_additions, + yeast=self.yeast, + units=SI_UNITS, + ) out = recipe.get_total_points() self.assertEquals(round(out, 1), 1957.2) @@ -156,29 +159,31 @@ def test_get_grain_add_dry_weight(self): self.assertEquals(round(out, 2), 0.28) def test_get_grain_add_dry_weight_lme(self): - pale_lme_add = GrainAddition(pale_lme, - weight=6.51, - grain_type=GRAIN_TYPE_LME, - units=SI_UNITS) - recipe = Recipe(u'lme', - grain_additions=[pale_lme_add], - hop_additions=self.hop_additions, - yeast=self.yeast, - units=SI_UNITS) + pale_lme_add = GrainAddition( + pale_lme, weight=6.51, grain_type=GRAIN_TYPE_LME, units=SI_UNITS + ) + recipe = Recipe( + u"lme", + grain_additions=[pale_lme_add], + hop_additions=self.hop_additions, + yeast=self.yeast, + units=SI_UNITS, + ) out = recipe.get_grain_add_dry_weight(pale_lme_add) self.assertEquals(round(out, 2), 5.33) def test_get_grain_add_dry_weight_dme(self): - pale_dme_add = GrainAddition(pale_dme, - weight=5.33, - grain_type=GRAIN_TYPE_DME, - units=SI_UNITS) - recipe = Recipe(u'dme', - grain_additions=[pale_dme_add], - hop_additions=self.hop_additions, - yeast=self.yeast, - units=SI_UNITS) + pale_dme_add = GrainAddition( + pale_dme, weight=5.33, grain_type=GRAIN_TYPE_DME, units=SI_UNITS + ) + recipe = Recipe( + u"dme", + grain_additions=[pale_dme_add], + hop_additions=self.hop_additions, + yeast=self.yeast, + units=SI_UNITS, + ) out = recipe.get_grain_add_dry_weight(pale_dme_add) self.assertEquals(round(out, 2), 5.33) @@ -188,41 +193,43 @@ def test_get_total_dry_weight(self): self.assertEquals(round(out, 2), 5.61) def test_get_grain_add_cereal_weight(self): - out = self.recipe.get_grain_add_cereal_weight(self.grain_additions[0], - ppg=ppg_pale) + out = self.recipe.get_grain_add_cereal_weight( + self.grain_additions[0], ppg=ppg_pale + ) self.assertEquals(round(out, 2), 6.33) - out = self.recipe.get_grain_add_cereal_weight(self.grain_additions[1], - ppg=ppg_crystal) + out = self.recipe.get_grain_add_cereal_weight( + self.grain_additions[1], ppg=ppg_crystal + ) self.assertEquals(round(out, 2), 0.35) def test_get_grain_add_cereal_weight_lme(self): - pale_lme_add = GrainAddition(pale_lme, - weight=6.51, - grain_type=GRAIN_TYPE_LME, - units=SI_UNITS) - recipe = Recipe(u'lme', - grain_additions=[pale_lme_add], - hop_additions=self.hop_additions, - yeast=self.yeast, - units=SI_UNITS) - - out = recipe.get_grain_add_cereal_weight(pale_lme_add, - ppg=ppg_pale) + pale_lme_add = GrainAddition( + pale_lme, weight=6.51, grain_type=GRAIN_TYPE_LME, units=SI_UNITS + ) + recipe = Recipe( + u"lme", + grain_additions=[pale_lme_add], + hop_additions=self.hop_additions, + yeast=self.yeast, + units=SI_UNITS, + ) + + out = recipe.get_grain_add_cereal_weight(pale_lme_add, ppg=ppg_pale) self.assertEquals(round(out, 2), 6.33) def test_get_grain_add_cereal_weight_dme(self): - pale_dme_add = GrainAddition(pale_dme, - weight=5.33, - grain_type=GRAIN_TYPE_DME, - units=SI_UNITS) - recipe = Recipe(u'dme', - grain_additions=[pale_dme_add], - hop_additions=self.hop_additions, - yeast=self.yeast, - units=SI_UNITS) - - out = recipe.get_grain_add_cereal_weight(pale_dme_add, - ppg=ppg_pale) + pale_dme_add = GrainAddition( + pale_dme, weight=5.33, grain_type=GRAIN_TYPE_DME, units=SI_UNITS + ) + recipe = Recipe( + u"dme", + grain_additions=[pale_dme_add], + hop_additions=self.hop_additions, + yeast=self.yeast, + units=SI_UNITS, + ) + + out = recipe.get_grain_add_cereal_weight(pale_dme_add, ppg=ppg_pale) self.assertEquals(round(out, 2), 6.34) def test_get_total_grain_weight(self): @@ -269,8 +276,8 @@ def test_color(self): def test_get_total_wort_color_map(self): wort_map = self.recipe.get_total_wort_color_map() expected = { - u'srm': {u'daniels': u'N/A', u'morey': 6.6, u'mosher': 7.3}, - u'ebc': {u'daniels': u'N/A', u'morey': 13.0, u'mosher': 14.4}, + u"srm": {u"daniels": u"N/A", u"morey": 6.6, u"mosher": 7.3}, + u"ebc": {u"daniels": u"N/A", u"morey": 13.0, u"mosher": 14.4}, } self.assertEquals(wort_map, expected) @@ -283,7 +290,8 @@ def test_to_json(self): def test_format(self): self.assertEquals(self.recipe.units, SI_UNITS) out = self.recipe.format() - expected = textwrap.dedent(u"""\ + expected = textwrap.dedent( + u"""\ pale ale =================================== @@ -350,7 +358,8 @@ def test_format(self): Wyeast 1056 Yeast ----------------------------------- - Attenuation: 75.0%""") + Attenuation: 75.0%""" + ) self.assertEquals(out, expected) def test_validate(self): @@ -359,7 +368,6 @@ def test_validate(self): class TestRecipeBuilderSIUnits(unittest.TestCase): - def setUp(self): # Define Grains self.grain_list = grain_list @@ -384,15 +392,16 @@ def test_get_grain_additions_raises_percent_sum_invalid(self): percent_list = [0.90, 0.05] with self.assertRaises(RecipeException) as ctx: self.builder.get_grain_additions(percent_list) - self.assertEquals(str(ctx.exception), - u"Percentages must sum to 1.0") + self.assertEquals(str(ctx.exception), u"Percentages must sum to 1.0") def test_get_grain_additions_raises_percent_length_mismatch(self): percent_list = [0.90, 0.05, 0.05] with self.assertRaises(RecipeException) as ctx: self.builder.get_grain_additions(percent_list) - self.assertEquals(str(ctx.exception), - u"The length of percent_list must equal length of self.grain_list") # noqa + self.assertEquals( + str(ctx.exception), + u"The length of percent_list must equal length of self.grain_list", + ) # noqa def test_get_hop_additions(self): percent_list = [0.8827, 0.1173] @@ -406,24 +415,27 @@ def test_get_hop_additions_raises_percent_sum_invalid(self): boil_time_list = [60.0, 5.0] with self.assertRaises(RecipeException) as ctx: self.builder.get_hop_additions(percent_list, boil_time_list) - self.assertEquals(str(ctx.exception), - u"Percentages must sum to 1.0") + self.assertEquals(str(ctx.exception), u"Percentages must sum to 1.0") def test_get_hop_additions_raises_percent_length_mismatch(self): percent_list = [0.8827, 0.0173, 0.10] boil_time_list = [60.0, 5.0] with self.assertRaises(RecipeException) as ctx: self.builder.get_hop_additions(percent_list, boil_time_list) - self.assertEquals(str(ctx.exception), - u"The length of percent_list must equal length of self.grain_list") # noqa + self.assertEquals( + str(ctx.exception), + u"The length of percent_list must equal length of self.grain_list", + ) # noqa def test_get_hop_additions_raises_boil_time_length_mismatch(self): percent_list = [0.8827, 0.1173] boil_time_list = [60.0, 5.0, 5.0] with self.assertRaises(RecipeException) as ctx: self.builder.get_hop_additions(percent_list, boil_time_list) - self.assertEquals(str(ctx.exception), - u"The length of boil_time_list must equal length of self.hop_list") # noqa + self.assertEquals( + str(ctx.exception), + u"The length of boil_time_list must equal length of self.hop_list", + ) # noqa def test_get_yeast_attenuation(self): abv = 0.0749 diff --git a/tests/test_styles.py b/tests/test_styles.py index 1f3599e..6680351 100644 --- a/tests/test_styles.py +++ b/tests/test_styles.py @@ -16,69 +16,70 @@ class TestStyle(unittest.TestCase): - def setUp(self): # Define Style self.style = american_pale_ale_style def test_validate_input_list_empty(self): with self.assertRaises(StyleException) as ctx: - Style._validate_input_list(None, (int, float), u'OG') - self.assertEquals(str(ctx.exception), - u"Must provide value_list for OG") + Style._validate_input_list(None, (int, float), u"OG") + self.assertEquals(str(ctx.exception), u"Must provide value_list for OG") def test_validate_input_list_type(self): with self.assertRaises(StyleException) as ctx: - Style._validate_input_list({u'a': u'b'}, (int, float), u'OG') - self.assertEquals(str(ctx.exception), - u"OG must be a list") + Style._validate_input_list({u"a": u"b"}, (int, float), u"OG") + self.assertEquals(str(ctx.exception), u"OG must be a list") def test_validate_input_list_length_short(self): with self.assertRaises(StyleException) as ctx: - Style._validate_input_list([1], (int, float), u'OG') - self.assertEquals(str(ctx.exception), - u"OG must contain two values") + Style._validate_input_list([1], (int, float), u"OG") + self.assertEquals(str(ctx.exception), u"OG must contain two values") def test_validate_input_list_length_long(self): with self.assertRaises(StyleException) as ctx: - Style._validate_input_list([1, 2, 3], (int, float), u'OG') - self.assertEquals(str(ctx.exception), - u"OG must contain two values") + Style._validate_input_list([1, 2, 3], (int, float), u"OG") + self.assertEquals(str(ctx.exception), u"OG must contain two values") def test_validate_input_list_wrong_type(self): with self.assertRaises(StyleException) as ctx: # noqa - Style._validate_input_list([1, u'2'], (int, float), u'OG') + Style._validate_input_list([1, u"2"], (int, float), u"OG") # self.assertEquals(str(ctx.exception), # u"OG must be type '(, )'") # noqa def test_validate_input_list_bad_order(self): with self.assertRaises(StyleException) as ctx: - Style._validate_input_list([2, 1], (int, float), u'OG') - self.assertEquals(str(ctx.exception), - u"OG values must be lowest value first") # noqa + Style._validate_input_list([2, 1], (int, float), u"OG") + self.assertEquals( + str(ctx.exception), u"OG values must be lowest value first" + ) # noqa def test_str(self): out = str(self.style) - self.assertEquals(out, u'18B American Pale Ale') + self.assertEquals(out, u"18B American Pale Ale") def test_unicode(self): - style = Style(u'Kölsh', - category=u'5', - subcategory=u'B', - og=[1.044, 1.050], - fg=[1.007, 1.011], - abv=[0.044, 0.052], - ibu=[18, 30], - color=[3.5, 5]) + style = Style( + u"Kölsh", + category=u"5", + subcategory=u"B", + og=[1.044, 1.050], + fg=[1.007, 1.011], + abv=[0.044, 0.052], + ibu=[18, 30], + color=[3.5, 5], + ) out = str(style) if sys.version_info[0] >= 3: - self.assertEquals(out, u'5B Kölsh') + self.assertEquals(out, u"5B Kölsh") else: - self.assertEquals(out, u'5B Kölsh'.encode('utf8')) + self.assertEquals(out, u"5B Kölsh".encode("utf8")) def test_repr(self): out = repr(self.style) - self.assertEquals(out, u"Style('American Pale Ale', category='18', subcategory='B', og=[1.045, 1.06], fg=[1.01, 1.015], abv=[0.045, 0.062], ibu=[30, 50], color=[5, 10])") # noqa + self.assertEquals( + out, + u"Style('American Pale Ale', category='18', subcategory='B', og=[1.045, 1.06], fg=[1.01, 1.015], abv=[0.045, 0.062], ibu=[30, 50], color=[5, 10])", + ) # noqa def test_eq(self): style1 = self.style @@ -86,91 +87,107 @@ def test_eq(self): self.assertEquals(style1, style2) def test_ne_style(self): - style2 = Style(u'English Pale Ale', - category=u'18', - subcategory=u'B', - og=[1.045, 1.06], - fg=[1.010, 1.015], - abv=[0.045, 0.062], - ibu=[30, 50], - color=[5, 10]) + style2 = Style( + u"English Pale Ale", + category=u"18", + subcategory=u"B", + og=[1.045, 1.06], + fg=[1.010, 1.015], + abv=[0.045, 0.062], + ibu=[30, 50], + color=[5, 10], + ) self.assertTrue(self.style != style2) def test_ne_category(self): - style2 = Style(u'American Pale Ale', - category=u'11', - subcategory=u'B', - og=[1.045, 1.06], - fg=[1.010, 1.015], - abv=[0.045, 0.062], - ibu=[30, 50], - color=[5, 10]) + style2 = Style( + u"American Pale Ale", + category=u"11", + subcategory=u"B", + og=[1.045, 1.06], + fg=[1.010, 1.015], + abv=[0.045, 0.062], + ibu=[30, 50], + color=[5, 10], + ) self.assertTrue(self.style != style2) def test_ne_subcategory(self): - style2 = Style(u'American Pale Ale', - category=u'18', - subcategory=u'A', - og=[1.045, 1.06], - fg=[1.010, 1.015], - abv=[0.045, 0.062], - ibu=[30, 50], - color=[5, 10]) + style2 = Style( + u"American Pale Ale", + category=u"18", + subcategory=u"A", + og=[1.045, 1.06], + fg=[1.010, 1.015], + abv=[0.045, 0.062], + ibu=[30, 50], + color=[5, 10], + ) self.assertTrue(self.style != style2) def test_ne_og(self): - style2 = Style(u'American Pale Ale', - category=u'18', - subcategory=u'B', - og=[1.045, 1.061], - fg=[1.010, 1.015], - abv=[0.045, 0.062], - ibu=[30, 50], - color=[5, 10]) + style2 = Style( + u"American Pale Ale", + category=u"18", + subcategory=u"B", + og=[1.045, 1.061], + fg=[1.010, 1.015], + abv=[0.045, 0.062], + ibu=[30, 50], + color=[5, 10], + ) self.assertTrue(self.style != style2) def test_ne_fg(self): - style2 = Style(u'American Pale Ale', - category=u'18', - subcategory=u'B', - og=[1.045, 1.06], - fg=[1.010, 1.016], - abv=[0.045, 0.062], - ibu=[30, 50], - color=[5, 10]) + style2 = Style( + u"American Pale Ale", + category=u"18", + subcategory=u"B", + og=[1.045, 1.06], + fg=[1.010, 1.016], + abv=[0.045, 0.062], + ibu=[30, 50], + color=[5, 10], + ) self.assertTrue(self.style != style2) def test_ne_abv(self): - style2 = Style(u'American Pale Ale', - category=u'18', - subcategory=u'B', - og=[1.045, 1.06], - fg=[1.010, 1.015], - abv=[4.5, 6.3], - ibu=[30, 50], - color=[5, 10]) + style2 = Style( + u"American Pale Ale", + category=u"18", + subcategory=u"B", + og=[1.045, 1.06], + fg=[1.010, 1.015], + abv=[4.5, 6.3], + ibu=[30, 50], + color=[5, 10], + ) self.assertTrue(self.style != style2) def test_ne_ibu(self): - style2 = Style(u'American Pale Ale', - category=u'18', - subcategory=u'B', - og=[1.045, 1.06], - fg=[1.010, 1.015], - abv=[0.045, 0.062], - ibu=[30, 51], - color=[5, 10]) + style2 = Style( + u"American Pale Ale", + category=u"18", + subcategory=u"B", + og=[1.045, 1.06], + fg=[1.010, 1.015], + abv=[0.045, 0.062], + ibu=[30, 51], + color=[5, 10], + ) self.assertTrue(self.style != style2) def test_ne_color(self): - style2 = Style(u'American Pale Ale', - category=u'18', - subcategory=u'B', - og=[1.045, 1.06], - fg=[1.010, 1.015], - abv=[0.045, 0.062], - ibu=[30, 50], - color=[5, 11]) + style2 = Style( + u"American Pale Ale", + category=u"18", + subcategory=u"B", + og=[1.045, 1.06], + fg=[1.010, 1.015], + abv=[0.045, 0.062], + ibu=[30, 50], + color=[5, 11], + ) self.assertTrue(self.style != style2) def test_ne_style_class(self): @@ -182,11 +199,11 @@ def test_og_matches(self): def test_og_matches_low(self): out = self.style.og_errors(1.044) - self.assertEquals(out, [u'OG is below style']) + self.assertEquals(out, [u"OG is below style"]) def test_og_matches_high(self): out = self.style.og_errors(1.061) - self.assertEquals(out, [u'OG is above style']) + self.assertEquals(out, [u"OG is above style"]) def test_fg_matches(self): out = self.style.fg_matches(1.012) @@ -194,11 +211,11 @@ def test_fg_matches(self): def test_fg_matches_low(self): out = self.style.fg_errors(1.009) - self.assertEquals(out, [u'FG is below style']) + self.assertEquals(out, [u"FG is below style"]) def test_fg_matches_high(self): out = self.style.fg_errors(1.016) - self.assertEquals(out, [u'FG is above style']) + self.assertEquals(out, [u"FG is above style"]) def test_abv_matches(self): out = self.style.abv_matches(0.050) @@ -206,11 +223,11 @@ def test_abv_matches(self): def test_abv_matches_low(self): out = self.style.abv_errors(0.044) - self.assertEquals(out, [u'ABV is below style']) + self.assertEquals(out, [u"ABV is below style"]) def test_abv_matches_high(self): out = self.style.abv_errors(0.063) - self.assertEquals(out, [u'ABV is above style']) + self.assertEquals(out, [u"ABV is above style"]) def test_ibu_matches(self): out = self.style.ibu_matches(33.0) @@ -218,11 +235,11 @@ def test_ibu_matches(self): def test_ibu_matches_low(self): out = self.style.ibu_errors(29) - self.assertEquals(out, [u'IBU is below style']) + self.assertEquals(out, [u"IBU is below style"]) def test_ibu_matches_high(self): out = self.style.ibu_errors(51) - self.assertEquals(out, [u'IBU is above style']) + self.assertEquals(out, [u"IBU is above style"]) def test_color_matches(self): out = self.style.color_matches(7.5) @@ -230,28 +247,24 @@ def test_color_matches(self): def test_color_matches_low(self): out = self.style.color_errors(4) - self.assertEquals(out, [u'Color is below style']) + self.assertEquals(out, [u"Color is below style"]) def test_color_matches_high(self): out = self.style.color_errors(11) - self.assertEquals(out, [u'Color is above style']) + self.assertEquals(out, [u"Color is above style"]) def test_recipe_matches(self): - pale_add = GrainAddition(pale, - weight=8.69) - crystal_add = GrainAddition(crystal, - weight=1.02) - pale_ale = Recipe(name=u'pale ale', - grain_additions=[ - pale_add, - crystal_add, - ], - hop_additions=hop_additions, - yeast=yeast, - brew_house_yield=0.70, - start_volume=7.0, - final_volume=5.0, - ) + pale_add = GrainAddition(pale, weight=8.69) + crystal_add = GrainAddition(crystal, weight=1.02) + pale_ale = Recipe( + name=u"pale ale", + grain_additions=[pale_add, crystal_add], + hop_additions=hop_additions, + yeast=yeast, + brew_house_yield=0.70, + start_volume=7.0, + final_volume=5.0, + ) out = self.style.recipe_matches(pale_ale) self.assertTrue(out) @@ -261,27 +274,21 @@ def test_recipe_matches_false(self): def test_recipe_errors(self): out = self.style.recipe_errors(recipe) - expected = [u'OG is above style', - u'FG is above style', - u'ABV is above style'] + expected = [u"OG is above style", u"FG is above style", u"ABV is above style"] self.assertEquals(out, expected) def test_recipe_errors_none(self): - pale_add = GrainAddition(pale, - weight=8.69) - crystal_add = GrainAddition(crystal, - weight=1.02) - pale_ale = Recipe(name=u'pale ale', - grain_additions=[ - pale_add, - crystal_add, - ], - hop_additions=hop_additions, - yeast=yeast, - brew_house_yield=0.70, - start_volume=7.0, - final_volume=5.0, - ) + pale_add = GrainAddition(pale, weight=8.69) + crystal_add = GrainAddition(crystal, weight=1.02) + pale_ale = Recipe( + name=u"pale ale", + grain_additions=[pale_add, crystal_add], + hop_additions=hop_additions, + yeast=yeast, + brew_house_yield=0.70, + start_volume=7.0, + final_volume=5.0, + ) out = self.style.recipe_errors(pale_ale) expected = [] self.assertEquals(out, expected) @@ -293,7 +300,8 @@ def test_to_json(self): def test_format(self): out = self.style.format() - expected = textwrap.dedent(u"""\ + expected = textwrap.dedent( + u"""\ 18B American Pale Ale =================================== @@ -302,7 +310,8 @@ def test_format(self): ABV: 4.50% - 6.20% IBU: 30.0 - 50.0 Color (SRM): 5.0 - 10.0 - """) + """ + ) self.assertEquals(out, expected) def test_validate(self): diff --git a/tests/test_utilities_abv.py b/tests/test_utilities_abv.py index aad097a..28e4641 100644 --- a/tests/test_utilities_abv.py +++ b/tests/test_utilities_abv.py @@ -13,7 +13,6 @@ class TestABVUtilities(unittest.TestCase): - def test_apparent_attenuation(self): oe = sg_to_plato(1.060) ae = sg_to_plato(1.010) diff --git a/tests/test_utilities_color.py b/tests/test_utilities_color.py index f15cc35..d1f8b73 100644 --- a/tests/test_utilities_color.py +++ b/tests/test_utilities_color.py @@ -22,7 +22,6 @@ class TestColorUtilities(unittest.TestCase): - def test_srm_to_ebc(self): ebc = srm_to_ebc(3.0) self.assertEquals(round(ebc, 2), 5.91) diff --git a/tests/test_utilities_efficiency.py b/tests/test_utilities_efficiency.py index 741ca6b..bd3169b 100644 --- a/tests/test_utilities_efficiency.py +++ b/tests/test_utilities_efficiency.py @@ -6,12 +6,11 @@ class TestEfficiencyUtilities(unittest.TestCase): - def setUp(self): self.recipe = recipe def test_calculate_brew_house_yield(self): - out = calculate_brew_house_yield(recipe.final_volume, - recipe.og, - recipe.grain_additions) + out = calculate_brew_house_yield( + recipe.final_volume, recipe.og, recipe.grain_additions + ) self.assertEquals(round(out, 3), self.recipe.brew_house_yield) diff --git a/tests/test_utilities_hops.py b/tests/test_utilities_hops.py index d31a9c3..ba8961f 100644 --- a/tests/test_utilities_hops.py +++ b/tests/test_utilities_hops.py @@ -19,7 +19,6 @@ class TestHopUtilities(unittest.TestCase): - def test_hope_type_weight_conversion_same_type(self): weight = 1.0 old_type = HOP_TYPE_PELLET @@ -86,26 +85,22 @@ def test_hope_type_weight_conversion_whole_wet_to_pellet(self): class TestHopsUtilization(unittest.TestCase): - def setUp(self): self.utilization_cls = HopsUtilization self.hop = centennial - self.addition_kwargs = [ - { - u'boil_time': 60.0, - u'weight': 0.57, - } - ] + self.addition_kwargs = [{u"boil_time": 60.0, u"weight": 0.57}] # Additions self.plato = 14.0 self.sg = plato_to_sg(self.plato) self.final_volume = 5.0 self.boil_time = 60.0 - self.hop_addition = HopAddition(self.hop, - boil_time=self.boil_time, - weight=0.57, - utilization_cls=self.utilization_cls) + self.hop_addition = HopAddition( + self.hop, + boil_time=self.boil_time, + weight=0.57, + utilization_cls=self.utilization_cls, + ) def test_get_ibus_raises(self): with self.assertRaises(NotImplementedError): @@ -114,11 +109,11 @@ def test_get_ibus_raises(self): def test_get_percent_utilization_raises(self): with self.assertRaises(NotImplementedError): self.hop_addition.utilization_cls.get_percent_utilization( - self.sg, self.final_volume) + self.sg, self.final_volume + ) def test_change_units(self): - self.assertEquals(self.hop_addition.utilization_cls.units, - IMPERIAL_UNITS) + self.assertEquals(self.hop_addition.utilization_cls.units, IMPERIAL_UNITS) util = self.hop_addition.utilization_cls.change_units() self.assertEquals(util.units, SI_UNITS) util = util.change_units() @@ -126,30 +121,25 @@ def test_change_units(self): class TestHopsUtilizationJackieRager(unittest.TestCase): - def setUp(self): self.utilization_cls = HopsUtilizationJackieRager self.hop = centennial - self.addition_kwargs = [ - { - u'boil_time': 60.0, - u'weight': 0.57, - } - ] + self.addition_kwargs = [{u"boil_time": 60.0, u"weight": 0.57}] # Additions self.plato = 14.0 self.sg = plato_to_sg(self.plato) self.final_volume = 5.0 self.boil_time = 60.0 - self.hop_addition = HopAddition(self.hop, - boil_time=self.boil_time, - weight=0.57, - utilization_cls=self.utilization_cls) + self.hop_addition = HopAddition( + self.hop, + boil_time=self.boil_time, + weight=0.57, + utilization_cls=self.utilization_cls, + ) def test_str(self): - self.assertEquals(str(self.hop_addition.utilization_cls), - u"Jackie Rager") + self.assertEquals(str(self.hop_addition.utilization_cls), u"Jackie Rager") def test_get_c_gravity(self): out = self.hop_addition.utilization_cls.get_c_gravity(self.sg) @@ -160,41 +150,40 @@ def test_get_c_gravity(self): self.assertEquals(round(out, 3), 1.000) def test_get_ibus(self): - ibu = self.hop_addition.get_ibus(self.sg, - self.final_volume) + ibu = self.hop_addition.get_ibus(self.sg, self.final_volume) self.assertEquals(round(ibu, 2), 39.18) def test_get_ibus_whole_wet(self): # Whole Dry Weight is HOP_UTILIZATION_SCALE_PELLET times more than pellet weight # Whole Wet Weight is HOP_WHOLE_DRY_TO_WET times more than dry weight weight = 0.57 * HOP_UTILIZATION_SCALE_PELLET * HOP_WHOLE_DRY_TO_WET - hop_addition = HopAddition(self.hop, - boil_time=self.boil_time, - weight=weight, - hop_type=HOP_TYPE_WHOLE_WET, - utilization_cls=self.utilization_cls) - ibu = hop_addition.get_ibus(self.sg, - self.final_volume) + hop_addition = HopAddition( + self.hop, + boil_time=self.boil_time, + weight=weight, + hop_type=HOP_TYPE_WHOLE_WET, + utilization_cls=self.utilization_cls, + ) + ibu = hop_addition.get_ibus(self.sg, self.final_volume) self.assertEquals(round(ibu, 2), 39.18) def test_get_percent_utilization(self): utilization = self.hop_addition.utilization_cls.get_percent_utilization( # noqa - self.sg, self.boil_time) + self.sg, self.boil_time + ) self.assertEquals(round(utilization * 100, 2), 29.80) def test_get_utilization_table(self): gravity_list = list(range(1030, 1140, 10)) boil_time_list = list(range(0, 60, 3)) + list(range(60, 130, 10)) - table = self.utilization_cls.get_utilization_table( - gravity_list, - boil_time_list) + table = self.utilization_cls.get_utilization_table(gravity_list, boil_time_list) self.assertEquals(table[0][0], 0.051) self.assertEquals(table[13][5], 0.205) self.assertEquals(table[26][10], 0.228) def test_format_utilization_table(self): out = self.utilization_cls.format_utilization_table() - expected = (u"""\ + expected = u"""\ Percent Alpha Acid Utilization - Boil Time vs Wort Original Gravity =================================================================== 1.030 1.040 1.050 1.060 1.070 1.080 1.090 1.100 1.110 1.120 1.130 @@ -225,39 +214,33 @@ def test_format_utilization_table(self): 90 0.319 0.319 0.319 0.304 0.290 0.278 0.266 0.255 0.246 0.236 0.228 100 0.320 0.320 0.320 0.304 0.290 0.278 0.266 0.256 0.246 0.237 0.228 110 0.320 0.320 0.320 0.304 0.291 0.278 0.266 0.256 0.246 0.237 0.228 - 120 0.320 0.320 0.320 0.304 0.291 0.278 0.266 0.256 0.246 0.237 0.228""") # noqa + 120 0.320 0.320 0.320 0.304 0.291 0.278 0.266 0.256 0.246 0.237 0.228""" # noqa self.assertEquals(out, expected) class TestHopsUtilizationGlennTinseth(unittest.TestCase): - def setUp(self): self.utilization_cls = HopsUtilizationGlennTinseth self.hop = centennial - self.addition_kwargs = [ - { - u'boil_time': 60.0, - u'weight': 0.57, - } - ] + self.addition_kwargs = [{u"boil_time": 60.0, u"weight": 0.57}] # Additions self.plato = 14.0 self.sg = plato_to_sg(self.plato) self.final_volume = 5.0 self.boil_time = 60.0 - self.hop_addition = HopAddition(self.hop, - boil_time=self.boil_time, - weight=0.57, - utilization_cls=self.utilization_cls) + self.hop_addition = HopAddition( + self.hop, + boil_time=self.boil_time, + weight=0.57, + utilization_cls=self.utilization_cls, + ) def test_str(self): - self.assertEquals(str(self.hop_addition.utilization_cls), - u"Glenn Tinseth") + self.assertEquals(str(self.hop_addition.utilization_cls), u"Glenn Tinseth") def test_get_ibus(self): - ibu = self.hop_addition.get_ibus(self.sg, - self.final_volume) + ibu = self.hop_addition.get_ibus(self.sg, self.final_volume) self.assertEquals(round(ibu, 2), 28.52) def test_get_ibus_whole_wet(self): @@ -266,13 +249,14 @@ def test_get_ibus_whole_wet(self): Whole Wet Weight is HOP_WHOLE_DRY_TO_WET times more than dry weight """ # noqa weight = 0.57 * HOP_UTILIZATION_SCALE_PELLET * HOP_WHOLE_DRY_TO_WET - hop_addition = HopAddition(self.hop, - boil_time=self.boil_time, - weight=weight, - hop_type=HOP_TYPE_WHOLE_WET, - utilization_cls=self.utilization_cls) - ibu = hop_addition.get_ibus(self.sg, - self.final_volume) + hop_addition = HopAddition( + self.hop, + boil_time=self.boil_time, + weight=weight, + hop_type=HOP_TYPE_WHOLE_WET, + utilization_cls=self.utilization_cls, + ) + ibu = hop_addition.get_ibus(self.sg, self.final_volume) self.assertEquals(round(ibu, 2), 28.52) def test_get_bigness_factor(self): @@ -280,11 +264,11 @@ def test_get_bigness_factor(self): self.assertEquals(round(bf, 2), 0.99) def test_get_boil_time_factor(self): - bf = self.hop_addition.utilization_cls.get_boil_time_factor( - self.boil_time) + bf = self.hop_addition.utilization_cls.get_boil_time_factor(self.boil_time) self.assertEquals(round(bf, 2), 0.22) def test_get_percent_utilization(self): utilization = self.hop_addition.utilization_cls.get_percent_utilization( # noqa - self.sg, self.boil_time) + self.sg, self.boil_time + ) self.assertEquals(round(utilization * 100, 2), 21.69) diff --git a/tests/test_utilities_malt.py b/tests/test_utilities_malt.py index bca664b..c238a6c 100644 --- a/tests/test_utilities_malt.py +++ b/tests/test_utilities_malt.py @@ -22,7 +22,6 @@ class TestMaltUtilities(unittest.TestCase): - def test_dry_to_liquid_malt_weight(self): out = dry_to_liquid_malt_weight(5.0) self.assertEquals(out, 6.25) diff --git a/tests/test_utilities_sugar.py b/tests/test_utilities_sugar.py index be925aa..2aeaea1 100644 --- a/tests/test_utilities_sugar.py +++ b/tests/test_utilities_sugar.py @@ -18,7 +18,6 @@ class TestSugarUtilities(unittest.TestCase): - def test_brix_to_plato(self): plato = brix_to_plato(22.0) self.assertEquals(round(plato, 3), 22.001) @@ -46,8 +45,9 @@ def test_sg_to_brix(self): def test_sg_to_brix_raises(self): with self.assertRaises(SugarException) as ctx: sg_to_brix(1.18) - self.assertEquals(str(ctx.exception), - u"Above 40 degBx this function no longer works") + self.assertEquals( + str(ctx.exception), u"Above 40 degBx this function no longer works" + ) def test_sg_to_plato(self): plato = sg_to_plato(1.057) @@ -77,30 +77,35 @@ def test_hydromter_adjustment_si_units(self): def test_hydrometer_adjustment_raises_bad_units(self): with self.assertRaises(ValidatorException) as ctx: - hydrometer_adjustment(1.050, 16.0, units=u'bad') - self.assertEquals(str(ctx.exception), - u"Unkown units 'bad', must use imperial or metric") + hydrometer_adjustment(1.050, 16.0, units=u"bad") + self.assertEquals( + str(ctx.exception), u"Unkown units 'bad', must use imperial or metric" + ) def test_hydrometer_adjustment_raises_bad_temp(self): with self.assertRaises(SugarException) as ctx: hydrometer_adjustment(1.050, -1.0) - self.assertEquals(str(ctx.exception), - u"Correction does not work outside temps 0 - 212F") + self.assertEquals( + str(ctx.exception), u"Correction does not work outside temps 0 - 212F" + ) with self.assertRaises(SugarException) as ctx: hydrometer_adjustment(1.050, 213.0) - self.assertEquals(str(ctx.exception), - u"Correction does not work outside temps 0 - 212F") + self.assertEquals( + str(ctx.exception), u"Correction does not work outside temps 0 - 212F" + ) with self.assertRaises(SugarException) as ctx: hydrometer_adjustment(1.050, -1.0, units=SI_UNITS) - self.assertEquals(str(ctx.exception), - u"Correction does not work outside temps 0 - 100C") + self.assertEquals( + str(ctx.exception), u"Correction does not work outside temps 0 - 100C" + ) with self.assertRaises(SugarException) as ctx: hydrometer_adjustment(1.050, 101.0, units=SI_UNITS) - self.assertEquals(str(ctx.exception), - u"Correction does not work outside temps 0 - 100C") + self.assertEquals( + str(ctx.exception), u"Correction does not work outside temps 0 - 100C" + ) def test_refractometer_adjustment(self): fg = refractometer_adjustment(1.053, 1.032) diff --git a/tests/test_utilities_temperature.py b/tests/test_utilities_temperature.py index d6c3117..25256c8 100644 --- a/tests/test_utilities_temperature.py +++ b/tests/test_utilities_temperature.py @@ -9,7 +9,6 @@ class TestTemperatureUtilities(unittest.TestCase): - def test_celsius_to_fahrenheit(self): ftemp = celsius_to_fahrenheit(100.0) self.assertEquals(ftemp, 212.0) @@ -27,7 +26,7 @@ def test_fahrenheit_to_celsius(self): self.assertEquals(ctemp, -40.0) def test_strike_temp(self): - temp = strike_temp(104.0, 70.0, 1.0 / 1.0, ) + temp = strike_temp(104.0, 70.0, 1.0 / 1.0) self.assertEquals(round(temp, 2), 110.8) def test_mash_infusion(self): diff --git a/tests/test_utilities_yeast.py b/tests/test_utilities_yeast.py index 0ca034f..24c144a 100644 --- a/tests/test_utilities_yeast.py +++ b/tests/test_utilities_yeast.py @@ -11,7 +11,6 @@ class TestYeastUtilities(unittest.TestCase): - def test_pitch_rate_conversion_si(self): out = pitch_rate_conversion(0.75, units=SI_UNITS) self.assertEquals(round(out, 2), 0.73) @@ -30,15 +29,16 @@ def test_pitch_rate_conversion_imperial(self): class TestYeastModel(unittest.TestCase): - def setUp(self): - self.yeast_model = YeastModel(u'stir plate') + self.yeast_model = YeastModel(u"stir plate") def test_yeast_model_raises(self): with self.assertRaises(YeastException) as ctx: - YeastModel(u'not an allowed method') - self.assertEquals(str(ctx.exception), - u"Method 'not an allowed method' not allowed for yeast model") # noqa + YeastModel(u"not an allowed method") + self.assertEquals( + str(ctx.exception), + u"Method 'not an allowed method' not allowed for yeast model", + ) # noqa def test_get_growth_rate(self): inoculation_rate = 6.17 @@ -52,7 +52,6 @@ def test_get_inoculation_rate(self): class TestKaiserYeastModel(unittest.TestCase): - def setUp(self): self.yeast_model = KaiserYeastModel() @@ -77,7 +76,6 @@ def test_get_inoculation_rate(self): class TestWhiteYeastModel(unittest.TestCase): - def setUp(self): self.yeast_model_cls = WhiteYeastModel self.yeast_model = self.yeast_model_cls() @@ -102,130 +100,134 @@ def test_get_viability(self): def test_get_yeast_pitch_rate(self): out = self.yeast_model.get_yeast_pitch_rate() - expected = {u'original_gravity': 1.050, - u'final_volume': 5.0, - u'viability': 0.79, - u'cells': 79.0, - u'target_pitch_rate': 1.42, - u'pitch_rate_as_is': 0.32, - u'pitch_rate_cells': 355.0, - u'cells_needed': 276.0, - u'required_growth_rate': 4.49, - u'units': 'imperial', - } + expected = { + u"original_gravity": 1.050, + u"final_volume": 5.0, + u"viability": 0.79, + u"cells": 79.0, + u"target_pitch_rate": 1.42, + u"pitch_rate_as_is": 0.32, + u"pitch_rate_cells": 355.0, + u"cells_needed": 276.0, + u"required_growth_rate": 4.49, + u"units": "imperial", + } self.assertEquals(out, expected) def test_get_yeast_pitch_rate_two_packs(self): out = self.yeast_model.get_yeast_pitch_rate(num_packs=2) - expected = {u'original_gravity': 1.05, - u'final_volume': 5.0, - u'viability': 0.79, - u'cells': 158.0, - u'target_pitch_rate': 1.42, - u'pitch_rate_as_is': 0.63, - u'pitch_rate_cells': 355.0, - u'cells_needed': 197.0, - u'required_growth_rate': 2.25, - u'units': 'imperial', - } + expected = { + u"original_gravity": 1.05, + u"final_volume": 5.0, + u"viability": 0.79, + u"cells": 158.0, + u"target_pitch_rate": 1.42, + u"pitch_rate_as_is": 0.63, + u"pitch_rate_cells": 355.0, + u"cells_needed": 197.0, + u"required_growth_rate": 2.25, + u"units": "imperial", + } self.assertEquals(out, expected) def test_get_yeast_pitch_rate_cells_le_zero(self): out = self.yeast_model.get_yeast_pitch_rate(days_since_manufacture=365) - expected = {u'original_gravity': 1.050, - u'final_volume': 5.0, - u'viability': 0.0, - u'cells': 0.0, - u'target_pitch_rate': 1.42, - u'pitch_rate_as_is': 0.0, - u'pitch_rate_cells': 355.0, - u'cells_needed': 355.0, - u'required_growth_rate': 0.0, - u'units': 'imperial', - } + expected = { + u"original_gravity": 1.050, + u"final_volume": 5.0, + u"viability": 0.0, + u"cells": 0.0, + u"target_pitch_rate": 1.42, + u"pitch_rate_as_is": 0.0, + u"pitch_rate_cells": 355.0, + u"cells_needed": 355.0, + u"required_growth_rate": 0.0, + u"units": "imperial", + } self.assertEquals(out, expected) def test_get_yeast_pitch_rate_metric(self): self.yeast_model.set_units(SI_UNITS) out = self.yeast_model.get_yeast_pitch_rate( - final_volume=21.0, - target_pitch_rate=1.5, - num_packs=2) - expected = {u'original_gravity': 1.050, - u'final_volume': 21.0, - u'viability': 0.79, - u'cells': 158.0, - u'target_pitch_rate': 1.5, - u'pitch_rate_as_is': 0.61, - u'pitch_rate_cells': 390.21, - u'cells_needed': 232.21, - u'required_growth_rate': 2.47, - u'units': 'metric', - } + final_volume=21.0, target_pitch_rate=1.5, num_packs=2 + ) + expected = { + u"original_gravity": 1.050, + u"final_volume": 21.0, + u"viability": 0.79, + u"cells": 158.0, + u"target_pitch_rate": 1.5, + u"pitch_rate_as_is": 0.61, + u"pitch_rate_cells": 390.21, + u"cells_needed": 232.21, + u"required_growth_rate": 2.47, + u"units": "metric", + } self.assertEquals(out, expected) def test_get_starter_volume(self): available_cells = 160.0 out = self.yeast_model.get_starter_volume(available_cells) - expected = {u'available_cells': 160.0, - u'starter_volume': 0.53, - u'original_gravity': 1.036, - u'dme': 7.23, - u'inoculation_rate': 80.0, - u'growth_rate': 0.68, - u'end_cell_count': 268.15, - u'units': 'imperial', - } + expected = { + u"available_cells": 160.0, + u"starter_volume": 0.53, + u"original_gravity": 1.036, + u"dme": 7.23, + u"inoculation_rate": 80.0, + u"growth_rate": 0.68, + u"end_cell_count": 268.15, + u"units": "imperial", + } self.assertEquals(out, expected) def test_get_starter_volume_metric_no_agitation(self): available_cells = 160.0 self.yeast_model.set_units(SI_UNITS) - out = self.yeast_model.get_starter_volume(available_cells, - starter_volume=2.0) - expected = {u'available_cells': 160.0, - u'starter_volume': 2.0, - u'original_gravity': 1.036, - u'dme': 204.9, - u'inoculation_rate': 80.0, - u'growth_rate': 0.68, - u'end_cell_count': 268.15, - u'units': 'metric', - } + out = self.yeast_model.get_starter_volume(available_cells, starter_volume=2.0) + expected = { + u"available_cells": 160.0, + u"starter_volume": 2.0, + u"original_gravity": 1.036, + u"dme": 204.9, + u"inoculation_rate": 80.0, + u"growth_rate": 0.68, + u"end_cell_count": 268.15, + u"units": "metric", + } self.assertEquals(out, expected) def test_get_starter_volume_metric_shaking(self): available_cells = 160.0 - yeast_model = self.yeast_model_cls(u'shaking') + yeast_model = self.yeast_model_cls(u"shaking") yeast_model.set_units(SI_UNITS) - out = yeast_model.get_starter_volume(available_cells, - starter_volume=2.0) - expected = {u'available_cells': 160.0, - u'starter_volume': 2.0, - u'original_gravity': 1.036, - u'dme': 204.9, - u'inoculation_rate': 80.0, - u'growth_rate': 1.18, - u'end_cell_count': 348.15, - u'units': 'metric', - } + out = yeast_model.get_starter_volume(available_cells, starter_volume=2.0) + expected = { + u"available_cells": 160.0, + u"starter_volume": 2.0, + u"original_gravity": 1.036, + u"dme": 204.9, + u"inoculation_rate": 80.0, + u"growth_rate": 1.18, + u"end_cell_count": 348.15, + u"units": "metric", + } self.assertEquals(out, expected) def test_get_starter_volume_metric_stir_plate(self): available_cells = 160.0 - yeast_model = self.yeast_model_cls(u'stir plate') + yeast_model = self.yeast_model_cls(u"stir plate") yeast_model.set_units(SI_UNITS) - out = yeast_model.get_starter_volume(available_cells, - starter_volume=2.0) - expected = {u'available_cells': 160.0, - u'starter_volume': 2.0, - u'original_gravity': 1.036, - u'dme': 204.9, - u'inoculation_rate': 80.0, - u'growth_rate': 1.68, - u'end_cell_count': 428.15, - u'units': 'metric', - } + out = yeast_model.get_starter_volume(available_cells, starter_volume=2.0) + expected = { + u"available_cells": 160.0, + u"starter_volume": 2.0, + u"original_gravity": 1.036, + u"dme": 204.9, + u"inoculation_rate": 80.0, + u"growth_rate": 1.68, + u"end_cell_count": 428.15, + u"units": "metric", + } self.assertEquals(out, expected) def test_get_resulting_pitch_rate_imperial(self): @@ -234,6 +236,5 @@ def test_get_resulting_pitch_rate_imperial(self): def test_get_resulting_pitch_rate_metric(self): self.yeast_model.set_units(SI_UNITS) - out = self.yeast_model.get_resulting_pitch_rate(268.15, - final_volume=21.0) + out = self.yeast_model.get_resulting_pitch_rate(268.15, final_volume=21.0) self.assertEquals(round(out, 2), 1.41) diff --git a/tests/test_validators.py b/tests/test_validators.py index f544eb4..4ee158a 100644 --- a/tests/test_validators.py +++ b/tests/test_validators.py @@ -13,16 +13,17 @@ class TestValidators(unittest.TestCase): - def test_validate_grain_type(self): out = validate_grain_type(GRAIN_TYPE_CEREAL) self.assertEqual(out, GRAIN_TYPE_CEREAL) def test_validate_grain_type_raises(self): with self.assertRaises(ValidatorException) as ctx: - validate_grain_type(u'bad grain type') - self.assertEquals(str(ctx.exception), - u"Unkown grain type 'bad grain type', must use cereal, specialty, dme, lme") # noqa + validate_grain_type(u"bad grain type") + self.assertEquals( + str(ctx.exception), + u"Unkown grain type 'bad grain type', must use cereal, specialty, dme, lme", + ) # noqa def test_validate_hop_type(self): out = validate_hop_type(HOP_TYPE_PELLET) @@ -30,9 +31,11 @@ def test_validate_hop_type(self): def test_validate_hop_type_raises(self): with self.assertRaises(ValidatorException) as ctx: - validate_hop_type(u'bad hop type') - self.assertEquals(str(ctx.exception), - u"Unkown hop type 'bad hop type', must use pellet, whole, whole wet, plug") # noqa + validate_hop_type(u"bad hop type") + self.assertEquals( + str(ctx.exception), + u"Unkown hop type 'bad hop type', must use pellet, whole, whole wet, plug", + ) # noqa def test_validate_percentage_pass(self): out = validate_percentage(0.97) @@ -41,63 +44,67 @@ def test_validate_percentage_pass(self): def test_validate_percentage_raises(self): with self.assertRaises(ValidatorException) as ctx: validate_percentage(1.01) - self.assertEquals(str(ctx.exception), - u"Percentage values should be in decimal format") + self.assertEquals( + str(ctx.exception), u"Percentage values should be in decimal format" + ) with self.assertRaises(ValidatorException) as ctx: validate_percentage(-0.01) - self.assertEquals(str(ctx.exception), - u"Percentage values should be in decimal format") + self.assertEquals( + str(ctx.exception), u"Percentage values should be in decimal format" + ) def test_validate_units(self): - out = validate_units(u'metric') - self.assertEquals(out, u'metric') + out = validate_units(u"metric") + self.assertEquals(out, u"metric") def test_validate_units_raises(self): with self.assertRaises(ValidatorException) as ctx: - validate_units(u'bad') - self.assertEquals(str(ctx.exception), - u"Unkown units 'bad', must use imperial or metric") + validate_units(u"bad") + self.assertEquals( + str(ctx.exception), u"Unkown units 'bad', must use imperial or metric" + ) def test_validate_required_fields(self): - data = {u'required': u'data'} - required_fields = [(u'required', str)] + data = {u"required": u"data"} + required_fields = [(u"required", str)] validate_required_fields(data, required_fields) def test_validate_required_fields_missing_field_raises(self): - data = {u'missing': u'data'} - required_fields = [(u'required', str)] + data = {u"missing": u"data"} + required_fields = [(u"required", str)] with self.assertRaises(ValidatorException) as ctx: validate_required_fields(data, required_fields) - self.assertEquals(str(ctx.exception), - u"Required field 'required' missing from data") + self.assertEquals( + str(ctx.exception), u"Required field 'required' missing from data" + ) def test_validate_required_fields_wrong_field_type_raises(self): - data = {u'required': u'data'} - required_fields = [(u'required', int)] + data = {u"required": u"data"} + required_fields = [(u"required", int)] with self.assertRaises(ValidatorException) as ctx: # noqa validate_required_fields(data, required_fields) # self.assertEquals(str(ctx.exception), # u"Required field 'required' is not of type ''") # noqa def test_validate_optional_fields(self): - data = {u'data': {u'optional': u'data'}} - optional_fields = [(u'optional', str)] + data = {u"data": {u"optional": u"data"}} + optional_fields = [(u"optional", str)] validate_optional_fields(data, optional_fields) def test_validate_optional_fields_extra_data(self): - data = {u'data': {u'extra': u'data'}} - optional_fields = [(u'optional', str)] + data = {u"data": {u"extra": u"data"}} + optional_fields = [(u"optional", str)] validate_optional_fields(data, optional_fields) def test_validate_optional_fields_missing_data_field(self): - data = {u'missing': {u'optional': u'data'}} - optional_fields = [(u'optional', str)] + data = {u"missing": {u"optional": u"data"}} + optional_fields = [(u"optional", str)] validate_optional_fields(data, optional_fields) def test_validate_optional_fields_wrong_field_type_raises(self): - data = {u'data': {u'optional': u'data'}} - optional_fields = [(u'optional', int)] + data = {u"data": {u"optional": u"data"}} + optional_fields = [(u"optional", int)] with self.assertRaises(ValidatorException) as ctx: # noqa validate_optional_fields(data, optional_fields) # self.assertEquals(str(ctx.exception), diff --git a/tests/test_yeasts.py b/tests/test_yeasts.py index d14a576..bb017f6 100644 --- a/tests/test_yeasts.py +++ b/tests/test_yeasts.py @@ -10,7 +10,6 @@ class TestYeasts(unittest.TestCase): - def setUp(self): # Define Yeasts @@ -18,40 +17,35 @@ def setUp(self): def test_str(self): out = str(self.yeast) - self.assertEquals(out, u'Wyeast 1056, attenuation 75.0%') + self.assertEquals(out, u"Wyeast 1056, attenuation 75.0%") def test_unicode(self): - yeast = Yeast(u'Kölsh', - percent_attenuation=0.74) + yeast = Yeast(u"Kölsh", percent_attenuation=0.74) out = str(yeast) if sys.version_info[0] >= 3: - self.assertEquals(out, u'Kölsh, attenuation 74.0%') + self.assertEquals(out, u"Kölsh, attenuation 74.0%") else: - self.assertEquals(out, u'Kölsh, attenuation 74.0%'.encode('utf8')) + self.assertEquals(out, u"Kölsh, attenuation 74.0%".encode("utf8")) def test_repr(self): out = repr(self.yeast) - self.assertEquals(out, u"Yeast('Wyeast 1056', percent_attenuation=0.75)") # noqa + self.assertEquals( + out, u"Yeast('Wyeast 1056', percent_attenuation=0.75)" + ) # noqa def test_eq(self): - yeast1 = Yeast(u'Wyeast 1056', - percent_attenuation=0.75) - yeast2 = Yeast(u'Wyeast 1056', - percent_attenuation=0.75) + yeast1 = Yeast(u"Wyeast 1056", percent_attenuation=0.75) + yeast2 = Yeast(u"Wyeast 1056", percent_attenuation=0.75) self.assertEquals(yeast1, yeast2) def test_ne_name(self): - yeast1 = Yeast(u'Wyeast 1056', - percent_attenuation=0.75) - yeast2 = Yeast(u'Wyeast 1057', - percent_attenuation=0.75) + yeast1 = Yeast(u"Wyeast 1056", percent_attenuation=0.75) + yeast2 = Yeast(u"Wyeast 1057", percent_attenuation=0.75) self.assertTrue(yeast1 != yeast2) def test_ne_percent_attenuation(self): - yeast1 = Yeast(u'Wyeast 1056', - percent_attenuation=0.75) - yeast2 = Yeast(u'Wyeast 1056', - percent_attenuation=0.70) + yeast1 = Yeast(u"Wyeast 1056", percent_attenuation=0.75) + yeast2 = Yeast(u"Wyeast 1056", percent_attenuation=0.70) self.assertTrue(yeast1 != yeast2) def test_ne_yeast_add_class(self): @@ -59,16 +53,14 @@ def test_ne_yeast_add_class(self): def test_to_dict(self): out = self.yeast.to_dict() - expected = {u'name': u'Wyeast 1056', - u'data': { - u'percent_attenuation': 0.75, - }, - } + expected = {u"name": u"Wyeast 1056", u"data": {u"percent_attenuation": 0.75}} self.assertEquals(out, expected) def test_to_json(self): out = self.yeast.to_json() - expected = u'{"data": {"percent_attenuation": 0.75}, "name": "Wyeast 1056"}' # noqa + expected = ( + u'{"data": {"percent_attenuation": 0.75}, "name": "Wyeast 1056"}' + ) # noqa self.assertEquals(out, expected) def test_validate(self): @@ -77,15 +69,17 @@ def test_validate(self): def test_format(self): out = self.yeast.format() - msg = textwrap.dedent(u"""\ + msg = textwrap.dedent( + u"""\ Wyeast 1056 Yeast ----------------------------------- - Attenuation: 75.0%""") + Attenuation: 75.0%""" + ) self.assertEquals(out, msg) def test_yeast_no_percent_attenuation(self): with self.assertRaises(YeastException) as ctx: - Yeast(u'Wyeast 1056', - percent_attenuation=None) - self.assertEquals(str(ctx.exception), - u"Wyeast 1056: Must provide percent attenuation") + Yeast(u"Wyeast 1056", percent_attenuation=None) + self.assertEquals( + str(ctx.exception), u"Wyeast 1056: Must provide percent attenuation" + ) diff --git a/update_coveralls.py b/update_coveralls.py index b7c8e3f..8fc1f03 100644 --- a/update_coveralls.py +++ b/update_coveralls.py @@ -4,20 +4,20 @@ from distutils.sysconfig import get_python_lib from subprocess import call -if __name__ == '__main__': +if __name__ == "__main__": # chdir to the site-packages directory so the report lists relative paths - dot_coverage_path = os.path.join(os.getcwd(), '.coverage') + dot_coverage_path = os.path.join(os.getcwd(), ".coverage") os.chdir(get_python_lib()) try: - os.remove('.coverage') + os.remove(".coverage") except OSError: pass - os.symlink(dot_coverage_path, '.coverage') + os.symlink(dot_coverage_path, ".coverage") # create a report from the coverage data - if 'TRAVIS' in os.environ: - rc = call('coveralls') + if "TRAVIS" in os.environ: + rc = call("coveralls") raise SystemExit(rc) else: - rc = call(['coverage', 'report']) + rc = call(["coverage", "report"]) raise SystemExit(rc)