Skip to content

Commit

Permalink
modified: tests/models/test_navit.py
Browse files Browse the repository at this point in the history
modified:   tests/models/test_vit.py
modified:   tests/nn/modules/test_linearactivation.py
modified:   tests/structs/test_localtransformer.py
modified:   tests/structs/test_transformer.py
modified:   zeta/nn/modules/test_dense_connect.py
  • Loading branch information
vyomakesh09 committed Dec 28, 2023
1 parent 5f36c90 commit ca2a9ee
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 43 deletions.
19 changes: 19 additions & 0 deletions scripts/delpycache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os

Check warning

Code scanning / Pylint (reported by Codacy)

Missing module docstring Warning

Missing module docstring

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Missing module docstring Warning

Missing module docstring
import shutil
import sys


def delete_pycache(directory):

Check warning

Code scanning / Pylint (reported by Codacy)

Missing function docstring Warning

Missing function docstring

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Missing function or method docstring Warning

Missing function or method docstring

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Redefining name 'directory' from outer scope (line 17) Note

Redefining name 'directory' from outer scope (line 17)
for root, dirs, files in os.walk(directory):

Check warning

Code scanning / Prospector (reported by Codacy)

Unused variable 'files' (unused-variable) Warning

Unused variable 'files' (unused-variable)

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Unused variable 'files' Note

Unused variable 'files'
if "__pycache__" in dirs:
shutil.rmtree(os.path.join(root, "__pycache__"))


if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python delete_pycache.py <directory>")
sys.exit(1)

directory = sys.argv[1]

Check warning

Code scanning / Pylint (reported by Codacy)

Constant name "directory" doesn't conform to UPPER_CASE naming style Warning

Constant name "directory" doesn't conform to UPPER_CASE naming style
delete_pycache(directory)
print(f"__pycache__ directories deleted in {directory}")
Empty file added tests/__init__.py
Empty file.
7 changes: 0 additions & 7 deletions tests/models/test_navit.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest
import torch
from zeta.models import NaViT
from torch.nn.modules.module import ModuleAttributeError
from torch.nn import Sequential


Expand Down Expand Up @@ -72,10 +71,4 @@ def test_token_dropout(neural_network_template):
assert callable(model.calc_token_dropout)


# Test if exceptions are thrown when they should be
def test_exceptions(neural_network_template):
with pytest.raises(ModuleAttributeError):
_ = neural_network_template.non_existent_attribute


# add your test cases here..
3 changes: 2 additions & 1 deletion tests/models/test_vit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import torch
import pytest
from zeta.models import ViT, Encoder
from zeta.models import ViT
from zeta.structs import Encoder

# Sample Tests

Expand Down
8 changes: 4 additions & 4 deletions tests/nn/modules/test_linearactivation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ def test_LinearActivation_init():
"input_tensor", [(torch.tensor([1, 2, 3])), (torch.tensor([-1, 0, 1]))]
)
def test_LinearActivation_forward(input_tensor):
"""Test if the forward method of LinearActivation class retruns the same input tensor."""
"""Test if the forward method of LinearActivation class returns the same input tensor."""
act = LinearActivation()
assert torch.equal(act.forward(input_tensor), input_tensor)


@pytest.mark.parametrize("input_tensor", [(torch.tensor([1, 2, "a"]))])
def test_LinearActivation_forward_error(input_tensor):
def test_LinearActivation_forward_error():

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Function name "test_LinearActivation_forward_error" doesn't conform to snake_case naming style Warning test

Function name "test_LinearActivation_forward_error" doesn't conform to snake_case naming style
"""Test if the forward method of LinearActivation class raises an error when input tensor is not valid."""
act = LinearActivation()
with pytest.raises(TypeError):
act.forward(input_tensor)
invalid_input = [1, 2, "a"]
act.forward(torch.tensor(invalid_input))
2 changes: 1 addition & 1 deletion tests/structs/test_localtransformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import torch
from zeta.structs import LocalTransformer
from torch.autograd import gradcheck
from zeta.nn.modules.dynamic_module import DynamicPositionBias
from zeta.nn import DynamicPositionBias

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Imports from package zeta are not grouped Warning test

Imports from package zeta are not grouped


@pytest.fixture
Expand Down
3 changes: 2 additions & 1 deletion tests/structs/test_transformer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
import torch
from zeta.structs import Transformer, AttentionLayers
from zeta.structs import Transformer
from zeta.structs.transformer import AttentionLayers

# assuming that you are testing the Transformer class

Expand Down
54 changes: 25 additions & 29 deletions zeta/nn/modules/test_dense_connect.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,36 @@
import torch
import torch.nn as nn
import unittest

import pytest
from zeta.nn.modules.dense_connect import DenseBlock


class DenseBlockTestCase(unittest.TestCase):
def setUp(self):
self.submodule = nn.Linear(10, 5)
self.dense_block = DenseBlock(self.submodule)
@pytest.fixture
def dense_block():

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Missing function or method docstring Warning test

Missing function or method docstring

Check warning

Code scanning / Pylint (reported by Codacy)

Missing function docstring Warning test

Missing function docstring
submodule = nn.Linear(10, 5)
return DenseBlock(submodule)


def test_forward(self):
x = torch.randn(32, 10)
output = self.dense_block(x)
def test_forward(dense_block):

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Missing function or method docstring Warning test

Missing function or method docstring

Check warning

Code scanning / Pylint (reported by Codacy)

Missing function docstring Warning test

Missing function docstring

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Redefining name 'dense_block' from outer scope (line 8) Note test

Redefining name 'dense_block' from outer scope (line 8)
x = torch.randn(32, 10)

Check warning

Code scanning / Pylint (reported by Codacy)

Variable name "x" doesn't conform to snake_case naming style Warning test

Variable name "x" doesn't conform to snake_case naming style
output = dense_block(x)

self.assertEqual(output.shape, (32, 15)) # Check output shape
self.assertTrue(
torch.allclose(output[:, :10], x)
) # Check if input is preserved
self.assertTrue(
torch.allclose(output[:, 10:], self.submodule(x))
) # Check submodule output
assert output.shape == (32, 15) # Check output shape

Check notice

Code scanning / Bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.

Check warning

Code scanning / Bandit (reported by Codacy)

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Warning test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
assert torch.allclose(output[:, :10], x) # Check if input is preserved

Check notice

Code scanning / Bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.

Check warning

Code scanning / Bandit (reported by Codacy)

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Warning test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
assert torch.allclose(

Check notice

Code scanning / Bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.

Check warning

Code scanning / Bandit (reported by Codacy)

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Warning test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
output[:, 10:], dense_block.submodule(x)
) # Check submodule output

def test_initialization(self):
self.assertEqual(
self.dense_block.submodule, self.submodule
) # Check submodule assignment

def test_docstrings(self):
self.assertIsNotNone(
DenseBlock.__init__.__doc__
) # Check if __init__ has a docstring
self.assertIsNotNone(
DenseBlock.forward.__doc__
) # Check if forward has a docstring
def test_initialization(dense_block):

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Missing function or method docstring Warning test

Missing function or method docstring

Check warning

Code scanning / Pylint (reported by Codacy)

Missing function docstring Warning test

Missing function docstring

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Redefining name 'dense_block' from outer scope (line 8) Note test

Redefining name 'dense_block' from outer scope (line 8)
assert isinstance(dense_block.submodule, nn.Linear) # Check submodule type

Check notice

Code scanning / Bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.

Check warning

Code scanning / Bandit (reported by Codacy)

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Warning test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
assert dense_block.submodule.in_features == 10 # Check input features

Check notice

Code scanning / Bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.

Check warning

Code scanning / Bandit (reported by Codacy)

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Warning test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
assert dense_block.submodule.out_features == 5 # Check output features

Check notice

Code scanning / Bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.

Check warning

Code scanning / Bandit (reported by Codacy)

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Warning test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.


if __name__ == "__main__":
unittest.main()
def test_docstrings():

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Missing function or method docstring Warning test

Missing function or method docstring

Check warning

Code scanning / Pylint (reported by Codacy)

Missing function docstring Warning test

Missing function docstring
assert (

Check notice

Code scanning / Bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.

Check warning

Code scanning / Bandit (reported by Codacy)

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Warning test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
DenseBlock.__init__.__doc__ is not None
) # Check if __init__ has a docstring
assert (

Check notice

Code scanning / Bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.

Check warning

Code scanning / Bandit (reported by Codacy)

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Warning test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
DenseBlock.forward.__doc__ is not None
) # Check if forward has a docstring

0 comments on commit ca2a9ee

Please sign in to comment.