<jupyter_start><jupyter_text>Test JulynterThis is a simple notebook that uses selenium to check whether all lints appear in an external notebook. I made it because of the effort of manually checking all messages, but I didn't do as proper tests to avoid the effort of detecting elements appearing. As a notebook, I can run at the right pace.Before running this notebook, there are some required steps:1- Create a folder and move into the folder: `mkdir temp; cd temp`2- Run jupyter lab externally (preferably in a clean environment with a fresh installation of Julynter): `jupyter lab`3- Check the URL and replace the `URL` variable below to use the proper tokenNow you can run this notebook cell by cell<jupyter_code>from contextlib import contextmanager
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains

URL = 'http://localhost:8888/?token=<PASSWORD>'
@contextmanager
def act(driver):
    actions = ActionChains(driver)
    try:
        yield actions
    finally:
        actions.perform()
def find_lints(driver, text):
    julynter_list = driver.find_element_by_css_selector('.jp-Julynter-content')
    return julynter_list.find_elements_by_xpath(
        '//div[contains(@class, "julynter-report-prompt")]/div[contains(., {!r})]'.format(text))
def reload_lints(driver):
    driver.find_element_by_css_selector('.julynter-title').click()
def alt_enter(actions):
    actions.key_down(Keys.ALT).send_keys(Keys.ENTER).key_up(Keys.ALT)
def shift_enter(actions):
    actions.key_down(Keys.SHIFT).send_keys(Keys.ENTER).key_up(Keys.SHIFT)
def write(driver, text, execute=True, before=""):
    with act(driver) as actions:
        if before:
            actions.send_keys(before)
        actions.send_keys(text)
        if execute:
            alt_enter(actions)

driver = webdriver.Firefox()
driver.get(URL)
side_bar = driver.find_element_by_css_selector('.jp-SideBar')
launcher = driver.find_element_by_css_selector('[title="New Launcher"]')
if not launcher.is_displayed():
    side_bar.find_element_by_css_selector('[title="File Browser (Ctrl+Shift+F)"]').click()
driver.find_element_by_css_selector('[title="New Launcher"]').click()
driver.find_element_by_css_selector('.p-DockPanel-widget:not(.lm-mod-hidden) [title="Python 3"]').click()
side_bar.find_element_by_css_selector('[title="Julynter"]').click()
# T2
title_lints = find_lints(driver, 'Title starts with "Untitled"')
assert len(title_lints) > 0
title_lints[0].click()
with act(driver) as actions:
    actions.send_keys(Keys.BACKSPACE + Keys.ENTER)
reload_lints(driver)
reload_lints(driver)
# T1
assert len(find_lints(driver, 'Title is empty')) > 0
# T7
title_lints = find_lints(driver, 'Title is too small')
assert len(title_lints) > 0
title_lints[0].click()
with act(driver) as actions:
    actions.send_keys("ã single title to rule them all but bigger better and stronger and even bigger so i dont know how big is too big-Copy.ipynb" + Keys.ENTER)

reload_lints(driver)
# T3, T4, T5, T6
assert len(find_lints(driver, 'Title has "-Copy"')) > 0
assert len(find_lints(driver, 'Title has blank spaces')) > 0
assert len(find_lints(driver, 'Title has special characters')) > 0
assert len(find_lints(driver, 'Title is too big')) > 0
find_lints(driver, 'Title is too big')[0].click()
with act(driver) as actions:
    actions.send_keys("NormalTitle" + Keys.ENTER)

reload_lints(driver)
# c4
lints = find_lints(driver, 'The first cell of the notebook is not a markdown cell')
assert len(lints) > 0
lints[0].click()
with act(driver) as actions:
    actions.send_keys(Keys.ESCAPE + "m" + Keys.ENTER)
reload_lints(driver)
driver.find_element_by_css_selector(':not(.lm-mod-hidden) .jp-Notebook').click()
write(driver, "title", before=Keys.ENTER)
write(driver, "if False:\nunknown")
# h6
assert len(find_lints(driver, "Cell 1 has the following undefined names: 'unknown'")) > 0
# c5
assert len(find_lints(driver, "The last cell of the notebook is not a markdown cell")) > 0
with act(driver) as actions:
    actions.send_keys(Keys.ESCAPE + "m" + Keys.ENTER)
reload_lints(driver)
write(driver, "templast")
write(driver, "a = 1", execute=False)
with act(driver) as actions:
    actions.send_keys(Keys.ESCAPE + "b" + Keys.ENTER)
reload_lints(driver)
write(driver, "b = 1")
# c1
assert len(find_lints(driver, "Cell 3 is a non-executed cell among executed ones")) > 0
write(driver, "")
write(driver, "c = b")
# c3
assert len(find_lints(driver, "Cell 5 is empty in the middle of the notebook")) > 0
with act(driver) as actions:
    actions.send_keys(Keys.ESCAPE + Keys.UP + Keys.UP + Keys.UP + Keys.UP + Keys.ENTER)
    shift_enter(actions)
    shift_enter(actions)
    actions.send_keys("dd")
reload_lints(driver)
# c2
assert len(find_lints(driver, "Cell 5 has the execution count 3 in the wrong order")) > 0
# h5
assert len(find_lints(driver, "Cell 5 uses name 'b' that was defined on In[2], but it does not exist anymore")) > 0
# h4
assert len(find_lints(driver, "Cell 5 skips the execution count")) > 0
with act(driver) as actions:
    actions.send_keys(Keys.TAB)
driver.find_element_by_css_selector(':not(.lm-mod-hidden) .jp-Notebook').click()
with act(driver) as actions:
    actions.send_keys(Keys.ENTER)
with act(driver) as actions:
    actions.send_keys(" + 1" + Keys.ESCAPE + Keys.UP)

# h2
lints = find_lints(driver, "Cell 5 has changed since its execution, but it wasn't executed after the changes")
assert len(lints) > 0

with act(driver) as actions:
    actions.send_keys(Keys.DOWN)
    shift_enter(actions)
write(driver, "import julynter", before=Keys.ENTER)
reload_lints(driver)
# i1
assert len(find_lints(driver, "Cell 6 has imports but it is not the first cell")) > 0
# i2
assert len(find_lints(driver, "Module julynter was imported by Cell 6, but it is not in the requirements file")) > 0
driver.find_element_by_css_selector(':not(.lm-mod-hidden) .jp-Notebook').click()
write(driver, "temp = '/usr/bin'", before=Keys.ENTER)
reload_lints(driver)
# p1
assert len(find_lints(driver, "Cell 7 has the following absolute paths: '/usr/bin'")) > 0
driver.find_element_by_css_selector(':not(.lm-mod-hidden) .jp-Notebook').click()
with act(driver) as actions:
    actions.send_keys(Keys.ESCAPE + "00")
with act(driver) as actions:
    actions.send_keys(Keys.ENTER)
reload_lints(driver)
# h1
assert len(find_lints(driver, "Cell 1 has execution results, but it wasn't executed on this session")) > 0
driver.find_element_by_css_selector(':not(.lm-mod-hidden) .jp-Notebook').click()
with act(driver) as actions:
    actions.send_keys(Keys.ESCAPE + Keys.UP + Keys.UP)
with act(driver) as actions:
    shift_enter(actions)
reload_lints(driver)
# h3
assert len(find_lints(driver, "Cell 7 repeats the execution count 1")) > 0
driver.find_element_by_css_selector(':not(.lm-mod-hidden) .jp-Notebook').click()
# Cleanup
write(driver, "!rm NormalTitle.ipynb", before=Keys.ENTER)
with act(driver) as actions:
    actions.key_down(Keys.ALT).send_keys("W").key_up(Keys.ALT)
with act(driver) as actions:
    actions.send_keys(Keys.LEFT + Keys.ENTER)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12552772305094287, 'fraction_numerical': 0.010413734871939206, 'mean_word_length': 5.373991031390134, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '355553', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 2475, 'n_tokens_neox': 2369, 'n_words': 661, 'path': 'tests/TestJulynterUsingSelenium.ipynb', 'repo_name': 'dew-uff/julynter', 'size': '7144'}