LOST-STATS/lost-stats.github.io

Code samples which don't pass tests

Closed this issue · 9 comments

There are a few code samples which don't quite work. For Python, they are here. For R they are here.

Likely reasons for breaking

Split blocks

Most likely, this is because code samples are split by text. For example, if the Markdown looked like this:

Set _x_ to 1.

```r
x <- 1
```

Then add 1 to it.

```r
x <- x + 1
```

In this case, x is not defined in the second code block. To fix this, you can name the code block, e.g.,

Set _x_ to 1.

```r?example=simple
x <- 1
```

Then add 1 to it.

```r?example=simple
x <- x + 1
```

The code tester will gather each of these code blocks together and run them sequentially.

Examples that aren't meant to work

There are a few examples where the example isn't literally meant to work. For example,

```python
import pandas as pd

df = pd.read_csv("name_of_file")
```

In this case, "name_of_file" is obviously a placeholder for the path to the file. But the code doesn't literally work, so it will cause a failure.

As a solution, you can indicate you want the system to skip it:

```python?skip=true&skipReason=file_does_not_exist
import pandas as pd

df = pd.read_csv("name_of_file")
```

Here note that we added ?skip=true, which tells the test runner to ignore the test. We also add &skipReason=file_does_not_exist, which is just an optional explanation for why we are skipping the test.

Rerunning the tests

If you are fixing these locally, you can (if you have python, poetry, and docker installed) run the tests locally with:

poetry install
poetry run py.test -n 4

Alternatively, you can rerun the tests on Github by:

  • Clicking the Actions tab
  • Choose Run monthly [python|r] tests
  • Find the Run workflow button
  • And then click Run workflow

I'm planning to go through and fix a bunch of chunks once the tests rerun so all the fixed ones are out of the way

Want to merge #124 and then I can start the test runners again? (Or you can see if the above instructions are sufficient. :-) )

Oops, I thought that one already got merged!

I should have kept reading - I don't have docker or poetry so I didn't think I could rerun the rests. But of course they can be run on GitHub directly. I'll do that.

Nice. Seems like the test runners are running for you! They take a little time because the docker images are a wee bit large to download (should see if there's some way to cache those) but should be done in like 10 min.

As of 5bd2832 all R code samples are working or set not to run, and the tests pass.

🙌 Amazing!! I've verified locally as well.

Reopening this issue so that it will be easily accessible in the highly likely instance that there are code examples that don't work in the futrue.

Closing this since it's now incorporated into the New Page Template 4a4d520