コード例 #1
0
 def save(self, new_setup):
     """Save a new setup"""
     SetupValidator().validate(new_setup)
     self.setup_file.save_setup(new_setup)
     self.setup_file.rotate_screen(new_setup["screen"]["rotate"])
     # refresh the backend too
     self._load_user_preferences()
     self._init_resources()
コード例 #2
0
 def test__check_tag_uniqueness_success(self):
     SetupValidator()._check_tag_uniqueness({
         "foo": {
             "tag": "tag1"
         },
         "bar": {
             "tag": "tag2"
         }
     })
コード例 #3
0
 def test__update_to_3_1_0(self, fixtures_dir):
     with open(os.path.join(fixtures_dir, "default_setup_3_0_0.json")) as file:
         setup = json.load(file)
     setup = SetupUpdater._update_to_3_1_0(setup)
     with open(os.path.join(fixtures_dir, "default_setup_3_1_0.json")) as file:
         fixture_3_1_0 = json.load(file)
     assert setup == fixture_3_1_0
     SetupValidator().validate(
         setup
     )  # this only could be applied to the last version update test
コード例 #4
0
 def test__check_formula_invalid_formula(self):
     """A formula not registered should fail"""
     formula = "fake_formula"
     with pytest.raises(SetupValidator.ValidationError) as excinfo:
         SetupValidator()._check_formula(
             {"foo": {
                 "formula": formula,
                 "unit": "bar"
             }})
     assert str(excinfo.value) == f"{formula} not found"
コード例 #5
0
 def test__check_formula_fail(self):
     """Invalid unit for specific formula should fail"""
     formula = "vdo_323_057"
     unit = "bar"
     with pytest.raises(SetupValidator.ValidationError) as excinfo:
         SetupValidator()._check_formula(
             {"foo": {
                 "formula": formula,
                 "unit": unit
             }})
     assert str(excinfo.value) == f"{unit} not allowed for {formula}"
コード例 #6
0
 def test__check_tag_uniqueness_fail(self):
     """Repeated tags should fail"""
     with pytest.raises(SetupValidator.ValidationError) as excinfo:
         SetupValidator()._check_tag_uniqueness({
             "foo": {
                 "tag": "same_tag"
             },
             "bar": {
                 "tag": "same_tag"
             }
         })
     assert str(excinfo.value) == "Repeated tag found"
コード例 #7
0
 def test_only_with_version(self):
     """An almost empty json with only the version tag should fail validating"""
     with pytest.raises(SetupValidator.ValidationError) as excinfo:
         SetupValidator().validate({
             "version": "2.3.2",
             "vss": {
                 "label": "",
                 "max": "",
                 "sectors": "",
                 "suffix": ""
             },
         })
     assert str(excinfo.value) == "'tag' is a required property"
コード例 #8
0
 def test_validation_error(self):
     SetupValidator.ValidationError()
コード例 #9
0
 def test__check_version_fail(self):
     with pytest.raises(SetupValidator.ValidationError) as excinfo:
         SetupValidator()._check_version({"version": {"1.0.0"}})
     assert str(excinfo.value) == "setup file should be at least 2.3.2"
コード例 #10
0
 def test__check_version_success(self):
     SetupValidator()._check_version({"version": "2.4.0"})
コード例 #11
0
 def test_default(self):
     """Validate the default setup json"""
     with open(DEFAULT_CONFIG_FILE_NAME, "r") as setup_file:
         SetupValidator().validate(json.load(setup_file))
コード例 #12
0
 def test__check_formula_no_formula_present(self):
     """If the value doesn't have formula then should validate correctly"""
     SetupValidator()._check_formula({"foo": {"bar"}})
コード例 #13
0
 def test__check_formula_success(self):
     SetupValidator()._check_formula(
         {"foo": {
             "formula": "vdo_323_057",
             "unit": "celsius"
         }})
コード例 #14
0
 def test_empty_json(self):
     """An empty json should fail validating"""
     with pytest.raises(SetupValidator.ValidationError) as excinfo:
         SetupValidator().validate({})
     assert str(excinfo.value) == "version tag not found"