Skip to content

Commit e8bd333

Browse files
authored
Merge pull request #11 from esciencecenter-digital-skills/fix-margins
Fix margins and text positioning in slides
2 parents a9ef599 + c2e2d0d commit e8bd333

File tree

3 files changed

+82
-135
lines changed

3 files changed

+82
-135
lines changed

modules/good-practices-lesson/documentation-slides.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ description: Day 3 Code Refinery
1414

1515
<!-- .slide: data-state="standard" -->
1616

17-
<img style="height: 550px;" src="./files/paint.png"/>
17+
<img style="height: 550px;" src="./media/documentation/paint.png"/>
1818

1919
===
2020

modules/good-practices-lesson/modular-code-slides.md

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ Simple components combined to produce complex behavior.
4747

4848
## What are these blocks/elements?
4949

50-
<div style="display: flex; justify-content: center; align-items: flex-start; margin-top: 20px;">
51-
<img src="./media/modular-code/building_blocks.png" alt="building blocks" height="200" style="margin-right: 20px;">
50+
<div style="display: flex; justify-content: center; align-items: flex-start; margin-top: 20px; max-width: 100%;">
51+
<img src="./media/modular-code/building_blocks.png" alt="building blocks" style="max-width: 40%; height: auto; margin-right: 20px;">
5252
<div>
5353
<ul>
5454
<li class="fragment" data-fragment-index="1">functions</li>
@@ -109,13 +109,16 @@ To allow reusability:
109109

110110
To facilitate scalability:
111111

112-
<img height="300" alt="scalability" src="./media/modular-code/scalability.png">
113-
112+
<div style="display: flex; align-items: center;">
114113

115-
<div>
114+
<img alt="scalability" src="./media/modular-code/scalability.png" style="max-width: 40%; height: auto; margin-right: 20px;">
116115

117-
- Complexity remains low by design.
118-
- This creates space for scaling up.
116+
<div>
117+
<ul>
118+
<li>Complexity remains low by design.</li>
119+
<li>This creates space for scaling up.</li>
120+
</ul>
121+
</div>
119122

120123
</div>
121124

@@ -127,7 +130,7 @@ To facilitate scalability:
127130

128131
To create opportunities for innovation:
129132

130-
<img height="300" alt="tetris shows innovation" src="./media/modular-code/tetris_innovation.png">
133+
<img alt="tetris shows innovation" src="./media/modular-code/tetris_innovation.png" style="max-width: 50%; height: auto;">
131134

132135
- Modules increase the capabilities and power of a project.
133136
- Rearrange old modules for new applications.
@@ -148,7 +151,7 @@ To save time:
148151
## A good module...
149152

150153
<div style="display: flex; justify-content: center; align-items: flex-start; margin-top: 20px;">
151-
<img src="./media/modular-code/units.png" alt="units" width="200" style="margin-right: 20px;">
154+
<img src="./media/modular-code/units.png" alt="units" width="300" style="margin-right: 20px;">
152155
<div>
153156
<ul>
154157
<li class="fragment" data-fragment-index="1">performs limited and clearly defined tasks</li>
@@ -168,7 +171,9 @@ To save time:
168171
- follow language specific conventions
169172
- avoid abbreviations
170173

171-
<img height="450" alt="naming" src="./media/modular-code/naming_stuff.jpg">
174+
<div style="text-align: center; margin-top: 20px;">
175+
<img alt="naming" src="./media/modular-code/naming_stuff.jpg" style="max-width: 100%; height: auto; max-height: 300px;">
176+
</div>
172177
<!-- .element: class="fragment" data-fragment-index="2" -->
173178

174179
===
@@ -178,7 +183,7 @@ To save time:
178183
## A good module...
179184

180185
<div style="display: flex; justify-content: center; align-items: flex-start; margin-top: 20px;">
181-
<img src="./media/modular-code/units.png" alt="units" width="200" style="margin-right: 20px;">
186+
<img src="./media/modular-code/units.png" alt="units" width="300" style="margin-right: 20px;">
182187
<div>
183188
<ul>
184189
<li>performs limited and clearly defined tasks</li>
@@ -219,7 +224,7 @@ indexAAG = getIndex(myList,'AAG')
219224
## A good module...
220225

221226
<div style="display: flex; justify-content: center; align-items: flex-start; margin-top: 20px;">
222-
<img src="./media/modular-code/units.png" alt="units" width="200" style="margin-right: 20px;">
227+
<img src="./media/modular-code/units.png" alt="units" width="300" style="margin-right: 20px;">
223228
<div>
224229
<ul>
225230
<li>performs limited and clearly defined tasks</li>
@@ -286,7 +291,7 @@ def fahrenheit_to_celsius(temp_list, converted_temps=None):
286291
## A good module...
287292

288293
<div style="display: flex; justify-content: center; align-items: flex-start; margin-top: 20px;">
289-
<img src="./media/modular-code/units.png" alt="units" width="200" style="margin-right: 20px;">
294+
<img src="./media/modular-code/units.png" alt="units" width="300" style="margin-right: 20px;">
290295
<div>
291296
<ul>
292297
<li>performs limited and clearly defined tasks</li>
@@ -304,7 +309,7 @@ def fahrenheit_to_celsius(temp_list, converted_temps=None):
304309
## Identifying opportunities for modularization
305310

306311
<div style="display: flex; justify-content: center; align-items: flex-start; margin-top: 20px;">
307-
<img src="./media/modular-code/testing_module.png" alt="testing a single module" width="200" style="margin-right: 20px;">
312+
<img src="./media/modular-code/testing_module.png" alt="testing a single module" width="300" style="margin-right: 20px;">
308313
<div>
309314
<ul>
310315
<li class="fragment" data-fragment-index="2">poor readability</li>
@@ -340,7 +345,7 @@ Modular code becomes more readable
340345
## Identifying opportunities for modularization
341346

342347
<div style="display: flex; justify-content: center; align-items: flex-start; margin-top: 20px;">
343-
<img src="./media/modular-code/testing_module.png" alt="testing a single module" width="200" style="margin-right: 20px;">
348+
<img src="./media/modular-code/testing_module.png" alt="testing a single module" width="300" style="margin-right: 20px;">
344349
<div>
345350
<ul>
346351
<li>poor readability</li>
@@ -359,7 +364,9 @@ Modular code becomes more readable
359364
- Identify functions units by their _action_
360365
- (e.g. "plot", "transform", "extract", "save")
361366

362-
<img height="350" alt="DRY" src="./media/modular-code/dry-vs-wet-code.jpg">
367+
<div style="text-align: center; margin-top: 20px;">
368+
<img alt="DRY" src="./media/modular-code/dry-vs-wet-code.jpg" style="max-width: 100%; height: auto; max-height: 300px;">
369+
</div>
363370

364371
===
365372

@@ -368,7 +375,7 @@ Modular code becomes more readable
368375
## Identifying opportunities for modularization
369376

370377
<div style="display: flex; justify-content: center; align-items: flex-start; margin-top: 20px;">
371-
<img src="./media/modular-code/testing_module.png" alt="testing a single module" width="200" style="margin-right: 20px;">
378+
<img src="./media/modular-code/testing_module.png" alt="testing a single module" width="300" style="margin-right: 20px;">
372379
<div>
373380
<ul>
374381
<li>poor readability</li>
@@ -432,7 +439,7 @@ sum_even_numbers (2,14) # 42
432439
## Identifying opportunities for modularization
433440

434441
<div style="display: flex; justify-content: center; align-items: flex-start; margin-top: 20px;">
435-
<img src="./media/modular-code/testing_module.png" alt="testing a single module" width="200" style="margin-right: 20px;">
442+
<img src="./media/modular-code/testing_module.png" alt="testing a single module" width="300" style="margin-right: 20px;">
436443
<div>
437444
<ul>
438445
<li>poor readability</li>
@@ -455,4 +462,7 @@ sum_even_numbers (2,14) # 42
455462
- Is the input/output clear?
456463
<!-- .element: class="fragment" data-fragment-index="3" -->
457464
- What can you not yet test? Extract it into a new module.
458-
<!-- .element: class="fragment" data-fragment-index="3" -->
465+
466+
467+
468+

modules/good-practices-lesson/testing-slides.md

Lines changed: 52 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Most modern programming languages have good options to streamline testing
117117

118118
## Testing metrics
119119

120-
#### Targets are arbitrary and indicative of but do not guarantee strong testing.
120+
#### Targets are arbitrary and indicative
121121

122122
<div style="display: flex; justify-content: center; align-items: center">
123123
<div>
@@ -141,178 +141,115 @@ Most modern programming languages have good options to streamline testing
141141
<img src="./media/testing/metrics.jpg" width="300" style="margin-left: 60px">
142142
</div>
143143

144-
145-
146-
===
147-
148-
<!-- .slide: data-state="standard" -->
149-
150-
## Misleading metrics
151-
152-
Consider this function...
153-
```python
154-
def fahrenheit_to_celsius(temp_list, converted_temps=[]):
155-
for temp in temp_list:
156-
temp_c = (temp - 32.0) * (5.0/9.0)
157-
converted_temps.append(temp_c)
158-
return converted_temps
159-
```
160-
161-
...and these tests with 100% coverage:
162-
<!-- .element: class="fragment" data-fragment-index="2" -->
163-
```python
164-
assert fahrenheit_to_celsius([32.0, 77.0]) == [0.0, 25.0]
165-
assert (fahrenheit_to_celsius([100], converted_temps = [0.0, 25.0])
166-
== [0.0, 25.0, 37.77777777777778])
167-
```
168-
<!-- .element: class="fragment" data-fragment-index="2" -->
169-
170-
Q: Can you think of a problem that will not be caught?
171-
<!-- .element: class="fragment" data-fragment-index="3" -->
172-
173144
===
174145

175146
<!-- .slide: data-state="standard" -->
176147

148+
## Write Code
177149

178-
## Writing a test file
179-
180-
Create a file called test_example.py ...
181150
<pre><code class="bash" style="overflow: hidden;" data-trim class="bash" data-line-numbers>
182151
$ mkdir pytest-example
183152
$ cd pytest-example
184-
$ nano test_example.py
185153
</code></pre>
186154

187155
<div class="fragment">
188-
... and add the function and tests from before:
156+
Creating a file <code>example.py</code> containing
189157
<pre><code class="python" style="overflow: hidden;" data-trim class="bash" data-line-numbers>
190-
def fahrenheit_to_celsius(temp_list, converted_temps=[]):
191-
for temp in temp_list:
192-
temp_c = (temp - 32.0) * (5.0/9.0)
193-
converted_temps.append(temp_c)
194-
return converted_temps
158+
def add(a, b):
159+
return a + b
195160
&nbsp;
196161
&nbsp;
197-
def test_convert(): # Special name!
198-
assert fahrenheit_to_celsius([32.0, 77.0]) == [0.0, 25.0]
199-
assert (fahrenheit_to_celsius([100], converted_temps = [0.0, 25.0])
200-
== [0.0, 25.0, 37.77777777777778])
162+
def test_add(): # Special name!
163+
assert add(2, 3) == 5 # What's `assert`? 🤔
164+
assert add('space', 'ship') == 'spaceship'
201165
</code></pre>
202166
</div>
203167

204-
===
168+
<div class="fragment">
169+
Chat with the python shell about <code>assert</code> ...
170+
</div>
171+
<div class="fragment">
172+
<pre><code class="python" style="overflow: hidden;" data-trim class="bash" data-line-numbers>
173+
>>> assert 1==1 # passes
174+
>>> assert 1==2 # throws error
175+
Traceback (most recent call last):
176+
File "&lt;stdin&gt;", line 1, in &lt;module&gt;
177+
AssertionError
178+
</code></pre>
205179

206-
<!-- .slide: data-state="standard" -->
180+
</div>
207181

208-
## Running Pytest
182+
===
209183

210-
The `pytest` command will run all functions starting with "test_" from all files starting with "test_".
184+
<!-- .slide: data-state="standard" -->
211185

186+
## Test!
212187

213-
<pre class="fragment"><code style="overflow: hidden;" data-trim class="bash" data-line-numbers="1|1-9">
214-
$ pytest
188+
<pre><code style="overflow: hidden;" data-trim class="bash" data-line-numbers="1|1-9">
189+
$ pytest example.py
215190
======================== test session starts ========================
216191
platform linux -- Python 3.6.9, pytest-7.0.1, pluggy-1.0.0
217192
rootdir: /home/ole/Desktop/pytest-texample
218193
collected 1 item
219194

220-
test_example.py . [100%]
195+
example.py . [100%]
221196

222197
========================= 1 passed in 0.00s =========================
223198
</code></pre>
224199

225-
226200
===
227201

228202
<!-- .slide: data-state="standard" -->
229203

230-
## Pytest Exercise
231-
232-
1. Add a test to catch "problematic" behavior of the function.
233-
- don't fix the function (yet)
234-
2. Run pytest to see what the response looks like.
235-
- what information can you gather from the response?
236-
3. Fix the function and rerun the test
204+
## Breaking Things
237205

238-
<div>
239206
<pre><code class="python" style="overflow: hidden;" data-trim class="bash" data-line-numbers>
240-
def fahrenheit_to_celsius(temp_list, converted_temps=[]):
241-
for temp in temp_list:
242-
temp_c = (temp - 32.0) * (5.0/9.0)
243-
converted_temps.append(temp_c)
244-
return converted_temps
245-
&nbsp;
246-
&nbsp;
247-
def test_convert():
248-
assert fahrenheit_to_celsius([32.0, 77.0]) == [0.0, 25.0]
249-
assert (fahrenheit_to_celsius([100], converted_temps = [0.0, 25.0])
250-
== [0.0, 25.0, 37.77777777777778])
251-
</code></pre>
252-
</div>
253-
254-
===
255-
256-
<!-- .slide: data-state="standard" -->
207+
def add(a, b):
208+
return a - b # Uh oh, mistake! 😱
257209

258-
## Breaking the test
259210

260-
1. Add a test to catch problematic behavior of the function.
261-
262-
<div class="fragment">
263-
<pre><code class="python" style="overflow: hidden;" data-trim class="bash" data-line-numbers="1-11|12">
264-
def fahrenheit_to_celsius(temp_list, converted_temps=[]):
265-
for temp in temp_list:
266-
temp_c = (temp - 32.0) * (5.0/9.0)
267-
converted_temps.append(temp_c)
268-
return converted_temps
269-
&nbsp;
270-
&nbsp;
271-
def test_convert():
272-
assert fahrenheit_to_celsius([32.0, 77.0]) == [0.0, 25.0]
273-
assert (fahrenheit_to_celsius([100], converted_temps = [0.0, 25.0])
274-
== [0.0, 25.0, 37.77777777777778])
275-
assert fahrenheit_to_celsius([32.0, 77.0]) == [0.0, 25.0]
211+
def test_add():
212+
assert add(2, 3) == 5
213+
assert add('space', 'ship') == 'spaceship'
276214
</code></pre>
277-
</div>
278215

279216
===
280217

281218
<!-- .slide: data-state="standard" -->
282219

283-
## Failing tests
220+
## Testing Again
284221

285-
<pre style="width: 100%; max-width: 1200px; overflow: auto;"><code style="overflow: hidden;" data-trim class="bash" data-line-numbers="1|2-8|9-22|23-26">
222+
<pre><code style="overflow: hidden;" data-trim class="bash" data-line-numbers="1|2-8|9-17|18-20">
286223
$ pytest example.py
287224
======================== test session starts =========================
288225
platform linux -- Python 3.6.9, pytest-7.0.1, pluggy-1.0.0
289226
rootdir: /home/ole/Desktop/pytest-texample
290227
collected 1 item
291228

292-
test_example.py F [100%]
229+
example.py F [100%]
293230

294231
============================== FAILURES ==============================
295-
______________________________ test_convert ______________________________
296-
297-
def test_convert(): # Special name!
298-
assert fahrenheit_to_celsius([32.0, 77.0]) == [0.0, 25.0]
299-
assert (fahrenheit_to_celsius([100], converted_temps = [0.0, 25.0])
300-
== [0.0, 25.0, 37.77777777777778])
301-
> assert fahrenheit_to_celsius([32.0, 77.0]) == [0.0, 25.0]
302-
E assert [0.0, 25.0, 0.0, 25.0] == [0.0, 25.0]
303-
E
304-
E Left contains 2 more items, first extra item: 0.0
305-
E Use -v to get more diff
306-
307-
test_example.py:11: AssertionError
308-
============================= short test summary info =============================
309-
FAILED test_example.py::test_convert - assert [0.0, 25.0, 0.0, 25.0] == [0.0, 25.0]
310-
================================ 1 failed in 0.67s ================================
311-
&nbsp;
232+
______________________________ test_add ______________________________
233+
234+
def test_add():
235+
> assert add(2, 3) == 5
236+
E assert -1 == 5
237+
E + where -1 = add(2, 3)
238+
239+
example.py:6: AssertionError
240+
====================== short test summary info =======================
241+
FAILED example.py::test_add - assert -1 == 5
242+
========================= 1 failed in 0.05s ==========================
312243
</code></pre>
313244

245+
<ul>
246+
<li class="fragment">🚀❓<span class="fragment">Functions fail on first error</span></li>
247+
<li class="fragment">But all test functions are executed</li>
248+
</ul>
249+
314250
===
315251

252+
316253
<!-- .slide: data-state="standard" -->
317254

318255
## Pytest wrap up

0 commit comments

Comments
 (0)