Skip to content

Commit add629a

Browse files
committed
Merge branch 'master' of github.com:RunestoneInteractive/thinkcspy
2 parents ec4459a + 074390b commit add629a

132 files changed

Lines changed: 1554 additions & 778 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ sphinx-enki-info.txt
1616
sphinx_settings.json
1717
output.log
1818
beta
19+
output
20+
published
21+
pdf

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export BOOKDIR=$(HOME)/Runestone/books/thinkcspy
22
export COMPDIR=$(HOME)/Runestone/RunestoneComponents
33
export RSURI = https://runestone.academy/cdn/runestone/
44

5-
.PHONY: pretext html pdf
5+
.PHONY: pretext html pdf runestone
66

77
help:
88
@echo "Unless you are converting RST to PTX you you should use this Makefile!!!!"
@@ -32,3 +32,8 @@ html:
3232
pdf:
3333
python ~/src/pretext/pretext/pretext -c all -f pdf -p $(BOOKDIR)/pretext/publication-rs-for-all.xml -x debug.rs.services.file /Users/bmiller/Runestone/RunestoneComponents/runestone/dist/webpack_static_imports.xml -d $(BOOKDIR)/pdf $(BOOKDIR)/pretext/thinkcspy.ptx
3434

35+
runestone:
36+
python ~/src/pretext/pretext/pretext -c all -f html -p $(BOOKDIR)/pretext/publication-rs-academy.xml -d $(BOOKDIR)/runestone $(BOOKDIR)/pretext/thinkcspy.ptx
37+
38+
profile:
39+
python -m cProfile -s cumulative ~/src/pretext/pretext/pretext -c all -f html -p $(BOOKDIR)/pretext/publication-rs-for-all.xml -d $(BOOKDIR)/beta $(BOOKDIR)/pretext/thinkcspy.ptx

README.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,18 @@ Building with PreTeXt
3232

3333
1. Create a virtual environment
3434
2. pip install pretextbook
35-
3. To build run: pretext build --input pretext/thinkcspy.ptx --output output --format html --publication pretext/publication-rs-for-all.xml
35+
3. To build run: pretext build web
3636
4. pretext view html
3737

3838
Note: The pretext sources are in the pretext folder, we will keep the _sources folder until we are 100% sure that the book has been converted correctly and as thoroughly as possible.
3939

40+
Building for Production on a Runestone Server
41+
---------------------------------------------
42+
43+
1. clone this repo to `httlacs` instead of `thinkcspy`
44+
2. Run `rsmanage addcourse` and add `httlacs` as course name and base course name
45+
3. Run `rsmanage build --ptx httlacs`
46+
4047

4148
Building with runestone
4249
-----------------------

_sources/UnitTesting/TestingWithpytest.rst

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ Here's an example of how it works:
6666
except Exception as e:
6767
self.assertEqual(item + " failed", item + " passed", item + " failed: " + str(e))
6868

69-
pyTests().main()
69+
pyTests().main()
70+
7071

71-
7272
.. test:
7373
7474
success = True
@@ -82,15 +82,15 @@ Here's an example of how it works:
8282
8383
if success:
8484
print("All tests passed!")
85-
85+
8686
This code example defines two functions: the function to be tested, ``round6``, and a function named ``test_round6``
8787
that contains unit test code. When using the pytest approach, you write your unit test as a function whose name must
8888
start with the prefix ``test_``. Inside the function, you write normal assert statements to test the desired function.
8989
Notice that you do not write a line to *call* the unit test function. Instead, when you launch pytest to run the unit
90-
tests, pytest scans your script and executes only the functions with the prefix ``test_``.
90+
tests, pytest scans your script and executes only the functions with the prefix ``test_``.
9191

9292
This ActiveCode environment simulates pytest by scanning for and executing functions with a ``test_`` prefix when you
93-
click **Run**. Go ahead and try it - rename the test_round6 function to ``test_itworks`` and try running the test again.
93+
click **Run**. Go ahead and try it - rename the test_round6 function to ``test_itworks`` and try running the test again.
9494

9595
Organizing pytest Functions
9696
---------------------------
@@ -121,11 +121,11 @@ Using pytest
121121
------------
122122

123123
To use pytest, you must first install it using the **pip** command. Open your computer's command line window
124-
(not the Python interpreter) and enter the following command to install:
124+
(not the Python interpreter) and enter the following command to install:
125125

126126
* Windows::
127127

128-
pip install pytest
128+
pip install pytest
129129

130130
* Mac/Linux::
131131

@@ -151,7 +151,7 @@ When you run the pytest command and an assertion fails, you see a report like th
151151
> assert round6(8.5) == 8
152152
E assert 9 == 8
153153
E + where 9 = round6(8.5)
154-
154+
155155
myround.py:8: AssertionError
156156

157157
Let's take a closer look at this report to understand what it's telling you.
@@ -168,15 +168,15 @@ Let's take a closer look at this report to understand what it's telling you.
168168
E + where 9 = round6(8.5)
169169

170170
This indicates that the call to ``round6(8.5)`` returned the value 9, instead of the value 8.
171-
The value ``9`` is the actual result of the function. Knowing the value actually produced by
171+
The value ``9`` is the actual result of the function. Knowing the value actually produced by
172172
the function can help you to troubleshoot the bug and correct the problem.
173173

174174
Integrated Unit Testing with pytest
175175
------------------------------------
176176

177177
When you use the pytest framework, you can include pytest test functions in your main program, along with the rest of
178178
your program code. This allows you to keep your tests together with the functions that they test, and you can run either
179-
your program (using the python command) or the unit tests (using the pytest command).
179+
your program (using the python command) or the unit tests (using the pytest command).
180180

181181
Take a look at this example that shows a function (``round6``, containing a bug), together with a
182182
unit test function (``test_round6``), and a main program that uses ``round6``:
@@ -234,7 +234,7 @@ sense, just remember: in order for pytest to work correctly, any code that is pa
234234
"""
235235
~~~~
236236
# Write a pytest unit test function named ``test_grade``
237-
237+
238238

239239
====
240240
from unittest.gui import TestCaseGui
@@ -247,7 +247,7 @@ sense, just remember: in order for pytest to work correctly, any code that is pa
247247
def grade(score):
248248
global illegal, testA, testB, testF
249249

250-
if score > 100 or score < 0:
250+
if score > 100 or score < 0:
251251
illegal = True
252252
return ''
253253
elif score >= 90:
@@ -276,13 +276,13 @@ sense, just remember: in order for pytest to work correctly, any code that is pa
276276

277277
The following is a suggested pytest unit test.
278278

279-
.. sourcecode::
280-
279+
.. sourcecode::
280+
281281
def test_grade():
282282
assert grade(92) == 'A'
283283
assert grade(85) == 'B'
284284
assert grade(69) == 'F'
285285

286-
286+
287287

288288

pretext/Appendices/foo

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<section xml:id="appendices_test-module-source-code">
2+
<title><c>test</c> module source code</title>
3+
<p>Starting in the Functions chapter, we have written unit tests using the <c>testEqual</c> function from
4+
the <c>test</c> module. This test module is not included in the standard Python distribution. (There is
5+
a standard test module but it is different from this.) What follows is the source code for this <c>test</c> module.</p>
6+
<program language="python"><input>
7+
def testEqual(actual,expected,places=5):
8+
'''
9+
Does the actual value equal the expected value?
10+
For floats, places indicates how many places, right of the decimal, must be correct
11+
'''
12+
if isinstance(expected,float):
13+
if abs(actual-expected) &lt; 10**(-places):
14+
print('\tPass')
15+
return True
16+
else:
17+
if actual == expected:
18+
print('\tPass')
19+
return True
20+
print('\tTest Failed: expected {} but got {}'.format(expected,actual))
21+
return False
22+
</input></program>
23+
<p>To use this module when programming on your own computer, save the above code with the name <term>test.py</term> in the same folder as the python program you want to test.</p>
24+
</section>
25+

pretext/ClassesBasics/Exercises.ptx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<exercises xml:id="classes-basics_exercises">
33
<title>Exercises</title>
4-
<exercise xml:id="classes_q1">
4+
<exercise label="classes_q1">
55
<statement>
66
<p>Add a <c>distanceFromPoint</c> method that works similar to <c>distanceFromOrigin</c> except that it
77
takes a <c>Point</c> as a parameter and
@@ -46,7 +46,7 @@ print(p.distanceFromPoint(q))
4646
</program>
4747
</solution>
4848
</exercise>
49-
<exercise xml:id="ch_cl_02">
49+
<exercise label="ch_cl_02">
5050
<statement>
5151
<p>Add a method <c>reflect_x</c> to Point which returns a new Point, one which is the
5252
reflection of the point about the x-axis. For example,
@@ -58,7 +58,7 @@ print(p.distanceFromPoint(q))
5858
</input>
5959
</program>
6060
</exercise>
61-
<exercise xml:id="classes_q3">
61+
<exercise label="classes_q3">
6262
<statement>
6363
<p>Add a method <c>slope_from_origin</c> which returns the slope of the line joining the origin
6464
to the point. For example,</p>
@@ -104,7 +104,7 @@ print(p.slope_from_origin())
104104
</program>
105105
</solution>
106106
</exercise>
107-
<exercise xml:id="ch_cl_04">
107+
<exercise label="ch_cl_04">
108108
<statement>
109109
<p>The equation of a straight line is <q>y = ax + b</q>, (or perhaps <q>y = mx + c</q>).
110110
The coefficients a and b completely describe the line. Write a method in the
@@ -122,7 +122,7 @@ print(p.slope_from_origin())
122122
</input>
123123
</program>
124124
</exercise>
125-
<exercise xml:id="classes_q5">
125+
<exercise label="classes_q5">
126126
<statement>
127127
<p>Add a method called <c>move</c> that will take two parameters, call them <c>dx</c> and <c>dy</c>. The method will
128128
cause the point to move in the x and y direction the number of units given. (Hint: you will change the values of the
@@ -169,7 +169,7 @@ print(p)
169169
</program>
170170
</solution>
171171
</exercise>
172-
<exercise xml:id="classes_q6">
172+
<exercise label="classes_q6">
173173
<statement>
174174
<p>Given three points that fall on the circumference of a circle, find the center and radius of the circle.</p>
175175
</statement>

pretext/ClassesBasics/UserDefinedClasses.ptx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ alex = Turtle()
125125
<p>
126126
<term>Check Your Understanding</term>
127127
</p>
128-
<exercise xml:id="chp17_objects">
128+
<exercise label="chp17_objects">
129129
<statement>
130130
<p>What is the the output of the following print code?</p>
131131
<program language="python">

pretext/ClassesDiggingDeeper/Exercises.ptx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<exercises xml:id="classes-digging-deeper_exercises">
33
<title>Exercises</title>
4-
<exercise xml:id="classes_deeper_q1">
4+
<exercise label="classes_deeper_q1">
55
<statement>
66
<p>We can represent a rectangle by knowing three things: the location of its lower left corner, its width, and its height.
77
Create a class definition for a Rectangle class using this idea. To create a Rectangle object at location (4,5) with width 6
@@ -50,7 +50,7 @@ print(r)
5050
</program>
5151
</solution>
5252
</exercise>
53-
<exercise xml:id="ch_cl2_q2">
53+
<exercise label="ch_cl2_q2">
5454
<statement>
5555
<p>Add the following accessor methods to the Rectangle class: <c>getWidth</c>, <c>getHeight</c>, <c>__str__</c>.</p>
5656
</statement>
@@ -60,7 +60,7 @@ print(r)
6060
</input>
6161
</program>
6262
</exercise>
63-
<exercise xml:id="ch_cl2_q3">
63+
<exercise label="ch_cl2_q3">
6464
<statement>
6565
<p>Add a method <c>area</c> to the Rectangle class that returns the area of any instance:</p>
6666
<pre>r = Rectangle(Point(0, 0), 10, 5)
@@ -107,7 +107,7 @@ class Rectangle:
107107
</program>
108108
</solution>
109109
</exercise>
110-
<exercise xml:id="ch_cl2_q4">
110+
<exercise label="ch_cl2_q4">
111111
<statement>
112112
<p>Write a <c>perimeter</c> method in the Rectangle class so that we can find
113113
the perimeter of any rectangle instance:</p>
@@ -120,7 +120,7 @@ test(r.perimeter(), 30)</pre>
120120
</input>
121121
</program>
122122
</exercise>
123-
<exercise xml:id="ch_cl2_q5">
123+
<exercise label="ch_cl2_q5">
124124
<statement>
125125
<p>Write a <c>transpose</c> method in the Rectangle class that swaps the width
126126
and the height of any rectangle instance:</p>
@@ -174,7 +174,7 @@ class Rectangle:
174174
</program>
175175
</solution>
176176
</exercise>
177-
<exercise xml:id="ch_cl2_q6">
177+
<exercise label="ch_cl2_q6">
178178
<statement>
179179
<p>Write a new method in the Rectangle class to test if a Point falls within
180180
the rectangle. For this exercise, assume that a rectangle at (0,0) with
@@ -196,7 +196,7 @@ test(r.contains(Point(-3, -3)), False)</pre>
196196
</input>
197197
</program>
198198
</exercise>
199-
<exercise xml:id="ch_cl2_q7">
199+
<exercise label="ch_cl2_q7">
200200
<statement>
201201
<p>Write a new method called <c>diagonal</c> that will return the length of the diagonal that runs
202202
from the lower left corner to the opposite corner.</p>
@@ -244,7 +244,7 @@ class Rectangle:
244244
</program>
245245
</solution>
246246
</exercise>
247-
<exercise xml:id="ch_cl2_q8">
247+
<exercise label="ch_cl2_q8">
248248
<statement>
249249
<p>In games, we often put a rectangular <q>bounding box</q> around our sprites in
250250
the game. We can then do <em>collision detection</em> between, say, bombs and

pretext/Debugging/HowtoAvoidDebugging.ptx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ print(final_time)
6666
</input>
6767
</program>
6868
<p>Hmm, when you run this example you see that something unexpected has happened. You would not realize this was an error unless you first knew what the program was supposed to do.</p>
69-
<exercise xml:id="db_q_ex3_1">
69+
<exercise label="db_q_ex3_1">
7070
<statement>
7171
<p>Which of the following best describes what is wrong with the previous example?</p>
7272
</statement>

pretext/Debugging/KnowyourerrorMessages.ptx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ print(final_time_int)
3434
Python interpreter. The interpreter in activecode is limited in many ways, but it is intended for beginners,
3535
including the wording chosen to describe errors.</p>
3636
</note>
37-
<exercise xml:id="db_qex32">
37+
<exercise label="db_qex32">
3838
<statement>
3939
<p>Which of the following explains why <c>wait_time_int = int(wait_time_int)</c> is an error?</p>
4040
</statement>

0 commit comments

Comments
 (0)