Skip to content
Snippets Groups Projects
Commit 5e1782bc authored by Hussain Kanafani's avatar Hussain Kanafani
Browse files

has_string method implemented and tested

parent 52dcc433
No related branches found
No related tags found
No related merge requests found
......@@ -101,3 +101,12 @@ def drop_file_extension(file_name):
raise ValueError
file_name = file_name.split('.')[:-1]
return '.'.join(file_name)
def has_string(string, sub_string):
if string is None or sub_string is None:
raise ValueError
string = str(string).lower()
sub_string = str(sub_string).lower()
return sub_string in string
from unittest import TestCase
import unittest.mock as mock
from src.utils import digits_in_string, make_directory, read_json, drop_file_extension, make_sorted_sample, \
sample_from_video_with_gt
from src.utils import *
import random
import os.path as osp
import os
......@@ -73,4 +72,11 @@ class TestUtils(TestCase):
user_scores=np.expand_dims(user_scores, axis=1)
video_frames = list(np.random.randn(n_frames))
sampled_frames, sampled_gt = sample_from_video_with_gt(video_frames, user_scores, duration, fps, n_samples=2)
self.assertEquals(len(sampled_frames), len(sampled_gt))
\ No newline at end of file
self.assertEquals(len(sampled_frames), len(sampled_gt))
def test_has_string(self):
self.assertTrue(has_string('Frame123','frame'))
self.assertTrue(has_string('frame123', 'Frame'))
self.assertFalse(has_string('', 'frame'))
with self.assertRaises(ValueError):
has_string(None,'string')
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment