balanced / balanced-python

Balanced API library in python.
MIT License
69 stars 49 forks source link

Run examples as part of test run #84

Open mjallday opened 10 years ago

mjallday commented 10 years ago

It's too easy to break the examples and not know about it.

julianpistorius commented 10 years ago

I've run into this problem with the examples before. I'll have a look at it. Any suggestions on how the examples could be run as part of the test suite?

mjallday commented 10 years ago

We can either enumerate all the files in the directory and run them then check for return code == 0 or rewrite the examples to be importable (e.g. if __name__ == 'main': run_example()).

I think the first is probably less work so doing it that way would be easier.

On the test side I think something like

import subprocess, sys
class ExampleTests(TestCase):
    def test_examples_run(self):
         for example_file_name in example_dir_files:
              self.assertEqual(subprocess.call( sys.executeable + " " + example_file_name, shell=True), 0)

this is probably a pretty naive implementation but it has the general idea right.

hat tip to @coderanger for the sys.executable move.