Skip to content

Commit

Permalink
Merge pull request #2770 from mr0re1/pytst
Browse files Browse the repository at this point in the history
Improve `pytest` flow
  • Loading branch information
mr0re1 authored Jul 17, 2024
2 parents 903b601 + d90d61f commit 1e65522
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 50 deletions.
16 changes: 16 additions & 0 deletions .pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

[pytest]
filterwarnings = ignore::DeprecationWarning

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2024 "Google LLC"
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Optional
import sys
from dataclasses import dataclass, field

SCRIPTS_DIR = "community/modules/scheduler/schedmd-slurm-gcp-v6-controller/modules/slurm_files/scripts"
if SCRIPTS_DIR not in sys.path:
sys.path.append(SCRIPTS_DIR) # TODO: make this more robust


# TODO: use "real" classes once they are defined (instead of NSDict)
@dataclass
class TstNodeset:
nodeset_name: str
node_count_static: int = 0
node_count_dynamic_max: int = 0


@dataclass
class TstCfg:
slurm_cluster_name: str = "m22"
nodeset: dict[str, TstNodeset] = field(default_factory=dict)
nodeset_tpu: dict[str, TstNodeset] = field(default_factory=dict)
output_dir: Optional[str] = None


@dataclass
class TstTPU: # to prevent client initialization durint "TPU.__init__"
vmcount: int


def make_to_hostnames_mock(tbl: Optional[dict[str, list[str]]]):
tbl = tbl or {}

def se(k: str) -> list[str]:
if k not in tbl:
raise AssertionError(f"to_hostnames mock: unexpected nodelist: '{k}'")
return tbl[k]

return se
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Optional
import mock
import sys
from common import TstCfg, TstNodeset, TstTPU, make_to_hostnames_mock

if ".." not in sys.path:
sys.path.append("..") # TODO: make this more robust
import util
import conf

from dataclasses import dataclass, field
import tempfile


# TODO: use "real" classes once they are defined (instead of NSDict)
@dataclass
class TstNodeset:
nodeset_name: str
node_count_static: int = 0
node_count_dynamic_max: int = 0


@dataclass
class TstCfg:
slurm_cluster_name: str = "m22"
nodeset: dict[str, TstNodeset] = field(default_factory=dict)
nodeset_tpu: dict[str, TstNodeset] = field(default_factory=dict)
output_dir: Optional[str] = None


@dataclass
class TstTPU: # to prevent client initialization durint "TPU.__init__"
vmcount: int


def make_to_hostnames_mock(tbl: Optional[dict[str, list[str]]]):
tbl = tbl or {}

def se(k: str) -> list[str]:
if k not in tbl:
raise AssertionError(f"to_hostnames mock: unexpected nodelist: '{k}'")
return tbl[k]

return se


def test_gen_topology_conf_empty():
cfg = TstCfg(output_dir=tempfile.mkdtemp())
conf.gen_topology_conf(util.Lookup(cfg))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
import pytest

if ".." not in sys.path:
sys.path.append("..") # TODO: make this more robust
import common # needed to import util
import util
from google.api_core.client_options import ClientOptions # noqa: E402

# Note: need to install pytest-mock


@pytest.mark.parametrize(
"name,expected",
[
Expand Down

0 comments on commit 1e65522

Please sign in to comment.