예제 #1
0
파일: yayv_test.py 프로젝트: arthurw9/yayv
 def testErrorMessages(self):
   s = yayv.ByExample("{id: AUTO_INC, name: REQUIRED}")
   s.IsValid("first_name: Boo")
   self.AssertEqual("# first_name is not in the schema in ROOT", s.ErrorMessage())
   s = yayv.ByExample("{id: AUTO_INC, name: REQUIRED}")
   s.IsValid("name:")
   self.AssertEqual("# REQUIRED field missing in ROOT.name", s.ErrorMessage())
   s = yayv.ByExample("{id: AUTO_INC, name: REQUIRED}")
   s.IsValid("")
   self.AssertEqual("# Expect yaml_obj to be a dict but it is: None in ROOT", s.ErrorMessage())
   s = yayv.ByExample("- {id: AUTO_INC, name: OPTIONAL}")
   s.IsValid("[ name: arthur, name: olga, names: sarah ]")
   self.AssertEqual("# names is not in the schema in ROOT[2]", s.ErrorMessage())
   s = yayv.ByExample("- {id: AUTO_INC, name: OPTIONAL}")
   s.IsValid("[ name: arthur, name: olga, names: sarah ]")
   self.AssertEqual("# names is not in the schema in ROOT[2]", s.ErrorMessage())
   s = yayv.ByExample("- {id: AUTO_INC, name: OPTIONAL}")
   s.IsValid("[ id: 1, id: 2 ]")
   self.AssertEqual("# ", s.ErrorMessage())
   s = yayv.ByExample("- {id: AUTO_INC, name: OPTIONAL}")
   s.IsValid("[ id: 1, id: 1 ]")
   self.AssertEqual("# duplicate AUTO_INC 1 found in ROOT[1].id", s.ErrorMessage())
   s = yayv.ByExample("- {id1: AUTO_INC 1, id2: AUTO_INC 2, name: UNIQUE a, name2: UNIQUE b}")
   s.IsValid("[ {id1: 1, name: arthur, name2: sarah}, {id2: 1, name: sarah, name2: arthur} ]")
   self.AssertEqual("# ", s.ErrorMessage())
   s = yayv.ByExample("- {name: OPTIONAL, schedule: [ {daypart: UNIQUE 1, room: OPTIONAL} ]}")
   s.IsValid("[ {name: foo, schedule: [ {daypart: monday a, room: 200}, {daypart: tuesday a, room: 200}]}]")
   self.AssertEqual("# ", s.ErrorMessage())
   s = yayv.ByExample("- {name: OPTIONAL, schedule: [ {daypart: UNIQUE 1, room: OPTIONAL} ]}")
   s.IsValid("[ {name: foo, schedule: [ {daypart: monday a, room: 200}, {daypart: monday a, room: 300}]}]")
   self.AssertEqual("# Duplicate Value monday a in UNIQUE 1 in ROOT[0].schedule[1].daypart", s.ErrorMessage())
예제 #2
0
 def testAutoInc(self):
   s = yayv.ByExample("[ {id: AUTO_INC, name: REQUIRED} ]")
   self.Assert(s, "[name: arthur, name: sarah, name: olga]", True)
   s = yayv.ByExample("[ {id: AUTO_INC, name: REQUIRED} ]")
   self.Assert(s, "[{name: arthur, id: 7}, name: sarah, name: olga]", True)
   if s.counters[''] != 7:
     self.FailWithMessage(s, "n/a", "counter starts at 8", s.counters[''])
   self.Assert(s, "[{name: arthur, id: 7}, name: sarah, name: olga]", True)
예제 #3
0
 def testList(self):
   s = yayv.ByExample("[OPTIONAL]")
   self.Assert(s, "[a, b, c]", True)
   self.Assert(s, "a: b", False)
   self.Assert(s, "[]", True)
   self.Assert(s, "", True)
   self.Assert(s, "[a, a, a]", True)
예제 #4
0
def Students():
    return yayv.ByExample("- email: UNIQUE\n"
                          "  first: REQUIRED\n"
                          "  last: REQUIRED\n"
                          "  current_grade: REQUIRED\n"
                          "  current_homeroom: REQUIRED\n"
                          "  edtechid: OPTIONAL\n")
예제 #5
0
 def testRealisticIsValidFails(self):
   s = yayv.ByExample(
       "- name: REQUIRED\n"
       "  id: AUTO_INC\n"
       "  instructor: OPTIONAL\n"
       "  max_enrollment: REQUIRED\n"
       "  prerequisites:\n"
       "    - current_grade: OPTIONAL\n"
       "      email: OPTIONAL\n"
       "      group: OPTIONAL\n"
       "  schedule:\n"
       "    - daypart: OPTIONAL\n"
       "      location: OPTIONAL\n")
   s.IsValid(
       "- name: 3D Printing\n"
       "  instructor: Mr. Brown\n"
       "  max_enrollment: 16\n"
       "  prerequisites: []\n"
       "    - current_grade: 8\n"
       "  schedule:\n"
       "    - daypart: Fri A\n"
       "      location: 25\n")
   self.AssertTrue(s.ErrorMessage().startswith("# Traceback"))
   self.AssertTrue("- name: 3D Printing" in s.ErrorMessage())
   self.AssertTrue("- current_grade: 8" in s.ErrorMessage())
예제 #6
0
 def testDict(self):
   s = yayv.ByExample("{ abc: REQUIRED, xyz: OPTIONAL }")
   self.Assert(s, "{abc: Hello, xyz: There}", True)
   self.Assert(s, "{abc: Hello}", True)
   self.Assert(s, "{xyz: Hello}", False)
   self.Assert(s, "{foo: Hello}", False)
   self.Assert(s, "foo", False)
   self.Assert(s, "[a, b, c]", False)
예제 #7
0
def AutoRegister():
    return yayv.ByExample(
        "- class: OPTIONAL\n"  # for human use
        "  class_id: REQUIRED\n"  # should match id from Classes
        "  applies_to:\n"
        "    - current_grade: OPTIONAL\n"
        "      email: OPTIONAL\n"
        "      group: OPTIONAL\n"
        "  id: OPTIONAL\n"
        "  exempt:\n"
        "    - OPTIONAL\n")
예제 #8
0
def Requirements():
    return yayv.ByExample("- name: REQUIRED\n"
                          "  applies_to:\n"
                          "    - current_grade: OPTIONAL\n"
                          "      email: OPTIONAL\n"
                          "      group: OPTIONAL\n"
                          "  id: AUTO_INC\n"
                          "  exempt:\n"
                          "    - OPTIONAL\n"
                          "  class_or_group_options:\n"
                          "    - \n"
                          "      - OPTIONAL\n")
예제 #9
0
  def testRealisticUpdate(self):
    schema = yayv.ByExample(
        "- name: REQUIRED\n"
        "  id: AUTO_INC\n"
        "  instructor: OPTIONAL\n"
        "  max_enrollment: REQUIRED\n"
        "  prerequisites:\n"
        "    - current_grade: OPTIONAL\n"
        "      email: OPTIONAL\n"
        "      group: OPTIONAL\n"
        "  schedule:\n"
        "    - daypart: REQUIRED\n"
        "      location: REQUIRED\n")
    str = schema.Update('\n'.join([
        "- instructor: Mr. McCartney",
        "  max_enrollment: 81",
        "  name: 8th Grade Core",
        "  prerequisites:",
        "  - current_grade: 8",
        "  schedule:",
        "  - daypart: Mon A",
        "    location: Homeroom",
        "  - daypart: Mon B",
        "    location: Homeroom",
        "  - daypart: Thurs A",
        "    location: Homeroom"]))

    # run the unit under test
    actual = schema.Update(str)

    expected = '\n'.join([
        "- id: 1",
        "  instructor: Mr. McCartney",
        "  max_enrollment: 81",
        "  name: 8th Grade Core",
        "  prerequisites:",
        "  - current_grade: 8",
        "  schedule:",
        "  - daypart: Mon A",
        "    location: Homeroom",
        "  - daypart: Mon B",
        "    location: Homeroom",
        "  - daypart: Thurs A",
        "    location: Homeroom",
        ""])
    self.AssertEqual(expected, actual)
예제 #10
0
def Classes():
    return yayv.ByExample("- name: REQUIRED\n"
                          "  id: AUTO_INC\n"
                          "  instructor: OPTIONAL\n"
                          "  max_enrollment: REQUIRED\n"
                          "  prerequisites:\n"
                          "    - current_grade: OPTIONAL\n"
                          "      email: OPTIONAL\n"
                          "      group: OPTIONAL\n"
                          "  schedule:\n"
                          "    - daypart: REQUIRED\n"
                          "      location: REQUIRED\n"
                          "  description: OPTIONAL\n"
                          "  donation: OPTIONAL\n"
                          "  exclude_from_catalog: OPTIONAL\n"
                          "  owners:\n"
                          "    - OPTIONAL\n"
                          "  open_enrollment: OPTIONAL\n"
                          "  fitness: OPTIONAL\n")
예제 #11
0
 def testUniq(self):
   s = yayv.ByExample("[{ id: UNIQUE, xyz: OPTIONAL }]")
   self.Assert(s, "[{id: Hello, xyz: There}, {id: There, xyz: Blue}]", True)
   self.Assert(s, "[{id: Hello, xyz: Hello}, {id: There, xyz: Blue}]", True)
   self.Assert(s, "[{id: Hello, xyz: There}, {id: Hello, xyz: Blue}]", False)
   self.Assert(s, "[{id: Hello, xyz: There}, {xyz: Blue}]", False)
예제 #12
0
def ClassGroups():
    return yayv.ByExample("- name: REQUIRED\n"
                          "  id: AUTO_INC\n"
                          "  classes:\n"
                          "    - name: OPTIONAL\n"  # for human use
                          "      id: REQUIRED\n")
예제 #13
0
def Teachers():
    return yayv.ByExample("- email: UNIQUE\n"
                          "  first: REQUIRED\n"
                          "  last: REQUIRED\n"
                          "  current_homeroom: OPTIONAL\n")
예제 #14
0
 def testNumbers(self):
   s = yayv.ByExample("OPTIONAL")
   self.Assert(s, "123", True)
   s = yayv.ByExample("REQUIRED")
   self.Assert(s, "123", True)
예제 #15
0
 def testRequired(self):
   s = yayv.ByExample("REQUIRED")
   self.Assert(s, "abc", True);
   self.Assert(s, "", False);
   self.Assert(s, "a: b", False);
   self.Assert(s, "[a, b, c]", False);
예제 #16
0
 def testSyntax(self):
   s = yayv.ByExample("OPTIONAL")
   self.Assert(s, "[ a, b", False)
   self.Assert(s, "- a\n- b\nc:d\n", False)
   self.Assert(s, "", True)
예제 #17
0
 def testValue(self):
   s = yayv.ByExample("OPTIONAL")
   self.Assert(s, "abc", True);
   self.Assert(s, "", True);
   self.Assert(s, "a: b", False);
   self.Assert(s, "[a, b, c]", False);
예제 #18
0
 def testBadSchema(self):
   s = yayv.ByExample("[a, b]")
   self.AssertThrows(s, "[a, b]")
예제 #19
0
def StudentGroups():
    return yayv.ByExample("- group_name: REQUIRED\n"
                          "  emails:\n"
                          "    - REQUIRED\n")
예제 #20
0
 def testUniqList(self):
   s = yayv.ByExample("[ UNIQUE ]")
   self.Assert(s, "[a, a, a]", False)
   self.Assert(s, "[a, b, c]", True)
예제 #21
0
def ServingRules():
    return yayv.ByExample("- name: REQUIRED\n"
                          "  allow:\n"
                          "    - current_grade: OPTIONAL\n"
                          "      current_homeroom: OPTIONAL\n"
                          "      email: OPTIONAL\n")
예제 #22
0
def Links():
    return yayv.ByExample("- name: REQUIRED\n" "  url: REQUIRED\n")
예제 #23
0
 def testAutoIncCounter(self):
   s = yayv.ByExample("- {id: AUTO_INC, name: REQUIRED}")
   n = s.Update("[{name: foo}, {name: bar}]")
   n = yaml.load(n)
   self.AssertEqual({"name": "foo", "id": 1}, n[0])
   self.AssertEqual({"name": "bar", "id": 2}, n[1])
예제 #24
0
def Dayparts():
    return yayv.ByExample("- name: UNIQUE\n"
                          "  row: REQUIRED\n"
                          "  col: REQUIRED\n"
                          "  rowspan: OPTIONAL\n"
                          "  colspan: OPTIONAL\n")