Skip to content

Commit

Permalink
cosmetic changes in tests/
Browse files Browse the repository at this point in the history
  • Loading branch information
parmentelat committed Nov 21, 2020
1 parent a9d04a9 commit 3a3494a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
2 changes: 2 additions & 0 deletions tests/AA-readme-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* re-run in 2020 may w/ fedora 31

* re-run in 2020 nov w/ fedora 33
* no big change but the test repo has .md notebooks
* so the reference notebook moves from index 60 to 80

* as of 2019 nov 15, darktek is being decommissioned and goes into the r2lab room;
our new test box will thus be **`stupeflip`**;
Expand Down
32 changes: 16 additions & 16 deletions tests/nbhtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@


# default location where to look for test notebooks
default_course_gitdir = Path.home() / "git" / "python-mooc"
default_course_gitdir = Path.home() / "git" / "python-mooc"
default_topurl = "https://nbhosting-dev.inria.fr/"
default_sleep_internal = 1
default_go_between_notebooks = 5
Expand All @@ -41,7 +41,7 @@ class Contents:
"""
models a coursedir that we scan so we can reference notebooks by their index
"""

def __init__(self, dir):
self.dir = dir
# check existence
Expand All @@ -60,7 +60,7 @@ def print(self):
print(i, n)


@property
@property
def filename(self):
return f"{self.coursename}.nbs.json"

Expand Down Expand Up @@ -89,10 +89,10 @@ def _load(self):
def pause(mark, message, *, sleep=0, duration=None, skip=0):
"""
skip is a number of sleep periods that should not be accounted
for in the computed duration
for in the computed duration
"""
line = f"{mark}:{message}"
if sleep:
if sleep:
line += f" - waiting for {sleep}s"
if duration:
line += f" (since beg. {duration - skip*sleep:.02f})s"
Expand All @@ -104,7 +104,7 @@ def pause(mark, message, *, sleep=0, duration=None, skip=0):
class Notebook:
def __init__(self, notebook_arg):
coursedir, index = notebook_arg.split(':')
contents = Contents(coursedir)
contents = Contents(coursedir)
course = contents.coursename
notebooks = contents.notebooks
self.course = course
Expand All @@ -114,12 +114,12 @@ def __init__(self, notebook_arg):
except IndexError:
self.nb_path = "unexisting-notebook"
print(f"Using {self.nb_path} for dangling index {index}")


@property
def url_path(self):
return f"{self.course}/{self.nb_path}"



class Artefact:
Expand Down Expand Up @@ -153,7 +153,7 @@ def filename(self, msg):

def run(topurl, user, notebooks, sleep, go, cut):
"""
fetch - as this user -
fetch - as this user -
notebook indexed by index relative to that course dir
then perform additional tasks (exec, save, etc..)
"""
Expand All @@ -174,14 +174,14 @@ def run(topurl, user, notebooks, sleep, go, cut):
driver = selenium.webdriver.Chrome(chrome_driver_binary, options=options)

print("driver ready")

def fetch_one_notebook(notebook, need_new_window):
nonlocal topurl
nb = notebook.nb_path
# be extra-safe
if topurl.endswith("/"):
topurl = topurl[:-1]

url = f"{topurl}/notebookLazyCopy/{notebook.url_path}/{user}"
mark = f"{nb}/{user}"

Expand Down Expand Up @@ -241,10 +241,10 @@ def fetch_one_notebook(notebook, need_new_window):
traceback.print_exc()
driver.save_screenshot(scr.filename('4boom'))

# the first one is different, it receives its window
# the first one is different, it receives its window
# in a natural way; other windows need to be open from there
notebook0, *others = notebooks

fetch_one_notebook(notebook0, False)
for other in others:
time.sleep(go)
Expand Down Expand Up @@ -289,11 +289,11 @@ def main():
parser.add_argument("notebooks", default=[f"{default_course_gitdir}:0"],
nargs='*',
help="""define the notebook to open; this is ':'-separated
with its first part a git repo, and the second part
with its first part a git repo, and the second part
an index in the list of known notebooks
- run with -l to see list""")
args = parser.parse_args()

if args.list:
for notebook_arg in args.notebooks:
coursedir = notebook_arg.split(':')[0]
Expand Down
12 changes: 6 additions & 6 deletions tests/nbhtests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env -S python3 -u

"""
Utility to open a large number of notebooks
Utility to open a large number of notebooks
We use subprocess because phantom and selenium are not asyncio-friendly,
and there is no clear advantage in running all the open-notebook instances
Expand All @@ -23,13 +23,13 @@
from intsranges import IntsRanges

from nbhtest import (
default_course_gitdir,
default_course_gitdir,
default_topurl,
default_sleep_internal,
default_go_between_notebooks,
Contents,
)

default_period = 20
default_window = 5
default_idle = 5 # this is the default on the dev box
Expand All @@ -56,13 +56,13 @@ def main() -> bool:
help="""just load the urls, don't do any further processing""")
parser.add_argument("-w", "--window", default=default_window, type=int,
help="window depth for spawning the nbhtest instances")
parser.add_argument("--idle", default=None,
parser.add_argument("--idle", default=None,
help="monitor idle setting")
parser.add_argument("-n", "--dry-run", action='store_true')
parser.add_argument("coursedirs", default=[default_course_gitdir],
nargs='*',
help="""a list of git repos where to fetch notebooks""")

signature = "".join(sys.argv[1:])
args = parser.parse_args()

Expand Down Expand Up @@ -97,7 +97,7 @@ def main() -> bool:
scheduler=scheduler,
node=local,
commands = [command, f"sleep {args.period}"])

if args.dry_run:
return True

Expand Down
12 changes: 5 additions & 7 deletions tests/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def has_time(line):
print(f"duration was {delta}")
except:
pass


def average(dir, criteria):
txt_filenames = Path(dir).glob("*.txt")
numbers = []
Expand All @@ -52,8 +52,8 @@ def average(dir, criteria):
return
array = np.array(numbers)
print(f"({len(array)} items) {criteria:12} avg={array.mean():.2f} with std.dev={np.sqrt(array.var()):.2f} ")


def count_booms(dir, verbose):
by_size = defaultdict(list)
counter = 0
Expand Down Expand Up @@ -92,7 +92,7 @@ def main():
By default all subdirs named in 'artefacts*'""")
parser.add_argument("-v", "--verbose", default=False, action='store_true')
args = parser.parse_args()

dirs = args.dirs
if not dirs:
dirs = Path(".").glob("artefacts*")
Expand All @@ -103,5 +103,3 @@ def main():

if __name__ == '__main__':
main()


0 comments on commit 3a3494a

Please sign in to comment.