Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backport] Fix example test to pass on Windows #1188

Merged
merged 1 commit into from Apr 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 12 additions & 6 deletions tests/example_tests/test_finance.py
@@ -1,3 +1,5 @@
import os
import re
import unittest

import six
Expand All @@ -7,18 +9,22 @@
from cupy import testing


def _normalize_regexp_eol(pattern):
return pattern.replace(r'\n', re.escape(os.linesep))


class TestBlackScholes(unittest.TestCase):

def test_black_scholes(self):
output = example_test.run_example(
'finance/black_scholes.py', '--n-options', '10')
six.assertRegex(
self, output.decode('utf-8'),
pattern = _normalize_regexp_eol(
r'initializing...\n' +
r'start computation\n' +
r' CPU \(NumPy, Naive implementation\):\t[0-9\.]+ sec\n' +
r' GPU \(CuPy, Naive implementation\):\t[0-9\.]+ sec\n' +
r' GPU \(CuPy, Elementwise kernel\):\t[0-9\.]+ sec')
six.assertRegex(self, output.decode('utf-8'), pattern)


class TestMonteCarlo(unittest.TestCase):
Expand All @@ -28,14 +34,14 @@ def test_monte_carlo(self):
'finance/monte_carlo.py', '--n-options', '10',
'--n-samples-per-thread', '10',
'--n-threads-per-option', '10')
six.assertRegex(
self, output.decode('utf-8'),
pattern = _normalize_regexp_eol(
r'initializing...\n' +
r'start computation\n' +
r' # of options: 10\n' +
r' # of samples per option: 100\n' +
r'GPU \(CuPy, Monte Carlo method\):\t[0-9\.]+ sec\n' +
r'Error: [0-9\.]+')
six.assertRegex(self, output.decode('utf-8'), pattern)


class TestMonteCarloWithMultiGPU(unittest.TestCase):
Expand All @@ -47,12 +53,12 @@ def test_monte_carlo_multigpu(self):
'--n-options', '10',
'--n-samples-per-thread', '10',
'--n-threads-per-option', '10')
six.assertRegex(
self, output.decode('utf-8'),
pattern = _normalize_regexp_eol(
r'initializing...\n' +
r'start computation\n' +
r' # of gpus: 2\n' +
r' # of options: 10\n' +
r' # of samples per option: 200\n' +
r'GPU \(CuPy, Monte Carlo method\):\t[0-9\.]+ sec\n' +
r'Error: [0-9\.]+')
six.assertRegex(self, output.decode('utf-8'), pattern)