def test_caseless_dict():
    test_dict = CaselessDict({})
    test_dict['Key1'] = 'Value1'
    assert 'KEY1' in test_dict
    test_dict['keY1'] = 'Value1a'
    assert test_dict['Key1'] != 'Value1'
    assert 'Value1a' == test_dict.pop('key1')

    test_dict['Key2'] = 'Value2'
    del(test_dict['kEy2'])

    test_dict['Key3'] = 'Value3'
    test_dict.changekey('keY3')
    assert 'key3' in test_dict
    assert 'KEY3' in test_dict
Пример #2
0
 def test_dynamic_attribute_errors_if_missing_stuff(self):
     row = CaselessDict({
         "name": "TestAttribute",
         "formula": "a + b",
         "type": "int"
     })
     self.assertRaises(ValueError, excel.get_dynamic, row)
Пример #3
0
 def test_dynamic_attribute_barfs_on_bad_syntax(self):
     row = CaselessDict({
         "name": "TestAttribute",
         "formula": "a ? b",
         "type": "int",
         "mode": "attr"
     })
     self.assertRaises(SyntaxError, excel.get_dynamic, row)
Пример #4
0
 def test_get_properties_both(self):
     row = CaselessDict({
         "Properties": "c=3",
         "Property:a": "1",
         "Property:b": "2"
     })
     result = excel.get_properties(row)
     self.assertDictEqual(result, {"a": ["1"], "b": ["2"], "c": ["3"]})
Пример #5
0
 def test_get_attribute_properties_errors_on_invalid_name(self):
     row = CaselessDict({
         "Attribute": "myAttribute",
         "AttrProp:Label": "Something",
         "AttrProp:Min value": "45",
         "AttrProp:Not valid": "foo"
     })
     self.assertRaises(ValueError, excel.get_attribute_properties, row)
Пример #6
0
 def test_get_dynamic_state(self):
     row = CaselessDict({
         "name": "WEIRD",
         "formula": "1 == 2",
         "type": "bool",
         "mode": "state"
     })
     result = excel.get_dynamic(row)
     self.assertDictEqual(result, {"DynamicStates": ["WEIRD=bool(1 == 2)"]})
Пример #7
0
 def test_get_dynamic_status(self):
     row = CaselessDict({
         "name": "Status",
         "formula": "'Something witty here'",
         "type": "str",
         "mode": "status"
     })
     result = excel.get_dynamic(row)
     self.assertDictEqual(
         result, {"DynamicStatus": ["str('Something witty here')"]})
Пример #8
0
 def test_get_dynamic_command(self):
     row = CaselessDict({
         "name": "TestCommand",
         "formula": "1 + 2",
         "type": "bool",
         "mode": "cmd"
     })
     result = excel.get_dynamic(row)
     self.assertDictEqual(result,
                          {"DynamicCommands": ["TestCommand=bool(1 + 2)"]})
Пример #9
0
 def test_get_dynamic_attribute(self):
     row = CaselessDict({
         "name": "TestAttribute",
         "formula": "a + b",
         "type": "int",
         "mode": "attr"
     })
     result = excel.get_dynamic(row)
     self.assertDictEqual(
         result.to_dict(),
         {"DynamicAttributes": ["TestAttribute=int(a + b)"]})
Пример #10
0
 def test_get_attribute_properties(self):
     row = CaselessDict({
         "Attribute": "myAttribute",
         "AttributeProperties": "min_value=1;max_value=2"
     })
     result = excel.get_attribute_properties(row)
     self.assertDictEqual(
         result, {"myAttribute": {
             "min_value": ["1"],
             "max_value": ["2"]
         }})
Пример #11
0
 def test_get_attribute_properties_multiple(self):
     row = CaselessDict({
         "Attribute": "myAttribute",
         "AttrProp:Label": "Something",
         "AttrProp:Min value": "45"
     })
     result = excel.get_attribute_properties(row)
     self.assertDictEqual(
         result,
         {"myAttribute": {
             "min_value": ["45"],
             "label": ["Something"]
         }})
Пример #12
0
 def test_get_properties_with_types(self):
     row = CaselessDict({"Property(int):a": 1.0, "Property(float):b": 1.0})
     result = excel.get_properties(row)
     self.assertDictEqual(result, {"a": ["1"], "b": ["1.0"]})
Пример #13
0
 def test_get_properties_with_zero_value(self):
     row = CaselessDict({"Property:a": 0})
     result = excel.get_properties(row)
     self.assertDictEqual(result, {"a": ["0"]})
Пример #14
0
 def test_get_properties_splits_separate(self):
     row = CaselessDict({"Property:a": "1\n2\n3"})
     result = excel.get_properties(row)
     self.assertDictEqual(result, {"a": ["1", "2", "3"]})
Пример #15
0
 def test_get_properties_splits_combined(self):
     row = CaselessDict({"Properties": "a=1\n2\n3"})
     result = excel.get_properties(row)
     self.assertDictEqual(result, {"a": ["1", "2", "3"]})
Пример #16
0
 def test_get_properties_combined(self):
     row = CaselessDict({"Properties": "a=1; b=2; c=3"})
     result = excel.get_properties(row)
     self.assertDictEqual(result, {"a": ["1"], "b": ["2"], "c": ["3"]})