Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions 8 sensor/sensor_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
##############################
# Do not remove these two lines
# They are needed to validate your unittest
recs = 0
data = []
print("Sensor Data App")
##############################

# Module 1 code here:

# Module 2 code here:

# Module 3 code here:

# Module 4 code here:

# Module 5 code here:
# Module 5 code here:

# Module 6 code here:
76 changes: 21 additions & 55 deletions 76 tests/test_module1.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,70 +328,32 @@ def test_load_data_load_recs_module1(parse):

@pytest.mark.test_sensor_app_load_data_return_module1
def test_sensor_app_load_data_return_module1(parse):
# First, let's verify the user did not accidentally deleted
# the two lines provided for them.

# from load_data import load_sensor_data
# data = [] # list to store data read from files
# print("Sensor Data App")

sensor = parse("sensor_app")
assert sensor.success, sensor.message

original_data = (
sensor.assign_().match(
{
"0_type": "Assign",
"0_targets_0_type": "Name",
"0_targets_0_id": "data",
"0_value_type": "List",
}
)
.exists()
)
assert (
original_data
), """Do you have a `data` variable set to an empty list on top of the file?
You need to have these two lines of code before you being testing Module1
data = []
print("Sensor Data App")
"""
#
# data = load_sensor_data()
# print("Loaded records {}".format(len(data)))

print_app = (
sensor.calls().match(
{
"type": "Expr",
"value_type": "Call",
"value_func_type": "Name",
"value_func_id": "print",
"value_args_0_type": "Constant",
"value_args_0_value": "Sensor Data App"
}
)
.exists()
)
assert (
print_app
), """Do you have a `print("Sensor Data App")` statement?
You need to have these two lines of code before you being testing Module1
data = []
print("Sensor Data App")"""
test_file = "sensor_app"
test_class = "HouseInfo"
test_method = "__init__"


######################################################
# Now we can test the actual module
######################################################
my_file = parse(test_file)
assert my_file.success, my_file.message

# from load_data import load_sensor_data
# data = load_sensor_data()
# print("Loaded records {}".format(len(data)))

load_sensor_data_import = sensor.from_imports(
my_file_import = my_file.from_imports(
"load_data", "load_sensor_data")
assert load_sensor_data_import, "Are you importing `load_sensor_data` from load_data?"
assert my_file_import, "Are you importing `load_sensor_data` from `load_data`?"

data = (
sensor.assign_().match(
my_file.assign_().match(
{
"0_type": "Assign",
"0_targets_0_type": "Name",
"0_targets_0_id": "data",
"0_value_type": "List",
"1_type": "Assign",
"1_targets_0_type": "Name",
"1_targets_0_id": "data",
Expand All @@ -404,4 +366,8 @@ def test_sensor_app_load_data_return_module1(parse):
)
assert (
data
), "Are you creating a variable called `data` set equal to `load_sensor_data()` function?"
), """Do you have a `data` variable set to an empty list on top of the file?
Did you delete the starting code ?
data = []
print("Sensor Data App")
In a new line, are you setting `data` to `load_sensor_data()` function call?"""
4 changes: 2 additions & 2 deletions 4 tests/test_module2.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ def test_sensor_app_house_info_by_date_module2(parse):

my_file_import = my_file.from_imports(
"datetime", "date")
assert my_file_import, "Are you importing `datetime` from `datetime` module?"
assert my_file_import, "Are you importing `date` from `datetime` module?"

# debug_test_case(my_file)

Expand All @@ -550,7 +550,7 @@ def test_sensor_app_house_info_by_date_module2(parse):
)
assert (
test_code
), """Are you creating an instance of the `datetime` class called `record_date`
), """Are you creating an instance of the `datetime` class called `test_date`
which takes `"5/9/20"` and `"%m/%d/%y"` as the two arguments?"""

test_code = (
Expand Down
14 changes: 8 additions & 6 deletions 14 tests/test_module3.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ def test_temperature_by_area_method_module3(parse):
test_code
), """Are you creating a variable called `recs` set equal to
the `{}` method from the `{}` parent class?
Are you passing "temperature" as the only argument to the method call?""".format(test_method, parent_class)
Are you passing `"temperature"` as the first argument to the method call?
Are you passing `rec_area` as the second argument to the method call?""".format(test_method, parent_class)

@pytest.mark.test_temperature_by_area_method_return_module3
def test_temperature_by_area_method_return_module3(parse):
Expand Down Expand Up @@ -310,7 +311,7 @@ def test_temperature_by_date_method_module3(parse):

my_file_import = my_file.from_imports(
"datetime", "date")
assert my_file_import, "Are you importing `date` from datetime in `{}`".format(test_file)
assert my_file_import, "Are you importing `date` from `datetime` in `{}`".format(test_file)

my_class = my_file.query("class {0}({1}): ??".format(test_class, parent_class))
assert (
Expand Down Expand Up @@ -379,7 +380,8 @@ def test_temperature_by_date_method_module3(parse):
test_code
), """Are you creating a variable called `recs` set equal to
the `{}` method from the `{}` parent class?
Are you passing "temperature" as the only argument to the method call?""".format(test_method, parent_class)
Are you passing `"temperature"` as the first argument to the method call?
Are you passing `rec_date` as the second argument to the method call?""".format(test_method, parent_class)

@pytest.mark.test_temperature_by_date_method_return_module3
def test_temperature_by_date_method_return_module3(parse):
Expand Down Expand Up @@ -449,7 +451,7 @@ def test_sensor_app_temp_info_by_area_module3(parse):

my_file_import = my_file.from_imports(
"temperature_info", "TemperatureData")
assert my_file_import, "Are you importing `TemperatureData` from `temperature_info` in `{}`".format(test_file)
assert my_file_import, "Are you importing `{0}` from `temperature_info` in `{}`".format(test_file)

# debug_test_case(my_file)

Expand All @@ -470,8 +472,8 @@ def test_sensor_app_temp_info_by_area_module3(parse):
)
assert (
test_code
), """Are you creating an instance of the '{}' class with
`data` list as the initialization argument for the constructor?
), """Are you creating an instance of the '{}' class called `temperature_data`?
Are you passing `data` list as the initialization argument for the constructor?
""".format(test_class)

test_code = (
Expand Down
27 changes: 14 additions & 13 deletions 27 tests/test_module4.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_humidity_convert_loop_module4(parse):
assert (
my_class.exists()
), """Have you created a class called `{0}`?
Is your class inheritings the properties of the `{1}` class?""".format(test_class, parent_class)
Is your class inheriting the properties of the `{1}` class?""".format(test_class, parent_class)

my_method = my_file.class_(test_class).method(test_method)
assert (
Expand Down Expand Up @@ -141,7 +141,7 @@ def test_humidity_convert_loop_module4(parse):
)
assert (
test_code
), """Inside your loop, are you converting `rec` value to `float()` and multipling it by `100`
), """Inside your loop, are you converting `rec` value to `float()` and multiplying it by `100`?
Are you appending it to `recs` list?"""

test_code= (
Expand Down Expand Up @@ -237,7 +237,8 @@ def test_humidity_by_area_and_method_module4(parse):
test_code
), """Are you creating a variable called `recs` set equal to
the `{}` method from the `{}` parent class?
Are you passing "humidity" as the only argument to the method call?""".format(test_method, parent_class)
Are you passing `"humidity"` as the first argument to the method call?
Are you passing `rec_area` as the second argument to the method call?""".format(test_method, parent_class)

test_code = (
my_method.returns_call().match(
Expand Down Expand Up @@ -347,7 +348,8 @@ def test_humidity_by_date_method_module4(parse):
test_code
), """Are you creating a variable called `recs` set equal to
the `{}` method from the `{}` parent class?
Are you passing "humidity" as the only argument to the method call?""".format(test_method, parent_class)
Are you passing `"humidity"` as the first argument to the method call?
Are you passing `rec_date` as the second argument to the method call?""".format(test_method, parent_class)

test_code = (
my_method.returns_call().match(
Expand Down Expand Up @@ -392,9 +394,6 @@ def test_sensor_app_temp_info_by_area_module4(parse):
"humidity_info", "HumidityData")
assert my_file_import, "Are you importing `HumidityData` from `humidity_info` in `{}`".format(test_file)

my_file_import = my_file.from_imports(
"statistics", "mean")
assert my_file_import, "Are you importing `mean` from `statistics` in `{}`".format(test_file)

# debug_test_case(my_file)

Expand All @@ -415,8 +414,8 @@ def test_sensor_app_temp_info_by_area_module4(parse):
)
assert (
test_code
), """Are you creating an instance of the '{}' class with
`data` list as the initialization argument for the constructor?
), """Are you creating an instance of the '{}' class called `humidity_data`?
Are you passing `data` as the initialization argument for the constructor?
""".format(test_class)

test_code = (
Expand Down Expand Up @@ -726,7 +725,8 @@ def test_particle_by_area_and_date_methods_module4(parse):
test_code
), """Are you creating a variable called `recs` set equal to
the `{}` method from the `{}` parent class?
Are you passing "particle" as the only argument to the method call?""".format(test_method, parent_class)
Are you passing `"particulate"` as the first argument to the method call?
Are you passing `rec_area` as the second argument to the method call?""".format(test_method, parent_class)

test_code = (
my_method.returns_call().match(
Expand Down Expand Up @@ -819,7 +819,8 @@ def test_particle_by_area_and_date_methods_module4(parse):
test_code
), """Are you creating a variable called `recs` set equal to
the `{}` method from the `{}` parent class?
Are you passing "particle" as the only argument to the method call?""".format(test_method, parent_class)
Are you passing `"particulate"` as the first argument to the method call?
Are you passing `rec_date`as the second argument to the method call?""".format(test_method, parent_class)

test_code = (
my_method.returns_call().match(
Expand Down Expand Up @@ -1031,8 +1032,8 @@ def test_sensor_app_particle_info_by_area_module4(parse):
)
assert (
test_code
), """Are you creating an instance of the '{}' class with
`data` list as the initialization argument for the constructor?
), """Are you creating an instance of the '{}' class called `particle_data`?
Are you passing `data` as the initialization argument for the constructor?
""".format(test_class)

test_code = (
Expand Down
30 changes: 10 additions & 20 deletions 30 tests/test_module5.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def test_energy_create_class_module5(parse):
assert (
my_class.exists()
), """Have you created a class called `{0}`?
Is your class inheritings the properties of the `{1}` class?""".format(test_class, parent_class)
Is your class inheriting the properties of the `{1}` class?""".format(test_class, parent_class)

# debug_test_case_class(my_class, test_method)
debug_test_case_class(my_class, test_method)

test_code = (
my_class.assign_().match(
Expand All @@ -37,18 +37,7 @@ def test_energy_create_class_module5(parse):
"0_targets_0_id": "ENERGY_PER_BULB",
"0_value_type": "Constant",
"0_value_value": "#<float>",
}
)
.exists()
)
assert (
test_code
), """Are you declararing a constant `ENERGY_PER_BULB`?
Did you set it to `0.2` float number?"""

test_code = (
my_class.assign_().match(
{

"1_type": "Assign",
"1_targets_0_type": "Name",
"1_targets_0_id": "ENERGY_BITS",
Expand All @@ -60,8 +49,11 @@ def test_energy_create_class_module5(parse):
)
assert (
test_code
), """Are you declararing a constant `ENERGY_BITS`?
), """Are you declararing a constant `ENERGY_PER_BULB`?
Did you set it to `0.2` float number?
Are you declararing a constant `ENERGY_BITS`?
Did you set it to `0x0F0` hex number?"""


@pytest.mark.test_energy_get_energy_method_module5
def test_energy_get_energy_method_module5(parse):
Expand All @@ -70,7 +62,6 @@ def test_energy_get_energy_method_module5(parse):
# rec = rec & ENERGY_BITS # mask ENERGY bits
# rec = rec >> 4 # shift right
# return rec

test_file = "energy_info"
parent_class = "HouseInfo"
test_class = "EnergyData"
Expand Down Expand Up @@ -670,8 +661,8 @@ def test_sensor_app_energy_info_by_area_module5(parse):
)
assert (
test_code
), """Are you creating an instance of the '{}' class with
`data` list as the initialization argument for the constructor?
), """Are you creating an instance of the '{}' class called `energy_data`
Are you passing `data` as the initialization argument for the constructor?
""".format(test_class)

test_code = (
Expand Down Expand Up @@ -789,6 +780,5 @@ def test_sensor_app_energy_info_by_date_module5(parse):
assert (
test_code
), """Are you setting `total_energy` to the method call `calculate_energy` from the `energy_data` object?
Are you pasing `get_data_by_date` method of the same object as input argument?
Are you passing `rec_date=test_date` as the argument to `get_data_by_date` method?
Are you passing `data=recs` as the only argument to the method?
"""
Morty Proxy This is a proxified and sanitized view of the page, visit original site.