Skip to content

Commit

Permalink
Merge pull request #6018 from befeleme/fix-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-bates authored Mar 24, 2021
2 parents ec4969e + 0723596 commit c719e27
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions notebook/tests/test_notebookapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,38 +90,36 @@ def test_generate_config():
assert os.path.exists(os.path.join(td, 'jupyter_notebook_config.py'))

#test if the version testin function works
def test_pep440_version():

for version in [
@pytest.mark.parametrize(
'version', [
'4.1.0.b1',
'4.1.b1',
'4.2',
'X.y.z',
'1.2.3.dev1.post2',
]:
def loc():
with pytest.raises(ValueError):
raise_on_bad_version(version)
yield loc

for version in [
]
)
def test_pep440_bad_version(version):
with pytest.raises(ValueError):
raise_on_bad_version(version)

@pytest.mark.parametrize(
'version', [
'4.1.1',
'4.2.1b3',
]:

yield (raise_on_bad_version, version)
]
)
def test_pep440_good_version(version):
raise_on_bad_version(version)



pep440re = re.compile('^(\d+)\.(\d+)\.(\d+((a|b|rc)\d+)?)(\.post\d+)?(\.dev\d*)?$')
pep440re = re.compile(r'^(\d+)\.(\d+)\.(\d+((a|b|rc)\d+)?)(\.post\d+)?(\.dev\d*)?$')

def raise_on_bad_version(version):
if not pep440re.match(version):
raise ValueError("Versions String does apparently not match Pep 440 specification, "
"which might lead to sdist and wheel being seen as 2 different release. "
"E.g: do not use dots for beta/alpha/rc markers.")


def test_current_version():
raise_on_bad_version(__version__)

Expand All @@ -139,7 +137,7 @@ def test_notebook_password():
assert nb.password != ''
passwd_check(nb.password, password)

class TestingStopApp(notebookapp.NbserverStopApp):
class StopAppTest(notebookapp.NbserverStopApp):
"""For testing the logic of NbserverStopApp."""
def __init__(self, **kwargs):
super().__init__(**kwargs)
Expand Down Expand Up @@ -168,15 +166,15 @@ def list_running_servers(runtime_dir):

# test stop with a match
with mock_servers:
app = TestingStopApp()
app = StopAppTest()
app.initialize(['105'])
app.start()
assert len(app.servers_shut_down) == 1
assert app.servers_shut_down[0]['port'] == 105

# test no match
with mock_servers, patch('os.kill') as os_kill:
app = TestingStopApp()
app = StopAppTest()
app.initialize(['999'])
with pytest.raises(SystemExit) as exc:
app.start()
Expand Down

0 comments on commit c719e27

Please sign in to comment.