How to use _get_metadata method in stestr

Best Python code snippet using stestr_python

test_create_assignment.py

Source:test_create_assignment.py Github

copy

Full Screen

...154 $($(".nbgrader-id-input")[{}]).val("{}").change().blur();155 """.format(index, cell_id)156 )157 browser.find_elements_by_css_selector(".nbgrader-cell")[index].click()158def _get_metadata(browser):159 return browser.execute_script(160 """161 var cell = Jupyter.notebook.get_cell(0);162 return cell.metadata.nbgrader;163 """164 )165def _get_total_points(browser):166 element = browser.find_element_by_id("nbgrader-total-points")167 return float(element.get_attribute("value"))168def _save(browser):169 browser.execute_script(dedent(170 """171 Jupyter._notebook_saved = false;172 Jupyter.notebook.save_notebook().then(function () {173 Jupyter._notebook_saved = true;174 });175 """176 ))177 def is_saved(browser):178 return browser.execute_script(dedent(179 """180 if (Jupyter._notebook_saved === true) {181 Jupyter._notebook_saved = false;182 return true;183 } else {184 return false;185 }186 """187 ))188 return is_saved189def _save_and_validate(browser):190 _wait(browser).until(_save(browser))191 read("blank.ipynb", current_nbformat)192def _wait_for_modal(browser):193 _wait(browser).until(194 EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".modal-dialog")))195def _dismiss_modal(browser):196 button = browser.find_element_by_css_selector(".modal-footer .btn-primary")197 button.click()198 def modal_gone(browser):199 try:200 browser.find_element_by_css_selector(".modal-dialog")201 except NoSuchElementException:202 return True203 return False204 _wait(browser).until(modal_gone)205def _save_screenshot(browser):206 browser.save_screenshot(os.path.join(os.path.dirname(__file__), "selenium.screenshot.png"))207@pytest.mark.nbextensions208def test_manual_cell(browser, port):209 _load_notebook(browser, port)210 _activate_toolbar(browser)211 # does the nbgrader metadata exist?212 assert _get_metadata(browser) is None213 # make it manually graded214 _select_manual(browser)215 assert _get_metadata(browser)['solution']216 assert _get_metadata(browser)['grade']217 assert not _get_metadata(browser)['locked']218 # wait for the points and id fields to appear219 _wait(browser).until(220 EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".nbgrader-points-input")))221 _wait(browser).until(222 EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".nbgrader-id-input")))223 # set the points224 _set_points(browser)225 assert 2 == _get_metadata(browser)['points']226 # set the id227 assert _get_metadata(browser)['grade_id'].startswith("cell-")228 _set_id(browser)229 assert "foo" == _get_metadata(browser)['grade_id']230 # make sure the metadata is valid231 _save_and_validate(browser)232 # make it nothing233 _select_none(browser)234 assert not _get_metadata(browser)235 _save_and_validate(browser)236@pytest.mark.nbextensions237def test_task_cell(browser, port):238 _load_notebook(browser, port, name='task')239 _activate_toolbar(browser)240 # does the nbgrader metadata exist?241 assert _get_metadata(browser) is None242 # make it manually graded243 _select_task(browser)244 assert _get_metadata(browser)['task']245 assert not _get_metadata(browser)['solution']246 assert not _get_metadata(browser)['grade']247 assert _get_metadata(browser)['locked']248 # wait for the points and id fields to appear249 _wait(browser).until(250 EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".nbgrader-points-input")))251 _wait(browser).until(252 EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".nbgrader-id-input")))253 # set the points254 _set_points(browser)255 assert 2 == _get_metadata(browser)['points']256 # set the id257 assert _get_metadata(browser)['grade_id'].startswith("cell-")258 _set_id(browser)259 assert "foo" == _get_metadata(browser)['grade_id']260 # make sure the metadata is valid261 _save_and_validate(browser)262 # make it nothing263 _select_none(browser)264 assert not _get_metadata(browser)265 _save_and_validate(browser)266@pytest.mark.nbextensions267def test_solution_cell(browser, port):268 _load_notebook(browser, port)269 _activate_toolbar(browser)270 # does the nbgrader metadata exist?271 assert _get_metadata(browser) is None272 # make it a solution cell273 _select_solution(browser)274 assert _get_metadata(browser)['solution']275 assert not _get_metadata(browser)['grade']276 assert not _get_metadata(browser)['locked']277 # wait for the id field to appear278 _wait(browser).until(279 EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".nbgrader-id")))280 # set the id281 assert _get_metadata(browser)['grade_id'].startswith("cell-")282 _set_id(browser)283 assert "foo" == _get_metadata(browser)['grade_id']284 # make sure the metadata is valid285 _save_and_validate(browser)286 # make it nothing287 _select_none(browser)288 assert not _get_metadata(browser)289 _save_and_validate(browser)290@pytest.mark.nbextensions291def test_tests_cell(browser, port):292 _load_notebook(browser, port)293 _activate_toolbar(browser)294 # does the nbgrader metadata exist?295 assert _get_metadata(browser) is None296 # make it autograder tests297 _select_tests(browser)298 assert not _get_metadata(browser)['solution']299 assert _get_metadata(browser)['grade']300 assert _get_metadata(browser)['locked']301 # wait for the points and id fields to appear302 _wait(browser).until(303 EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".nbgrader-points")))304 _wait(browser).until(305 EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".nbgrader-id")))306 WebDriverWait(browser, 30).until(307 EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".lock-button")))308 # set the points309 _set_points(browser)310 assert 2 == _get_metadata(browser)['points']311 # set the id312 assert _get_metadata(browser)['grade_id'].startswith("cell-")313 _set_id(browser)314 assert "foo" == _get_metadata(browser)['grade_id']315 # make sure the metadata is valid316 _save_and_validate(browser)317 # make it nothing318 _select_none(browser)319 assert not _get_metadata(browser)320 _save_and_validate(browser)321@pytest.mark.nbextensions322def test_tests_to_solution_cell(browser, port):323 _load_notebook(browser, port)324 _activate_toolbar(browser)325 # does the nbgrader metadata exist?326 assert _get_metadata(browser) is None327 # make it autograder tests328 _select_tests(browser)329 assert not _get_metadata(browser)['solution']330 assert _get_metadata(browser)['grade']331 assert _get_metadata(browser)['locked']332 # wait for the points and id fields to appear333 _wait(browser).until(334 EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".nbgrader-points")))335 _wait(browser).until(336 EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".nbgrader-id")))337 WebDriverWait(browser, 30).until(338 EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".lock-button")))339 # set the points340 _set_points(browser)341 assert 2 == _get_metadata(browser)['points']342 # set the id343 assert _get_metadata(browser)['grade_id'].startswith("cell-")344 _set_id(browser)345 assert "foo" == _get_metadata(browser)['grade_id']346 # make sure the metadata is valid347 _save_and_validate(browser)348 # make it a solution cell and make sure the points are gone349 _select_solution(browser)350 assert _get_metadata(browser)['solution']351 assert not _get_metadata(browser)['grade']352 assert not _get_metadata(browser)['locked']353 assert 'points' not in _get_metadata(browser)354 _save_and_validate(browser)355 # make it nothing356 _select_none(browser)357 assert not _get_metadata(browser)358 _save_and_validate(browser)359@pytest.mark.nbextensions360def test_locked_cell(browser, port):361 _load_notebook(browser, port)362 _activate_toolbar(browser)363 # does the nbgrader metadata exist?364 assert _get_metadata(browser) is None365 # make it locked366 _select_locked(browser)367 assert not _get_metadata(browser)['solution']368 assert not _get_metadata(browser)['grade']369 assert _get_metadata(browser)['locked']370 # wait for the id and lock button to appear371 WebDriverWait(browser, 30).until(372 EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".nbgrader-id")))373 WebDriverWait(browser, 30).until(374 EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".lock-button")))375 # set the id376 assert _get_metadata(browser)['grade_id'].startswith("cell-")377 _set_id(browser)378 assert "foo" == _get_metadata(browser)['grade_id']379 # make sure the metadata is valid380 _save_and_validate(browser)381 # make it nothing382 _select_none(browser)383 assert not _get_metadata(browser)384 _save_and_validate(browser)385@pytest.mark.nbextensions386def test_grade_cell_css(browser, port):387 _load_notebook(browser, port)388 _activate_toolbar(browser)389 # make it manually graded390 _select_manual(browser)391 elements = browser.find_elements_by_css_selector(".nbgrader-cell")392 assert len(elements) == 1393 # make it nothing394 _select_none(browser)395 elements = browser.find_elements_by_css_selector(".nbgrader-cell")396 assert len(elements) == 0397 # make it a solution398 _select_solution(browser)399 elements = browser.find_elements_by_css_selector(".nbgrader-cell")400 assert len(elements) == 1401 # make it nothing402 _select_none(browser)403 elements = browser.find_elements_by_css_selector(".nbgrader-cell")404 assert len(elements) == 0405 # make it autograder tests406 _select_tests(browser)407 elements = browser.find_elements_by_css_selector(".nbgrader-cell")408 assert len(elements) == 1409 # make it nothing410 _select_none(browser)411 elements = browser.find_elements_by_css_selector(".nbgrader-cell")412 assert len(elements) == 0413 # make it autograder tests414 _select_tests(browser)415 elements = browser.find_elements_by_css_selector(".nbgrader-cell")416 assert len(elements) == 1417 # deactivate the toolbar418 _activate_toolbar(browser, "None")419 elements = browser.find_elements_by_css_selector(".nbgrader-cell")420 assert len(elements) == 0421 # activate the toolbar422 _activate_toolbar(browser)423 elements = browser.find_elements_by_css_selector(".nbgrader-cell")424 assert len(elements) == 1425 # deactivate the toolbar426 _activate_toolbar(browser, "Edit%20Metadata")427 elements = browser.find_elements_by_css_selector(".nbgrader-cell")428 assert len(elements) == 0429@pytest.mark.nbextensions430def test_tabbing(browser, port):431 _load_notebook(browser, port)432 _activate_toolbar(browser)433 def active_element_is(class_name):434 def waitfor(browser):435 elem = browser.execute_script("return document.activeElement")436 return elem.get_attribute("class") == class_name437 return waitfor438 # make it manually graded439 _select_manual(browser)440 # click the id field441 element = browser.find_element_by_css_selector(".nbgrader-points-input")442 # There is a bug where sometimes the click doesn't register, so we also press enter443 # here which for some reason seems to help. It's not clear here what's happening444 # to cause this bug but see https://github.com/mozilla/geckodriver/issues/322 for445 # reference. It only seemed to be a problem on Linux, not Mac or Windows.446 element.click()447 element.send_keys(Keys.RETURN)448 _wait(browser).until(active_element_is("nbgrader-points-input"))449 # press tab and check that the active element is correct450 element.send_keys(Keys.TAB)451 _wait(browser).until(active_element_is("nbgrader-id-input"))452 # make it autograder tests453 _select_tests(browser)454 # click the id field455 element = browser.find_element_by_css_selector(".nbgrader-points-input")456 element.click()457 element.send_keys(Keys.RETURN)458 _wait(browser).until(active_element_is("nbgrader-points-input"))459 # press tab and check that the active element is correct460 element.send_keys(Keys.TAB)461 _wait(browser).until(active_element_is("nbgrader-id-input"))462@pytest.mark.nbextensions463def test_total_points(browser, port):464 _load_notebook(browser, port)465 _activate_toolbar(browser)466 # make sure the total points is zero467 assert _get_total_points(browser) == 0468 # make it autograder tests and set the points to two469 _select_tests(browser)470 _set_points(browser)471 _set_id(browser)472 assert _get_total_points(browser) == 2473 # make it manually graded474 _select_manual(browser)475 assert _get_total_points(browser) == 2476 # make it a solution make sure the total points is zero477 _select_solution(browser)478 assert _get_total_points(browser) == 0479 # make it autograder tests480 _select_tests(browser)481 assert _get_total_points(browser) == 0482 _set_points(browser)483 assert _get_total_points(browser) == 2484 # create a new cell485 element = browser.find_element_by_tag_name("body")486 element.send_keys(Keys.ESCAPE)487 element.send_keys("b")488 # make sure the toolbar appeared489 def find_toolbar(browser):490 try:491 browser.find_elements_by_css_selector(".celltoolbar select")[1]492 except IndexError:493 return False494 return True495 _wait(browser).until(find_toolbar)496 # make it a test cell497 _select_tests(browser, index=1)498 _set_points(browser, points=1, index=1)499 _set_id(browser, cell_id="bar", index=1)500 assert _get_total_points(browser) == 3501 # delete the new cell502 element = browser.find_elements_by_css_selector(".cell")[0]503 element.click()504 element.send_keys(Keys.ESCAPE)505 element.send_keys("d")506 element.send_keys("d")507 assert _get_total_points(browser) == 1508 # delete the first cell509 element = browser.find_elements_by_css_selector(".cell")[0]510 element.send_keys("d")511 element.send_keys("d")512 assert _get_total_points(browser) == 0513@pytest.mark.nbextensions514def test_task_total_points(browser, port):515 _load_notebook(browser, port, name='task')516 _activate_toolbar(browser)517 # make sure the total points is zero518 assert _get_total_points(browser) == 0519 # make it autograder tests and set the points to two520 _select_task(browser)521 _set_points(browser)522 _set_id(browser)523 assert _get_total_points(browser) == 2524 # make it manually graded525 _select_manual(browser)526 assert _get_total_points(browser) == 2527 # make it a none and make sure the total points is zero528 _select_none(browser)529 assert _get_total_points(browser) == 0530 # make it task531 _select_task(browser)532 assert _get_total_points(browser) == 0533 _set_points(browser)534 assert _get_total_points(browser) == 2535 # create a new cell536 element = browser.find_element_by_tag_name("body")537 element.send_keys(Keys.ESCAPE)538 element.send_keys("b")539 # make sure the toolbar appeared540 def find_toolbar(browser):541 try:542 browser.find_elements_by_css_selector(".celltoolbar select")[1]543 except IndexError:544 return False545 return True546 _wait(browser).until(find_toolbar)547 # make it a test cell548 _select_tests(browser, index=1)549 _set_points(browser, points=1, index=1)550 _set_id(browser, cell_id="bar", index=1)551 assert _get_total_points(browser) == 3552 # delete the new cell553 element = browser.find_elements_by_css_selector(".cell")[0]554 element.click()555 element.send_keys(Keys.ESCAPE)556 element.send_keys("d")557 element.send_keys("d")558 assert _get_total_points(browser) == 1559 # delete the first cell560 element = browser.find_elements_by_css_selector(".cell")[0]561 element.send_keys("d")562 element.send_keys("d")563 assert _get_total_points(browser) == 0564@pytest.mark.nbextensions565def test_cell_ids(browser, port):566 _load_notebook(browser, port)567 _activate_toolbar(browser)568 # turn it into a cell with an id569 _select_solution(browser)570 # for some reason only one call doesn't trigger on_change event571 _select_solution(browser)572 _set_id(browser, cell_id="")573 # save and check for an error (blank id)574 _save(browser)575 _wait_for_modal(browser)576 _dismiss_modal(browser)577 # set the label578 _set_id(browser)579 # create a new cell580 element = browser.find_element_by_tag_name("body")581 element.send_keys(Keys.ESCAPE)582 element.send_keys("b")583 # make sure the toolbar appeared584 def find_toolbar(browser):585 try:586 browser.find_elements_by_css_selector(".celltoolbar select")[1]587 except IndexError:588 return False589 return True590 _wait(browser).until(find_toolbar)591 # make it a test cell and set the label592 _select_tests(browser, index=1)593 _set_id(browser, index=1)594 # save and check for an error (duplicate id)595 _save(browser)596 _wait_for_modal(browser)597 _dismiss_modal(browser)598@pytest.mark.nbextensions599def test_task_cell_ids(browser, port):600 _load_notebook(browser, port, name='task')601 _activate_toolbar(browser)602 # turn it into a cell with an id603 _select_task(browser)604 _set_id(browser, cell_id="")605 # save and check for an error (blank id)606 _save(browser)607 _wait_for_modal(browser)608 _dismiss_modal(browser)609 # set the label610 _set_id(browser)611 # create a new cell612 element = browser.find_element_by_tag_name("body")613 element.send_keys(Keys.ESCAPE)614 element.send_keys("b")615 # make sure the toolbar appeared616 def find_toolbar(browser):617 try:618 browser.find_elements_by_css_selector(".celltoolbar select")[1]619 except IndexError:620 return False621 return True622 _wait(browser).until(find_toolbar)623 # make it a test cell and set the label624 _select_task(browser, index=1)625 _set_id(browser, index=1)626 # save and check for an error (duplicate id)627 _save(browser)628 _wait_for_modal(browser)629 _dismiss_modal(browser)630@pytest.mark.nbextensions631def test_negative_points(browser, port):632 _load_notebook(browser, port)633 _activate_toolbar(browser)634 # make sure the total points is zero635 assert _get_total_points(browser) == 0636 # make it autograder tests and set the points to two637 _select_tests(browser)638 _set_points(browser, points=2)639 _set_id(browser)640 assert _get_total_points(browser) == 2641 assert 2 == _get_metadata(browser)['points']642 # set the points to negative one643 _set_points(browser, points=-1)644 assert _get_total_points(browser) == 0645 assert 0 == _get_metadata(browser)['points']646@pytest.mark.nbextensions647def test_task_negative_points(browser, port):648 _load_notebook(browser, port, name='task')649 _activate_toolbar(browser)650 # make sure the total points is zero651 assert _get_total_points(browser) == 0652 # make it autograder tests and set the points to two653 _select_task(browser)654 _set_points(browser, points=2)655 _set_id(browser)656 assert _get_total_points(browser) == 2657 assert 2 == _get_metadata(browser)['points']658 # set the points to negative one659 _set_points(browser, points=-1)660 assert _get_total_points(browser) == 0661 assert 0 == _get_metadata(browser)['points']662@pytest.mark.nbextensions663def test_schema_version(browser, port):664 _load_notebook(browser, port, name="old-schema")665 # activating the toolbar should cause the dialog warning about the schema666 # version to appear667 _activate_toolbar(browser)668 _wait_for_modal(browser)669 _dismiss_modal(browser)670@pytest.mark.nbextensions671def test_invalid_nbgrader_cell_type(browser, port):672 _load_notebook(browser, port)673 _activate_toolbar(browser)674 # make it a solution cell675 _select_solution(browser)676 assert _get_metadata(browser)['solution']677 assert not _get_metadata(browser)['grade']678 assert not _get_metadata(browser)['locked']679 # wait for the id field to appear680 _wait(browser).until(681 EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".nbgrader-id")))682 # set the id683 assert _get_metadata(browser)['grade_id'].startswith("cell-")684 _set_id(browser)685 assert _get_metadata(browser)['grade_id'] == "foo"686 # make sure the metadata is valid687 _save_and_validate(browser)688 # change the cell to a markdown cell689 element = browser.find_element_by_tag_name("body")690 element.send_keys(Keys.ESCAPE)691 element.send_keys("m")692 # make sure the toolbar appeared693 def find_toolbar(browser):694 try:695 browser.find_elements_by_css_selector(".celltoolbar select")[0]696 except IndexError:697 return False698 return True699 _wait(browser).until(find_toolbar)700 # check that then nbgrader metadata is consistent701 assert not _get_metadata(browser)['solution']702 assert not _get_metadata(browser)['grade']703 assert not _get_metadata(browser)['locked']704 assert _get_metadata(browser)['grade_id'] == "foo"705################################################################################706####### DO NOT ADD TESTS BELOW THIS LINE #######################################707################################################################################708@pytest.mark.nbextensions709def test_final(browser, port):710 """This is a final test to be run so that the browser doesn't hang, see711 https://github.com/mozilla/geckodriver/issues/1151712 """...

Full Screen

Full Screen

__init__.py

Source:__init__.py Github

copy

Full Screen

1from pkg_resources import get_distribution2from .retriever import retrieve_model, retrieve_raw3def _get_metadata(name):4 pkg = get_distribution(__package__)5 for line in pkg.get_metadata_lines(pkg.PKG_INFO):6 if line.startswith("{}: ".format(name)):7 return line.split(": ")[1]8 return ""9_copyright_notice = "Copyright (c) {} <{}>".format(10 _get_metadata("Author"), _get_metadata("Author-email")11)12usage = [_get_metadata("Summary"), _copyright_notice]13def doc_split(func):14 return func.__doc__.split("\n\n")[0]15def version(name):16 return "{} version {}\n\n{}\nHomepage: {}".format(17 _get_metadata("Name"),18 _get_metadata("Version"),19 _copyright_notice,20 _get_metadata("Home-page"),...

Full Screen

Full Screen

conf.py

Source:conf.py Github

copy

Full Screen

1from subprocess import call2call('pip install ..', shell=True)3from mutalyzer_retriever import _get_metadata4author = _get_metadata('Author')5copyright = _get_metadata('Author')6project = _get_metadata('Name')7release = _get_metadata('Version')8autoclass_content = 'both'9extensions = ['sphinx.ext.autodoc']...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run stestr automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful