Skip to content

Commit 6b7bfed

Browse files
authored
Merge pull request #79 from realpython/emacs-the-best-python-editor
Adding code to support Emacs article
2 parents 94fc018 + a456bac commit 6b7bfed

File tree

10 files changed

+582
-0
lines changed

10 files changed

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

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

Lines changed: 86 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: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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 + ",
42+
expr.result(),
43+
"ERROR: Negative/positive term expression",
44+
)
45+
expr = Expression("53+-2")
46+
self.assertEqual(
47+
"53 -2 + ",
48+
expr.result(),
49+
"ERROR: Positive/negative term expression",
50+
)
51+
expr = Expression("-53+-2")
52+
self.assertEqual(
53+
"-53 -2 + ",
54+
expr.result(),
55+
"ERROR: Double negative term expression",
56+
)
57+
58+
def test_double_term_operands(self):
59+
"""
60+
Tests a set of operands
61+
"""
62+
expr = Expression("53+2")
63+
self.assertEqual(
64+
"53 2 + ", expr.result(), "ERROR: Additive expression"
65+
)
66+
expr = Expression("53-2")
67+
self.assertEqual(
68+
"53 2 - ", expr.result(), "ERROR: Subtrative expression"
69+
)
70+
expr = Expression("53*2")
71+
self.assertEqual(
72+
"53 2 * ", expr.result(), "ERROR: Multiplicative expression"
73+
)
74+
expr = Expression("53/2")
75+
self.assertEqual("53 2 / ", expr.result(), "ERROR: Divide expression")
76+
77+
def test_triple_term_expression(self):
78+
"""
79+
Tests a set of triple term expressions
80+
"""
81+
expr = Expression("53+2+37")
82+
self.assertEqual(
83+
"53 2 37 + + ", expr.result(), "ERROR: Add/Add expression"
84+
)
85+
expr = Expression("53+2*37")
86+
self.assertEqual(
87+
"53 2 37 * + ", expr.result(), "ERROR: Add/Multiply expression"
88+
)
89+
expr = Expression("53*2+37")
90+
self.assertEqual(
91+
"53 2 * 37 + ", expr.result(), "ERROR: Multiply/Add expression"
92+
)
93+
expr = Expression("53*2*37")
94+
self.assertEqual(
95+
"53 2 37 * * ",
96+
expr.result(),
97+
"ERROR: Multiply/Multiply expression",
98+
)
99+
100+
def test_whitespace_expression(self):
101+
"""
102+
Tests a set of expressions with a variety of whitespace
103+
"""
104+
expr = Expression("53+2+37")
105+
self.assertEqual(
106+
"53 2 37 + + ", expr.result(), "ERROR: No whitespace expression"
107+
)
108+
expr = Expression("53 + 2 + 37")
109+
self.assertEqual(
110+
"53 2 37 + + ",
111+
expr.result(),
112+
"ERROR: Infixed whitespace expression",
113+
)
114+
expr = Expression(" 53+2+37 ")
115+
self.assertEqual(
116+
"53 2 37 + + ",
117+
expr.result(),
118+
"ERROR: Pre/post-fixed whitespace expression",
119+
)
120+
expr = Expression(" 53 + 2 + 37 ")
121+
self.assertEqual(
122+
"53 2 37 + + ",
123+
expr.result(),
124+
"ERROR: Pre/post/in-fixed whitespace expression",
125+
)
126+
expr = Expression(" 53 + 2 + 37 ")
127+
self.assertEqual(
128+
"53 2 37 + + ",
129+
expr.result(),
130+
"ERROR: Multiple whitespace expression",
131+
)
132+
133+
# This test should throw an exception - spaces in between operands
134+
# should give an error
135+
with self.assertRaises(SyntaxError):
136+
expr = Expression(" 53 + - 2 + 37 ")
137+
expr.parse()

0 commit comments

Comments
 (0)