-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a1b03a
commit b5ff9cc
Showing
2 changed files
with
85 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,33 @@ | ||
import warnings | ||
from unittest.mock import MagicMock | ||
|
||
from pyspark.sql import SparkSession | ||
|
||
from joblibspark.backend import SparkDistributedBackend | ||
|
||
|
||
def test_effective_n_jobs(): | ||
class TestLocalSparkCluster: | ||
@classmethod | ||
def setup_class(cls): | ||
cls.spark = ( | ||
SparkSession.builder.master("local[*]").getOrCreate() | ||
) | ||
|
||
@classmethod | ||
def teardown_class(cls): | ||
cls.spark.stop() | ||
|
||
def test_effective_n_jobs(self): | ||
|
||
backend = SparkDistributedBackend() | ||
max_num_concurrent_tasks = 8 | ||
backend._get_max_num_concurrent_tasks = MagicMock(return_value=max_num_concurrent_tasks) | ||
backend = SparkDistributedBackend() | ||
max_num_concurrent_tasks = 8 | ||
backend._get_max_num_concurrent_tasks = MagicMock(return_value=max_num_concurrent_tasks) | ||
|
||
assert backend.effective_n_jobs(n_jobs=None) == 1 | ||
assert backend.effective_n_jobs(n_jobs=-1) == 8 | ||
assert backend.effective_n_jobs(n_jobs=4) == 4 | ||
assert backend.effective_n_jobs(n_jobs=None) == 1 | ||
assert backend.effective_n_jobs(n_jobs=-1) == 8 | ||
assert backend.effective_n_jobs(n_jobs=4) == 4 | ||
|
||
with warnings.catch_warnings(record=True) as w: | ||
warnings.simplefilter("always") | ||
assert backend.effective_n_jobs(n_jobs=16) == 16 | ||
assert len(w) == 1 | ||
with warnings.catch_warnings(record=True) as w: | ||
warnings.simplefilter("always") | ||
assert backend.effective_n_jobs(n_jobs=16) == 16 | ||
assert len(w) == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters