Skip to content

Commit

Permalink
Merge pull request #1188 from okuta/bp-1172-fix-example-test-windows
Browse files Browse the repository at this point in the history
[backport] Fix example test to pass on Windows
  • Loading branch information
kmaehashi committed Apr 26, 2018
2 parents 011f696 + d25c31a commit d057392
Showing 1 changed file with 12 additions and 6 deletions.
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)

0 comments on commit d057392

Please sign in to comment.