Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Makefile to run tests #35

Merged
merged 2 commits into from
Aug 7, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add Makefile
  • Loading branch information
charlax committed Feb 1, 2018
commit cdab7f3f067f4d3248f10e1d354d6330284eb7d3
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ build
dist
MANIFEST
.idea

testfile.txt
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test:
python test_simpleeval.py
.PHONY: test
13 changes: 10 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ simpleeval (Simple Eval)
.. image:: https://travis-ci.org/danthedeckie/simpleeval.svg?branch=master
:target: https://travis-ci.org/danthedeckie/simpleeval
:alt: Build Status

.. image:: https://coveralls.io/repos/github/danthedeckie/simpleeval/badge.svg?branch=master
:target: https://coveralls.io/r/danthedeckie/simpleeval?branch=master
:alt: Coverage Status
Expand Down Expand Up @@ -185,7 +185,7 @@ which, of course, can be nested:

>>> simple_eval("'a' if 1 == 2 else 'b' if 2 == 3 else 'c'")
'c'


Functions
---------
Expand Down Expand Up @@ -278,7 +278,7 @@ cases):

>>> s.eval('100 * 10')
1000

# and so on...

You can assign / edit the various options of the ``SimpleEval`` object if you
Expand Down Expand Up @@ -355,3 +355,10 @@ If you really need that (BE CAREFUL!), then modify the module global
Please read the ``test_simpleeval.py`` file for other potential gotchas or
details. I'm very happy to accept pull requests, suggestions, or other issues.
Enjoy!

Developing
----------

Run tests::

$ make test
11 changes: 7 additions & 4 deletions test_simpleeval.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def test_load_file(self):

# write to the file:

with open("file.txt", 'w') as f:
with open("testfile.txt", 'w') as f:
f.write("42")

# define the function we'll send to the eval'er
Expand All @@ -175,20 +175,20 @@ def load_file(filename):
# simple load:

self.s.functions = {"read": load_file}
self.t("read('file.txt')", "42")
self.t("read('testfile.txt')", "42")

# and we should have *replaced* the default functions. Let's check:

with self.assertRaises(simpleeval.FunctionNotDefined):
self.t("int(read('file.txt'))", 42)
self.t("int(read('testfile.txt'))", 42)

# OK, so we can load in the default functions as well...

self.s.functions.update(simpleeval.DEFAULT_FUNCTIONS)

# now it works:

self.t("int(read('file.txt'))", 42)
self.t("int(read('testfile.txt'))", 42)

def test_randoms(self):
""" test the rand() and randint() functions """
Expand Down Expand Up @@ -687,3 +687,6 @@ def _eval_call(self, node):

with self.assertRaises(simpleeval.FeatureNotAvailable):
e.eval('" blah ".strip()')

if __name__ == '__main__':
unittest.main()