コード例 #1
0
 def test_number_of_parameters_error(self):
     with pytest.raises(HyperParameterEncodingError) as err:
         encode({str(i): i for i in range(101)})
     assert (
         str(err.value) ==
         "SageMaker allows at most 100 hyperparameters but 101 were specified."
     )
コード例 #2
0
 def test_value_length_error(self):
     v = "b" * 255  # 257 minus two quote characters
     with pytest.raises(HyperParameterEncodingError) as err:
         encode({"a": v})
     assert str(
         err.value
     ) == "Value '\"{}\"' for key 'a' must have length at most 256.".format(
         v)
コード例 #3
0
 def test_nested_key_length_error(self):
     k1 = "a" * 100
     k2 = "b" * 100
     k3 = "c" * 55  # 257 minus two dots
     with pytest.raises(HyperParameterEncodingError) as err:
         encode({k1: {k2: {k3: 5}}})
     assert str(
         err.value
     ) == "Key '{}.{}.{}' must be at most 256 characters.".format(
         k1, k2, k3)
コード例 #4
0
ファイル: fixtures.py プロジェクト: prodigyfinance/ml2p
 def train(self, **kw):
     self.monkeypatch.setenv("TRAINING_JOB_NAME", "test-train-1.2.3")
     params = {"ML2P_PROJECT": "test-project", "ML2P_S3_URL": "s3://foo/bar"}
     params.update(kw)
     for k, v in kw.items():
         if v is None:
             del params[k]
     self.ml_folder.mkdir("input").mkdir("config").join(
         "hyperparameters.json"
     ).write(json.dumps(hyperparameters.encode({"ML2P_ENV": params})))
     return SageMakerEnv(str(self.ml_folder))
コード例 #5
0
 def test_nested_twice(self):
     assert encode(
         {"a": {
             "b1": {
                 "c1": 3,
                 "d1": 4
             },
             "b2": {
                 "c2": 5,
                 "d2": 6
             }
         }}) == {
             "a.b1.c1": "3",
             "a.b1.d1": "4",
             "a.b2.c2": "5",
             "a.b2.d2": "6",
         }
コード例 #6
0
 def test_int(self):
     assert encode({"a": 1}) == {"a": "1"}
コード例 #7
0
 def test_key_length_error(self):
     k = "a" * 257
     with pytest.raises(HyperParameterEncodingError) as err:
         encode({k: 5})
     assert str(
         err.value) == "Key '{}' must be at most 256 characters.".format(k)
コード例 #8
0
 def test_key_format_error(self):
     with pytest.raises(HyperParameterEncodingError) as err:
         encode({"a.b": 5})
     assert str(
         err.value) == "Key 'a.b' must be a string without dots ('.')"
コード例 #9
0
 def test_nested_once(self):
     assert encode({"a": {"b": 1, "c": 2}}) == {"a.b": "1", "a.c": "2"}
コード例 #10
0
 def test_list(self):
     assert encode({"a": [1, 2, 3]}) == {"a": "[1, 2, 3]"}
コード例 #11
0
 def test_false(self):
     assert encode({"a": False}) == {"a": "false"}
コード例 #12
0
 def test_true(self):
     assert encode({"a": True}) == {"a": "true"}
コード例 #13
0
 def test_none(self):
     assert encode({"a": None}) == {"a": "null"}
コード例 #14
0
 def test_str(self):
     assert encode({"a": "b"}) == {"a": '"b"'}
コード例 #15
0
 def test_float(self):
     assert encode({"a": 1.2}) == {"a": "1.2"}