gamsjupyter01.gms : 메가 슬롯 Jupyter 노트북 테스트

설명

기고자: Clemens Westphal, 2020년 9월)

소형 모델 유형 :메가 슬롯


카테고리 : 메가 슬롯 테스트 라이브러리


메인 파일 : gamsjupyter01.gms

$title '메가 슬롯 Jupyter 노트북 테스트' (GAMSJUPYTER01,SEQ=836)

$onText
기고자: Clemens Westphal, 2020년 9월)
$offText

$set srcRoot %메가 슬롯sysdir%api%system.dirsep%python%system.dirsep%examples%system.dirsep%magic%system.dirsep%
$set testDir %sysenv.GTESTDIR%%system.dirsep%%sysenv.MODTESTDIR%%system.dirsep%gamsjupyter01

$설정되지 않은 경우 JUPYTER $exit

$onEmbeddedCode 파이썬:
수입 OS
수입 차단

def _patch_sysdir(file_in, file_out, 이전, 새):
    open(file_in, 'r', 인코딩='utf-8')을 f로 사용:
        s = f.read().replace(이전, 신규)
    open(file_out, 'w', 인코딩='utf-8')을 f로 사용:
        f.쓰기

def patch_sysdir(file_in, file_out):
    _patch_sysdir(
        파일_인,
        파일 출력,
        '"%reload_ext 메가 슬롯magic"',
        r'"%reload_ext 메가 슬롯magic\n", "os 가져오기\n", "메가 슬롯reset(os.environ.get(\"GTESTDIR\", None))"'
    )

def patch_sysdir_py(file_in, file_out):
    _patch_sysdir(
        파일_인,
        파일 출력,
        '메가 슬롯 = GamsInteractive()',
        r'메가 슬롯 = GamsInteractive(); 수입 OS; 메가 슬롯reset(os.environ.get("GTESTDIR", None))'
    )

test_dir = r"%testDir%"
os.makedirs(test_dir,exist_ok=True)

patch_sysdir(r"%srcRoot%Introduction.ipynb", os.path.join(test_dir, "Introduction.ipynb"))
patch_sysdir(r"%srcRoot%Millco.ipynb", os.path.join(test_dir, "Millco.ipynb"))
patch_sysdir(r"%srcRoot%Polyomino.ipynb", os.path.join(test_dir, "Polyomino.ipynb"))
patch_sysdir(r"%srcRoot%Pickstock.ipynb", os.path.join(test_dir, "Pickstock.ipynb"))
patch_sysdir(r"%srcRoot%NordhausDice.ipynb", os.path.join(test_dir, "NordhausDice.ipynb"))

# Polyomino.ipynb에 필요한 Pentominos.png 복사
shutdown.copy(r"%srcRoot%Pentominos.png", test_dir)

patch_sysdir_py(r"%srcRoot%millco.py", os.path.join(test_dir, "millco.py"))
patch_sysdir_py(r"%srcRoot%nordhausdice.py", os.path.join(test_dir, "nordhausdice.py"))
patch_sysdir_py(r"%srcRoot%pickstock.py", os.path.join(test_dir, "pickstock.py"))

$offEmbeddedCode

$call.checkErrorLevel CD . && "%sysenv.JUPYTER%" nbconvert --to 노트북 --execute "%testDir%%system.dirsep%Introduction.ipynb" > Introduction.log 2>&1
$call.checkErrorLevel CD . && "%sysenv.JUPYTER%" nbconvert --to 노트북 --execute "%testDir%%system.dirsep%Millco.ipynb" > Millco.log 2>&1
$ifThen dExist "%메가 슬롯sysdir%GMSPython"
$ call.checkErrorLevel CD . && "%메가 슬롯sysdir%GMSPython%system.dirsep%python" "%testDir%%system.dirsep%millco.py" > millco_py.log 2>&1
$endIf

$if %DEMOSIZE% == 1 $exit

$call.checkErrorLevel CD . && "%sysenv.JUPYTER%" nbconvert --to 노트북 --execute "%testDir%%system.dirsep%Polyomino.ipynb" > Polyomino.log 2>&1
$call.checkErrorLevel CD . && "%sysenv.JUPYTER%" nbconvert --to 노트북 --execute "%testDir%%system.dirsep%Pickstock.ipynb" > Pickstock.log 2>&1
$call.checkErrorLevel CD . && "%sysenv.JUPYTER%" nbconvert --to 노트북 --execute "%testDir%%system.dirsep%NordhausDice.ipynb" > NordhausDice.log 2>&1
$ifThen dExist "%메가 슬롯sysdir%GMSPython"
$ call.checkErrorLevel CD . && "%메가 슬롯sysdir%GMSPython%system.dirsep%python" "%testDir%%system.dirsep%pickstock.py" > pickstock_py.log 2>&1
$endIf
$ifThen dExist "%메가 슬롯sysdir%GMSPython"
$ call.checkErrorLevel CD . && "%메가 슬롯sysdir%GMSPython%system.dirsep%python" "%testDir%%system.dirsep%nordhausdice.py" > nordhausdice_py.log 2>&1
$endIf