Simplify pyrepl.ts and kill base.ts#884
Conversation
We want to run the most basic tests first: so first we check that we can print(), and only later we test the behavior of display(), which is much more complex. Also, add a test to ensure that we can load&execute code which was typed inside the <py-repl> This simplifies the rest of the tests because we can put the code directly in the tag instead of having to use .type() all the times
…t. Write a test and its fix
…we format it incorrectly
…ated expression, as you would expect by a REPL
…he output ID doesn't exist
…e old code, they are too hard to fix and they were not really testing anything useful
| editorLabel.setAttribute('style', labelStyle); | ||
| editorLabel.htmlFor = 'code-editor'; | ||
| boxDiv.append(editorLabel); | ||
| boxDiv.appendChild(editorDiv); |
There was a problem hiding this comment.
So, this means we always create the output div, even if we have an explicit output attribute?
There was a problem hiding this comment.
yes, I did it intentionally because it simplify handling the case in which output=... points to a non-existent ID:
pyscript/pyscriptjs/src/components/pyrepl.ts
Lines 187 to 191 in 02ca665
I think that an empty div should not cause problems, does it?
There was a problem hiding this comment.
I don't think it does and I'm probably too picky here. It just leaves an unused empty tag which I don't think is a big deal.
|
I know this PR is WIP but thought I'd leave early feedback. Great work ;) |
actually when you reviewed it it was almost ready, so you saw basically everything. But see the top message now, it's probably worth to look at two sets of commits separately. |
| @@ -8,61 +8,78 @@ class TestPyRepl(PyScriptTest): | |||
| def test_repl_loads(self): | |||
There was a problem hiding this comment.
This entire file looks good to me 👍
Should I review the rest too?
There was a problem hiding this comment.
This entire file looks good to me
🎉
Should I review the rest too?
reviews are always welcome :)
|
solid |
What is not tested is broken man_facepalming Test&fix <py-repl auto-generate=true> which was broken by PR #884
Yet another of my refactorings. This PR does two things which are related but also clearly separated, and probably it would have been better to make two different ones, but too late now.
I suggest reviewers to review the two parts separately, it is probably easier to understand what I did:
base.tsandpyreply.tsin the first 25 commits (from 9c225b2 to 0c661f5)BaseEvalElementwas used only by pyrepl now. By merging them I could simplify a lot the logic and kill a lot of code. In the process, I also improved and extented thepy-replintegration tests, to ensure that I didn't break anything.pyrepl.tsin the next 29 commits (from 0a9e19d to the end)this part of the PR doesn't change much of the concrete logic: it's just a sequence of renaming variables, moving code around, group code into functions, killing code which is no longer needed (you might also want to look at the commits one by one, every of them is self-contained and passed the tests). But the end result is much better and nicer to read, IMHO.
Other highlights:
pyexec.tsto run the code42and run it, it displayed nothing). This PR re-introduces this behavior, which is what you would expect by a REPL.--devoption: now it implies--no-fake-serverso that sourcemaps works automaticallyautogeneratefunctionality is untested. It should probably be improved/refactored by another PRA possibly controversial change:
pyrepl.test.ts: the old tests didn't check anything useful, just that some of the attributes existed on the instance, but after the refactoring I killed most of them and they were impossible to test in that way. I claim that this style of unit test doesn't really add much value if you have good integration tests (which now we have) and trying to revive them was not worth the hassle. This is the relevant commit: 8e8ed9c