Skip to content
This repository has been archived by the owner on Apr 23, 2021. It is now read-only.

Commit

Permalink
Merge pull request #405 from simphony/noqa-for-cuba-enum-long-lines
Browse files Browse the repository at this point in the history
Added noqa to the cuba enum parser when long lines are present
  • Loading branch information
stefanoborini committed Mar 13, 2017
2 parents 00a29c4 + 05b0f86 commit a3b607e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
12 changes: 8 additions & 4 deletions scripts/cuba_enum_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ def generate(self, ontology, output):
'@unique\n',
'class CUBA(Enum):\n'
]
template = ' {cuba_name} = "{cuba_name}"\n'
template = ' {cuba_name} = "{cuba_name}"'

all_keys = set(d.name for d in ontology.data_types)
all_keys.update([d.name for d, _ in traverse(ontology.root_cuds_item)])

for keyword in sorted(list(all_keys)):
lines.append(
template.format(
cuba_name=without_cuba_prefix(keyword)))
line = template.format(cuba_name=without_cuba_prefix(keyword))

# yapf does not break such lines, so we have to get creative.
if len(line) >= 79:
line += " # noqa"

lines.append(line+'\n')

output.writelines(lines)
18 changes: 18 additions & 0 deletions scripts/tests/test_cuba_enum_generator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
from six import StringIO

from simphony_metaparser.nodes import CUDSItem
from scripts.cuba_enum_generator import CUBAEnumGenerator
from scripts.tests import fixtures

Expand All @@ -21,3 +22,20 @@ def test_basic_parsing(self):
self.assertIn(
'{keyword} = "{keyword}"'.format(
keyword=keyword), text)

def test_long_line(self):
generator = CUBAEnumGenerator()
output = StringIO()
self.ontology.root_cuds_item.children.append(
CUDSItem(
name="CUBA.REALLY_LONG_NAME_THAT_GOES_BEYOND_THE_79_CHARACTER_LIMIT", # noqa
parent=self.ontology.root_cuds_item
)
)

generator.generate(self.ontology, output)

text = output.getvalue()
self.assertIn(
'"REALLY_LONG_NAME_THAT_GOES_BEYOND_THE_79_CHARACTER_LIMIT" # noqa', # noqa
text)

0 comments on commit a3b607e

Please sign in to comment.