Пример #1
0
    def test_temporaries(self):
        f = tempfile.NamedTemporaryFile()
        t = open(f.name, "w")
        t.write("""{"foo" : "bar"}""")
        t.close()

        s = settings._Settings(f.name)
        s.register("foo", str, "default")
        s.register("bar", str, "default")
        s.set("foo", "notdefault")
        self.assertEqual(s.foo, "notdefault")
        s.set_temporarily("foo", "temporary")
        self.assertEqual(s.foo, "temporary")

        self.assertTrue(s.is_manually_set, "foo")
        self.assertTrue(s.is_manually_set, "bar")

        s.set_temporarily("bar", "temporary")

        # ensure the file didn't change
        s2 = settings._Settings(f.name)
        s2.register("foo", str, "default")
        self.assertEqual(s2.foo, "notdefault")

        f.close()
Пример #2
0
  def test_temporaries(self):
    f = tempfile.NamedTemporaryFile()
    t = open(f.name,"w")
    t.write("""{"foo" : "bar"}""")
    t.close()

    s = settings._Settings(f.name)
    s.register("foo",str,"default")
    s.register("bar",str,"default")
    s.set("foo","notdefault")
    self.assertEqual(s.foo, "notdefault")
    s.set_temporarily("foo","temporary")
    self.assertEqual(s.foo, "temporary")

    self.assertTrue(s.is_manually_set, "foo")
    self.assertTrue(s.is_manually_set, "bar")

    s.set_temporarily("bar","temporary")

    # ensure the file didn't change
    s2 = settings._Settings(f.name)
    s2.register("foo",str,"default")
    self.assertEqual(s2.foo,"notdefault")

    f.close()
Пример #3
0
    def test_basic(self):
        f = tempfile.NamedTemporaryFile()
        s = settings._Settings(f.name)
        self.assertFalse(s.has_setting("foo"))
        self.assertRaises(settings.SettingDoesntExistException,
                          lambda: s["foo"])
        s.register("doSomething", bool, True)
        self.assertTrue(s.has_setting("doSomething"))
        self.assertFalse(s.is_manually_set("doSomething"))
        self.assertTrue(s["doSomething"])
        self.assertTrue(s.doSomething)
        self.assertRaises(
            Exception,
            lambda: s.register("doSomething", int, None))  # type mismatch
        self.assertRaises(TypeError, lambda: s.set("doSomething", "Foo"))
        self.assertRaises(settings.SettingDoesntExistException,
                          lambda: s.set("bar", "boo"))

        # change the setting manually to false...
        s.set("doSomething", False)
        self.assertEqual(s.doSomething, False)
        self.assertTrue(s.is_manually_set("doSomething"))

        # check that this was saved and persisted...
        s2 = settings._Settings(f.name)
        s2.register("doSomething", bool, True)
        self.assertFalse(s2.doSomething)
        self.assertTrue(s2.is_manually_set(s2.doSomething))
        f.close()
Пример #4
0
  def test_basic(self):
    f = tempfile.NamedTemporaryFile()
    s = settings._Settings(f.name)
    self.assertFalse(s.has_setting("foo"))
    self.assertRaises(settings.SettingDoesntExistException,lambda: s["foo"])
    s.register("doSomething",bool,True)
    self.assertTrue(s.has_setting("doSomething"))
    self.assertFalse(s.is_manually_set("doSomething"))
    self.assertTrue(s["doSomething"])
    self.assertTrue(s.doSomething)
    self.assertRaises(Exception,lambda: s.register("doSomething",int,None)) # type mismatch
    self.assertRaises(TypeError,lambda: s.set("doSomething","Foo"))
    self.assertRaises(settings.SettingDoesntExistException,lambda: s.set("bar","boo"))

    # change the setting manually to false...
    s.set("doSomething",False)
    self.assertEqual(s.doSomething,False)
    self.assertTrue(s.is_manually_set("doSomething"))

    # check that this was saved and persisted...
    s2 = settings._Settings(f.name)
    s2.register("doSomething",bool,True)
    self.assertFalse(s2.doSomething)
    self.assertTrue(s2.is_manually_set(s2.doSomething))
    f.close()
Пример #5
0
 def test_has_unresolved(self):
     f = tempfile.NamedTemporaryFile()
     t = open(f.name, "w")
     t.write("""{"foo" : True}""")
     t.close()
     s = settings._Settings(f.name)
     self.assertTrue(s.has_unresolved_settings())
     f.close()
Пример #6
0
 def test_has_unresolved(self):
   f = tempfile.NamedTemporaryFile()
   t = open(f.name,"w")
   t.write("""{"foo" : True}""")
   t.close()
   s = settings._Settings(f.name)
   self.assertTrue(s.has_unresolved_settings())
   f.close()
Пример #7
0
    def test_from_existing_with_type_mismatch(self):
        f = tempfile.NamedTemporaryFile()
        t = open(f.name, "w")
        t.write("""{"foo" : 3}""")
        t.close()

        s = settings._Settings(f.name)
        s.register("foo", str, "")
        self.assertFalse(s.has_unresolved_settings())
        self.assertFalse(s.is_manually_set("foo"))
        self.assertEqual(s.foo, "")
        f.close()
Пример #8
0
  def test_from_existing_with_type_mismatch(self):
    f = tempfile.NamedTemporaryFile()
    t = open(f.name,"w")
    t.write("""{"foo" : 3}""")
    t.close()

    s = settings._Settings(f.name)
    s.register("foo",str,"")
    self.assertFalse(s.has_unresolved_settings())
    self.assertFalse(s.is_manually_set("foo"))
    self.assertEqual(s.foo,"")
    f.close()
Пример #9
0
 def test_dup_setting(self):
     f = tempfile.NamedTemporaryFile()
     s = settings._Settings(f.name)
     s.register("foo", str, 3)
     s.register("foo", str, 3)
     f.close()
Пример #10
0
 def test_dup_setting(self):
   f = tempfile.NamedTemporaryFile()
   s = settings._Settings(f.name)
   s.register("foo",str,3)
   s.register("foo",str,3)
   f.close()