fix example test to pass on Windows
+import os
import unittest
import six
@@ -12,13 +13,14 @@ 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 = (
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.replace('\n', os.linesep))
class TestMonteCarlo(unittest.TestCase):
@@ -28,8 +30,7 @@ class TestMonteCarlo(unittest.TestCase):
'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 = (
r'initializing...\n' +
r'start computation\n' +
r' # of options: 10\n' +
@@ -37,6 +38,9 @@ class TestMonteCarlo(unittest.TestCase):
r'GPU \(CuPy, Monte Carlo method\):\t[0-9\.]+ sec\n' +
r'Error: [0-9\.]+')
+ six.assertRegex(
+ self, output.decode('utf-8'), pattern.replace('\n', os.linesep))
+
class TestMonteCarloWithMultiGPU(unittest.TestCase):
@@ -47,8 +51,7 @@ class TestMonteCarloWithMultiGPU(unittest.TestCase):
'--n-options', '10',
'--n-samples-per-thread', '10',
'--n-threads-per-option', '10')
- six.assertRegex(
- self, output.decode('utf-8'),
+ pattern = (
r'initializing...\n' +
r'start computation\n' +
r' # of gpus: 2\n' +
@@ -56,3 +59,5 @@ class TestMonteCarloWithMultiGPU(unittest.TestCase):
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.replace('\n', os.linesep))
