Skip to content

Commit

Permalink
Update unittest logging
Browse files Browse the repository at this point in the history
  • Loading branch information
TimKoornstra committed Aug 17, 2023
1 parent 3a11b03 commit 5d3f050
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 9 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Run Tests
on: [push, pull_request]

jobs:
test:
unittests:
runs-on: ubuntu-latest

steps:
Expand All @@ -26,18 +26,26 @@ jobs:
- name: Test utils
run: |
python -m unittest tests/test_utils.py
env:
TF_CPP_MIN_LOG_LEVEL: '2'

- name: Test DataGeneratorNew2
if: always()
run: |
python -m unittest tests/test_datagenerator.py
env:
TF_CPP_MIN_LOG_LEVEL: '2'

- name: Test DataLoaderNew
if: always()
run: |
python -m unittest tests/test_dataloader.py
env:
TF_CPP_MIN_LOG_LEVEL: '2'

- name: Test basic model creation
- name: Test model creation
if: always()
run: |
python -m unittest tests/test_model_creation.py
env:
TF_CPP_MIN_LOG_LEVEL: '2'
8 changes: 8 additions & 0 deletions tests/test_datagenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import numpy as np

# > Standard library
import logging
import os
import sys
import unittest
Expand All @@ -28,6 +29,13 @@ class TestDataGenerator(unittest.TestCase):

@classmethod
def setUpClass(cls):
# Set up logging
logging.basicConfig(
format="%(asctime)s - %(levelname)s - %(message)s",
datefmt="%d/%m/%Y %H:%M:%S",
level=logging.ERROR,
)

# Determine the directory of this file
current_file_dir = os.path.dirname(os.path.realpath(__file__))

Expand Down
8 changes: 8 additions & 0 deletions tests/test_dataloader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Imports

# > Standard library
import logging
import os
import sys
import tempfile
Expand Down Expand Up @@ -35,6 +36,13 @@ class DataLoaderTest(unittest.TestCase):

@classmethod
def setUpClass(cls):
# Set up logging
logging.basicConfig(
format="%(asctime)s - %(levelname)s - %(message)s",
datefmt="%d/%m/%Y %H:%M:%S",
level=logging.ERROR,
)

# Determine the directory of this file
current_file_dir = os.path.dirname(os.path.realpath(__file__))

Expand Down
21 changes: 14 additions & 7 deletions tests/test_model_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from tensorflow.keras import activations

# > Standard library
import logging
import unittest
import sys

Expand Down Expand Up @@ -37,7 +38,13 @@ class VGSLModelGeneratorTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
sys.path.append("./src")
tf.get_logger().setLevel('ERROR')

# Set up logging
logging.basicConfig(
format="%(asctime)s - %(levelname)s - %(message)s",
datefmt="%d/%m/%Y %H:%M:%S",
level=logging.ERROR,
)

from vgsl_model_generator import VGSLModelGenerator
cls.VGSLModelGenerator = VGSLModelGenerator
Expand Down Expand Up @@ -197,7 +204,7 @@ def test_fully_connected_layer(self):
self.assertEqual(model.layers[5].activation, activations.softmax)

def test_lstm_layer(self):
vgsl_spec_string = "None,64,None,1 Rc Lfxs128 O1s10"
vgsl_spec_string = "None,64,None,1 Rc Lfs128 O1s10"
model_generator = self.VGSLModelGenerator(vgsl_spec_string)
model = model_generator.build()
self.assertIsInstance(model.layers[2], layers.LSTM)
Expand All @@ -208,15 +215,15 @@ def test_lstm_layer(self):
self.assertEqual(model.layers[2].return_sequences, True)

# Check backwards LSTM with return_sequences
vgsl_spec_string = "None,64,None,1 Rc Lrx128 O1s10"
vgsl_spec_string = "None,64,None,1 Rc Lr128 O1s10"
model_generator = self.VGSLModelGenerator(vgsl_spec_string)
model = model_generator.build()

self.assertEqual(model.layers[2].go_backwards, True)
self.assertEqual(model.layers[2].return_sequences, False)

def test_gru_layer(self):
vgsl_spec_string = "None,64,None,1 Rc Gfxs128 O1s10"
vgsl_spec_string = "None,64,None,1 Rc Gfs128 O1s10"
model_generator = self.VGSLModelGenerator(vgsl_spec_string)
model = model_generator.build()
self.assertIsInstance(model.layers[2], layers.GRU)
Expand All @@ -227,22 +234,22 @@ def test_gru_layer(self):
self.assertEqual(model.layers[2].return_sequences, True)

# Check backwards GRU with return_sequences
vgsl_spec_string = "None,64,None,1 Rc Grx128 O1s10"
vgsl_spec_string = "None,64,None,1 Rc Gr128 O1s10"
model_generator = self.VGSLModelGenerator(vgsl_spec_string)
model = model_generator.build()

self.assertEqual(model.layers[2].go_backwards, True)
self.assertEqual(model.layers[2].return_sequences, False)

def test_bidirectional_layer(self):
vgsl_spec_string = "None,64,None,1 Rc Bgxs128 O1s10"
vgsl_spec_string = "None,64,None,1 Rc Bgs128 O1s10"
model_generator = self.VGSLModelGenerator(vgsl_spec_string)
model = model_generator.build()
self.assertIsInstance(model.layers[2], layers.Bidirectional)
self.assertIsInstance(model.layers[2].layer, layers.GRU)
self.assertEqual(model.layers[2].layer.units, 128)

vgsl_spec_string = "None,64,None,1 Rc Blxs128 O1s10"
vgsl_spec_string = "None,64,None,1 Rc Bls128 O1s10"
model_generator = self.VGSLModelGenerator(vgsl_spec_string)
model = model_generator.build()
self.assertIsInstance(model.layers[2], layers.Bidirectional)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import numpy as np

# > Standard library
import logging
import unittest
import os
import sys
Expand All @@ -13,6 +14,13 @@
class TestUtils(unittest.TestCase):
@classmethod
def setUpClass(cls):
# Set up logging
logging.basicConfig(
format="%(asctime)s - %(levelname)s - %(message)s",
datefmt="%d/%m/%Y %H:%M:%S",
level=logging.ERROR,
)

# Determine the directory of this file
current_file_dir = os.path.dirname(os.path.realpath(__file__))

Expand Down

0 comments on commit 5d3f050

Please sign in to comment.