Skip to content

Commit a66da4d

Browse files
committed
nose2pytest test_university
1 parent baf74a6 commit a66da4d

File tree

1 file changed

+28
-30
lines changed

1 file changed

+28
-30
lines changed

tests/test_university.py

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ def test_activate():
4141
def test_fill():
4242
"""check that the randomized tables are consistently defined"""
4343
# check randomized tables
44-
assert_true(len(Student()) == 300 and _hash4(Student) == "1e1a")
45-
assert_true(len(StudentMajor()) == 226 and _hash4(StudentMajor) == "3129")
46-
assert_true(len(Section()) == 756 and _hash4(Section) == "dc7e")
47-
assert_true(len(Enroll()) == 3364 and _hash4(Enroll) == "177d")
48-
assert_true(len(Grade()) == 3027 and _hash4(Grade) == "4a9d")
44+
assert len(Student()) == 300 and _hash4(Student) == "1e1a"
45+
assert len(StudentMajor()) == 226 and _hash4(StudentMajor) == "3129"
46+
assert len(Section()) == 756 and _hash4(Section) == "dc7e"
47+
assert len(Enroll()) == 3364 and _hash4(Enroll) == "177d"
48+
assert len(Grade()) == 3027 and _hash4(Grade) == "4a9d"
4949

5050

5151
def test_restrict():
@@ -55,7 +55,7 @@ def test_restrict():
5555
"""
5656
utahns1 = Student & {"home_state": "UT"}
5757
utahns2 = Student & 'home_state="UT"'
58-
assert_true(len(utahns1) == len(utahns2.fetch("KEY")) == 7)
58+
assert len(utahns1) == len(utahns2.fetch("KEY")) == 7
5959

6060
# male nonutahns
6161
sex1, state1 = ((Student & 'sex="M"') - {"home_state": "UT"}).fetch(
@@ -64,8 +64,8 @@ def test_restrict():
6464
sex2, state2 = ((Student & 'sex="M"') - {"home_state": "UT"}).fetch(
6565
"sex", "home_state", order_by="student_id"
6666
)
67-
assert_true(len(set(state1)) == len(set(state2)) == 44)
68-
assert_true(set(sex1).pop() == set(sex2).pop() == "M")
67+
assert len(set(state1)) == len(set(state2)) == 44
68+
assert set(sex1).pop() == set(sex2).pop() == "M"
6969

7070
# students from OK, NM, TX
7171
s1 = (Student & [{"home_state": s} for s in ("OK", "NM", "TX")]).fetch(
@@ -74,72 +74,70 @@ def test_restrict():
7474
s2 = (Student & 'home_state in ("OK", "NM", "TX")').fetch(
7575
"KEY", order_by="student_id"
7676
)
77-
assert_true(len(s1) == 11)
78-
assert_list_equal(s1, s2)
77+
assert len(s1) == 11
78+
assert s1 == s2
7979

8080
millennials = Student & 'date_of_birth between "1981-01-01" and "1996-12-31"'
81-
assert_true(len(millennials) == 170)
81+
assert len(millennials) == 170
8282
millennials_no_math = millennials - (Enroll & 'dept="MATH"')
83-
assert_true(len(millennials_no_math) == 53)
83+
assert len(millennials_no_math) == 53
8484

8585
inactive_students = Student - (Enroll & CurrentTerm)
86-
assert_true(len(inactive_students) == 204)
86+
assert len(inactive_students) == 204
8787

8888
# Females who are active or major in non-math
8989
special = Student & [Enroll, StudentMajor - {"dept": "MATH"}] & {"sex": "F"}
90-
assert_true(len(special) == 158)
90+
assert len(special) == 158
9191

9292

9393
def test_advanced_join():
9494
"""test advanced joins"""
9595
# Students with ungraded courses in current term
9696
ungraded = Enroll * CurrentTerm - Grade
97-
assert_true(len(ungraded) == 34)
97+
assert len(ungraded) == 34
9898

9999
# add major
100100
major = StudentMajor.proj(..., major="dept")
101-
assert_true(len(ungraded.join(major, left=True)) == len(ungraded) == 34)
102-
assert_true(len(ungraded.join(major)) == len(ungraded & major) == 31)
101+
assert len(ungraded.join(major, left=True)) == len(ungraded) == 34
102+
assert len(ungraded.join(major)) == len(ungraded & major) == 31
103103

104104

105105
def test_union():
106106
# effective left join Enroll with Major
107107
q1 = (Enroll & "student_id=101") + (Enroll & "student_id=102")
108108
q2 = Enroll & "student_id in (101, 102)"
109-
assert_true(len(q1) == len(q2) == 41)
109+
assert len(q1) == len(q2) == 41
110110

111111

112112
def test_aggr():
113113
avg_grade_per_course = Course.aggr(
114114
Grade * LetterGrade, avg_grade="round(avg(points), 2)"
115115
)
116-
assert_true(len(avg_grade_per_course) == 45)
116+
assert len(avg_grade_per_course) == 45
117117

118118
# GPA
119119
student_gpa = Student.aggr(
120120
Course * Grade * LetterGrade, gpa="round(sum(points*credits)/sum(credits), 2)"
121121
)
122122
gpa = student_gpa.fetch("gpa")
123-
assert_true(len(gpa) == 261)
124-
assert_true(2 < gpa.mean() < 3)
123+
assert len(gpa) == 261
124+
assert 2 < gpa.mean() < 3
125125

126126
# Sections in biology department with zero students in them
127127
section = (Section & {"dept": "BIOL"}).aggr(
128128
Enroll, n="count(student_id)", keep_all_rows=True
129129
) & "n=0"
130-
assert_true(len(set(section.fetch("dept"))) == 1)
131-
assert_true(len(section) == 17)
132-
assert_true(bool(section))
130+
assert len(set(section.fetch("dept"))) == 1
131+
assert len(section) == 17
132+
assert bool(section)
133133

134134
# Test correct use of ellipses in a similar query
135135
section = (Section & {"dept": "BIOL"}).aggr(
136136
Grade, ..., n="count(student_id)", keep_all_rows=True
137137
) & "n>1"
138-
assert_false(
139-
any(
138+
assert not any(
140139
name in section.heading.names for name in Grade.heading.secondary_attributes
141140
)
142-
)
143-
assert_true(len(set(section.fetch("dept"))) == 1)
144-
assert_true(len(section) == 168)
145-
assert_true(bool(section))
141+
assert len(set(section.fetch("dept"))) == 1
142+
assert len(section) == 168
143+
assert bool(section)

0 commit comments

Comments
 (0)