vatlab / sos-notebook

Multi-language Jupyter Notebook
http://vatlab.github.io/SoS
BSD 3-Clause "New" or "Revised" License
177 stars 17 forks source link

Selenium tests fail after separating magics #210

Closed BoPeng closed 5 years ago

BoPeng commented 5 years ago

After I separate the test_magics test into tests for each magic (eg. here, each individual test passes but overall only the first test passes, and all others fail with a time out error. It seems that each test needs to conclude in some way.

BoPeng commented 5 years ago

@jma7 Please have a look. Note that I changed your add_cell_and_execute_cell_in_kernel to append_cell_and_execute_cell_in_kernel without the cell index so that the cell will always be added to the end of notebook. This allows tests to be run in any other without fixed indexes.

BoPeng commented 5 years ago

Also, I do not understand why this test passes, but fails if I change

command = "sosa = '24' "

to

command = "sosa = f'{24}'"

I doubt that is something wrong with Python3 kernel, but the command works fine outside of selenium.

BoPeng commented 5 years ago

The error message for the first cell is

File "<ipython-input-1-a279d06a4059>", line 1
    sosa = f'{24}' '
                    ^
SyntaxError: EOL while scanning string literal

so for whatever reason an extra quote was added to command.

BoPeng commented 5 years ago

The split version is moved to split_test branch, but the master still fails after merging the tests.

I think it is important to first figure out why

sosa = f'{24}' 

fails to execute in Python 3 kernel.

jma7 commented 5 years ago

Just want to let you know that in conftest.py, if you change

elif os.environ.get('JUPYTER_TEST_BROWSER') == 'chrome':
        #driver = Chrome()
        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_argument('--no-sandbox')
        chrome_options.add_argument('--window-size=1420,1080')
        chrome_options.add_argument('--headless')
        chrome_options.add_argument('--disable-gpu')
        driver = Chrome(options=chrome_options)

to

elif os.environ.get('JUPYTER_TEST_BROWSER') == 'chrome':
        driver = Chrome()

You could see the actions in real browser to get some ideas of what went wrong.

In test_magic_expand, an extra curly brace was inserted at the end, I have to remove the right curly brace in the content to get the correct expression, don't know why.

idx = notebook.append_and_execute_cell_in_kernel(content=dedent("""\
            %expand ${ }
            if (${par} > 50) {
                cat('A parameter ${par} greater than 50 is specified.');
            """), kernel="R")

In test_magic_preview

command="%preview -n a \na = [1, 2, 3] "

This line gives error.

BoPeng commented 5 years ago

Good suggestion! The extra brace thing might also explain why a = f'{24}' becomes a=f'{24}' '.

jma7 commented 5 years ago

I tried

sosa = f'{3*8}'''

The f string got executed without error, so you might use this as a temporary fix. I still don't know what causes the extra quote. I tried to send sosa=f'{24}' to original notebook cell, the extra quote was still added. So I suspect the problem is in selenium.

BoPeng commented 5 years ago

If you can execute JS code, you can use something like IPython.notebook.get_cell(idx).set_text() to set text to cell directly...

jma7 commented 5 years ago
self.browser.execute_script("IPython.notebook.get_cell("+str(index)+").set_text("+repr(content)+")")

This seems working.

BoPeng commented 5 years ago

Good. Let me test.

BoPeng commented 5 years ago

Great. It seems to be working all right. Thanks!