LowVoltage/actions/conversion.py
ConversionUnitTests
has 32 functions (exceeds 20 allowed). Consider refactoring. Open
Open
class ConversionUnitTests(_tst.UnitTests):
def test_convert_unicode_value_to_db(self):
self.assertEqual(_convert_value_to_db(u"éoà"), {"S": u"éoà"})
def test_convert_bytes_value_to_db(self):
Function _convert_value_to_db
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
Open
def _convert_value_to_db(value):
if isinstance(value, unicode):
return {"S": value}
elif isinstance(value, bytes):
return {"B": base64.b64encode(value).decode("utf8")}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _convert_db_to_value
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
Open
def _convert_db_to_value(value):
if "S" in value:
return value["S"]
elif "B" in value:
return bytes(base64.b64decode(value["B"].encode("utf8")))
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this function. Open
Open
return {"M": {n: _convert_value_to_db(v) for n, v in value.iteritems()}}
Avoid too many return
statements within this function. Open
Open
return set(bytes(base64.b64decode(v.encode("utf8"))) for v in value["BS"])
Avoid too many return
statements within this function. Open
Open
return {"NULL": True}
Avoid too many return
statements within this function. Open
Open
return {"L": [_convert_value_to_db(v) for v in value]}
Avoid too many return
statements within this function. Open
Open
return {"SS": [s for s in value]}
Avoid too many return
statements within this function. Open
Open
return set(int(v) for v in value["NS"])
Avoid too many return
statements within this function. Open
Open
return {n: _convert_db_to_value(v) for n, v in value["M"].iteritems()}
Avoid too many return
statements within this function. Open
Open
return {"BS": [base64.b64encode(b).decode("utf8") for b in value]}
Avoid too many return
statements within this function. Open
Open
return {"NS": [str(n) for n in value]}
Avoid too many return
statements within this function. Open
Open
return set(value["SS"])
Avoid too many return
statements within this function. Open
Open
return None
Avoid too many return
statements within this function. Open
Open
return [_convert_db_to_value(v) for v in value["L"]]