diff --git a/.travis.yml b/.travis.yml index ecdc35b2..9c257de8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,13 +9,17 @@ before_install: # Installing Arpeggio as a dependency - cd .. - pip install Jinja2 + - pip install coverage + - pip install flake8 - git clone --depth=1 --branch=master git://github.com/igordejanovic/Arpeggio.git - cd Arpeggio && python setup.py install - cd ../textX install: - python setup.py install script: - - py.test tests/functional + - coverage run --source textx -m py.test tests/functional + - coverage report --fail-under 80 + - flake8 textx tests --exclude tests/perf,textx/six.py,textx/lang.py matrix: include: diff --git a/docs/about/contributing.md b/docs/about/contributing.md index 2a778d4a..c9b44929 100644 --- a/docs/about/contributing.md +++ b/docs/about/contributing.md @@ -88,7 +88,7 @@ Ready to contribute? Here's how to set up `textX` for local development. To verify that everything is setup properly run tests: - $ flake8 tests/functional/ + $ flake8 textx tests --exclude tests/perf,textx/six.py,textx/lang.py $ py.test tests/functional/ 4. Create a branch for local development:: @@ -97,11 +97,18 @@ Ready to contribute? Here's how to set up `textX` for local development. Now you can make your changes locally. -5. When you're done making changes, check that your changes pass flake8 and the - tests: +5. When you're done making changes, check that your changes pass flake8, the + tests, and have a look at the coverage: - $ flake8 textX tests + $ flake8 textx tests/functional $ py.test tests/functional/ + $ coverage run --source textx -m py.test tests/functional + $ coverage report + + In case you have doubts, have also a look at the html rendered version of + the coverage results: + + $ coverage html 6. Commit your changes and push your branch to GitHub: diff --git a/examples/StateMachine/smdot.py b/examples/StateMachine/smdot.py index 1a0cda15..63e61b0a 100644 --- a/examples/StateMachine/smdot.py +++ b/examples/StateMachine/smdot.py @@ -1,15 +1,11 @@ """ Export state machine models to dot. """ +from __future__ import unicode_literals import codecs import sys from os.path import dirname, join from textx import metamodel_from_file -if sys.version < '3': - text = unicode -else: - text = str - HEADER = ''' digraph xtext { @@ -64,5 +60,5 @@ def sm_to_dot(model): meta = metamodel_from_file(join(this_folder, 'state_machine.tx')) model = meta.model_from_file(model_name) with codecs.open("{}.dot".format(model_name), 'w', - encoding='utf-8') as f: + encoding='utf-8') as f: f.write(sm_to_dot(model)) diff --git a/examples/StateMachine/state_machine.py b/examples/StateMachine/state_machine.py index 369acb9f..5508ee07 100644 --- a/examples/StateMachine/state_machine.py +++ b/examples/StateMachine/state_machine.py @@ -55,14 +55,13 @@ def interpret(self): return event = int(event) event = self.model.events[event-1] - except: + except Exception: print('Invalid input') self.event(event) self.print_menu() - if __name__ == '__main__': this_folder = dirname(__file__) if len(sys.argv) != 2: diff --git a/examples/hello_world/hello.py b/examples/hello_world/hello.py index 5636d36b..a9485bdb 100755 --- a/examples/hello_world/hello.py +++ b/examples/hello_world/hello.py @@ -25,7 +25,3 @@ def main(debug=False): if __name__ == '__main__': main() - - - - diff --git a/examples/pyFlies/experiment.py b/examples/pyFlies/experiment.py index ebf6caf5..44e1ddac 100644 --- a/examples/pyFlies/experiment.py +++ b/examples/pyFlies/experiment.py @@ -17,4 +17,3 @@ def main(debug=False): if __name__ == '__main__': main() - diff --git a/examples/workflow/workflow.py b/examples/workflow/workflow.py index 68046060..d26da258 100644 --- a/examples/workflow/workflow.py +++ b/examples/workflow/workflow.py @@ -25,4 +25,3 @@ def main(debug=False): if __name__ == '__main__': main() - diff --git a/requirements_dev.txt b/requirements_dev.txt index 6f11ba06..da11f25c 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,5 +1,6 @@ pytest flake8 +coverage jinja2 mkdocs mike diff --git a/tests/functional/test_regexp_with_groups.py b/tests/functional/test_regexp_with_groups.py index 4d8a8654..79c7e3a0 100644 --- a/tests/functional/test_regexp_with_groups.py +++ b/tests/functional/test_regexp_with_groups.py @@ -14,12 +14,12 @@ grammar = r""" Model: entries += Entry; Entry: - 'data' '=' data=/\"(?ms){3}(.*?)\"{3}/ + 'data' '=' data=/(?ms)\"{3}(.*?)\"{3}/ ; """ grammar2 = r""" Model: - 'data' '=' data=/\"(?ms){3}(.*?)\"{3}\s*\-(\w+)\-/ + 'data' '=' data=/(?ms)\"{3}(.*?)\"{3}\s*\-(\w+)\-/ ; """ diff --git a/textx/commands/console.py b/textx/commands/console.py index 724a0386..8b0404c9 100644 --- a/textx/commands/console.py +++ b/textx/commands/console.py @@ -13,7 +13,8 @@ def textx(): class MyParser(argparse.ArgumentParser): """ Custom argument parser for printing help message in case of an error. - See http://stackoverflow.com/questions/4042452/display-help-message-with-python-argparse-when-script-is-called-without-any-argu + See + http://stackoverflow.com/questions/4042452/display-help-message-with-python-argparse-when-script-is-called-without-any-argu """ def error(self, message): sys.stderr.write('error: %s\n' % message) diff --git a/textx/export.py b/textx/export.py index 9efda0f3..fc991498 100644 --- a/textx/export.py +++ b/textx/export.py @@ -266,4 +266,4 @@ def _export_subgraph(m): else: _export(model) - f.write('\n}\n') \ No newline at end of file + f.write('\n}\n') diff --git a/textx/scoping/__init__.py b/textx/scoping/__init__.py index d5060849..eb966de3 100644 --- a/textx/scoping/__init__.py +++ b/textx/scoping/__init__.py @@ -220,7 +220,7 @@ def load_model( return self.local_models.filename_to_model[filename] def _add_model(self, model): - filename =self.update_model_in_repo_based_on_filename(model) + filename = self.update_model_in_repo_based_on_filename(model) self.local_models.filename_to_model[filename] = model def update_model_in_repo_based_on_filename(self, model): @@ -234,9 +234,9 @@ def update_model_in_repo_based_on_filename(self, model): for fn in self.all_models.filename_to_model: if self.all_models.filename_to_model[fn] == model: return fn - i=0 + i = 0 while self.all_models.has_model("anonymous{}".format(i)): - i+=1 + i += 1 myfilename = "anonymous{}".format(i) self.all_models.filename_to_model[myfilename] = model else: @@ -245,7 +245,6 @@ def update_model_in_repo_based_on_filename(self, model): self.all_models.filename_to_model[myfilename] = model return myfilename - def pre_ref_resolution_callback(self, other_model): """ (internal: used to store a model after parsing into the repository) @@ -296,4 +295,3 @@ def get_all_models_including_attached_models(model): else: models = [model] return models - diff --git a/textx/scoping/providers.py b/textx/scoping/providers.py index c7d4f325..9a0c843b 100644 --- a/textx/scoping/providers.py +++ b/textx/scoping/providers.py @@ -10,7 +10,7 @@ import textx.scoping as scoping """ -This module defines scope providers to be used in conjunctions with a +This module defines scope providers to be used in conjunctions with a textx.metamodel meta model. See docs/scoping.md