Skip to content

Commit 07434fa

Browse files
committed
Files needed for Emacs article
1 parent e5e3cde commit 07434fa

File tree

9 files changed

+684
-0
lines changed

9 files changed

+684
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[[source]]
2+
url = "https://pypi.org/simple"
3+
verify_ssl = true
4+
name = "pypi"
5+
6+
[packages]
7+
pylint = "*"
8+
jedi = "*"
9+
autopep8 = "*"
10+
yapf = "*"
11+
black = "*"
12+
flake8 = "*"
13+
14+
[dev-packages]
15+
16+
[requires]
17+
python_version = "3.6"

emacs-the-best-python-editor/PyEval/Pipfile.lock

Lines changed: 222 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'''
2+
Example code for debugging PyEval
3+
'''
4+
5+
from pyeval_expression import Expression
6+
7+
expr = Expression("53 * -2 + 4")
8+
expr.parse()
9+
print(expr.result())
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
"""
2+
Test cases for PyEval
3+
4+
Jon Fincher, July 2018
5+
"""
6+
import unittest
7+
from pyeval_expression import Expression
8+
9+
10+
class TestPyEval(unittest.TestCase):
11+
12+
"""
13+
Validation of Expression and Operator classes.
14+
No setup function is needed
15+
"""
16+
17+
def test_positive_operand_expression(self):
18+
"""
19+
Tests a single positive operand expression
20+
"""
21+
expr = Expression("53")
22+
self.assertEqual("53 ", expr.result(), "ERROR: Positive operand")
23+
24+
def test_negative_operand_expression(self):
25+
"""
26+
Tests a single negative operand expression
27+
"""
28+
expr = Expression("-53")
29+
self.assertEqual("-53 ", expr.result(), "ERROR: Negative operand")
30+
31+
def test_double_term_expression(self):
32+
"""
33+
Tests a set of double term expressions
34+
"""
35+
expr = Expression("53+2")
36+
self.assertEqual(
37+
"53 2 + ", expr.result(), "ERROR: Double positive term expression"
38+
)
39+
expr = Expression("-53+2")
40+
self.assertEqual(
41+
"-53 2 + ", expr.result(), "ERROR: Negative/positive term expression"
42+
)
43+
expr = Expression("53+-2")
44+
self.assertEqual(
45+
"53 -2 + ", expr.result(), "ERROR: Positive/negative term expression"
46+
)
47+
expr = Expression("-53+-2")
48+
self.assertEqual(
49+
"-53 -2 + ", expr.result(), "ERROR: Double negative term expression"
50+
)
51+
52+
def test_double_term_operands(self):
53+
"""
54+
Tests a set of operands
55+
"""
56+
expr = Expression("53+2")
57+
self.assertEqual("53 2 + ", expr.result(), "ERROR: Additive expression")
58+
expr = Expression("53-2")
59+
self.assertEqual("53 2 - ", expr.result(), "ERROR: Subtrative expression")
60+
expr = Expression("53*2")
61+
self.assertEqual("53 2 * ", expr.result(), "ERROR: Multiplicative expression")
62+
expr = Expression("53/2")
63+
self.assertEqual("53 2 / ", expr.result(), "ERROR: Divide expression")
64+
65+
def test_triple_term_expression(self):
66+
"""
67+
Tests a set of triple term expressions
68+
"""
69+
expr = Expression("53+2+37")
70+
self.assertEqual("53 2 37 + + ", expr.result(), "ERROR: Add/Add expression")
71+
expr = Expression("53+2*37")
72+
self.assertEqual(
73+
"53 2 37 * + ", expr.result(), "ERROR: Add/Multiply expression"
74+
)
75+
expr = Expression("53*2+37")
76+
self.assertEqual(
77+
"53 2 * 37 + ", expr.result(), "ERROR: Multiply/Add expression"
78+
)
79+
expr = Expression("53*2*37")
80+
self.assertEqual(
81+
"53 2 37 * * ", expr.result(), "ERROR: Multiply/Multiply expression"
82+
)
83+
84+
def test_whitespace_expression(self):
85+
"""
86+
Tests a set of expressions with a variety of whitespace
87+
"""
88+
expr = Expression("53+2+37")
89+
self.assertEqual(
90+
"53 2 37 + + ", expr.result(), "ERROR: No whitespace expression"
91+
)
92+
expr = Expression("53 + 2 + 37")
93+
self.assertEqual(
94+
"53 2 37 + + ", expr.result(), "ERROR: Infixed whitespace expression"
95+
)
96+
expr = Expression(" 53+2+37 ")
97+
self.assertEqual(
98+
"53 2 37 + + ", expr.result(), "ERROR: Pre/post-fixed whitespace expression"
99+
)
100+
expr = Expression(" 53 + 2 + 37 ")
101+
self.assertEqual(
102+
"53 2 37 + + ",
103+
expr.result(),
104+
"ERROR: Pre/post/in-fixed whitespace expression",
105+
)
106+
expr = Expression(" 53 + 2 + 37 ")
107+
self.assertEqual(
108+
"53 2 37 + + ", expr.result(), "ERROR: Multiple whitespace expression"
109+
)
110+
111+
# This test should throw an exception - spaces in between operands should give an error
112+
with self.assertRaises(SyntaxError):
113+
expr = Expression(" 53 + - 2 + 37 ")
114+
expr.parse()

0 commit comments

Comments
 (0)