def test_hidden_folders_removed_from_subject_list(self, mock_walk,
                                                      mock_exists):
        mock_exists.return_value = True
        walk = (self.path, ['subject1', '.git', 'subject2', '.hidden2'], [])
        mock_walk.return_value.next.return_value = walk

        subjects = utilities.get_subj(self.path)

        assert sorted(list(subjects)) == sorted(['subject1', 'subject2'])
    def test_doesnt_crash_when_no_subjects_found(self, mock_walk, mock_exists):
        # Pretend the path exists, but is empty dir
        mock_exists.return_value = True
        walk = (self.path, [], [])
        mock_walk.return_value.next.return_value = walk

        subjects = utilities.get_subj(self.path)

        assert subjects == []
    def test_user_filter_removes_tagged_subjects(self, mock_walk, mock_exists):
        # Set up list of tagged and untagged subjects
        tagged_subjects = [
            'STUDY_CMH_0000_01', 'STUDY_CMH_9999_01', 'STUDY_CMH_1234_01'
        ]
        all_subjects = ['STUDY_MRP_1234_01', 'STUDY_MRP_0001_01']
        all_subjects.extend(tagged_subjects)
        random.shuffle(all_subjects)

        # Set up mocks
        mock_exists.return_value = True
        walk = (self.path, all_subjects, [])
        mock_walk.return_value.next.return_value = walk

        subjects = utilities.get_subj(self.path, user_filter='CMH')

        assert sorted(list(subjects)) == sorted(tagged_subjects)
    def test_all_subjects_returned(self, mock_walk, mock_exists):
        # Set up list of subjects with different site tags
        all_subjects = [
            'STUDY_CMH_0000_01', 'STUDY_CMH_9999_01', 'STUDY_CMH_1234_01',
            'STUDY_MRP_1234_01', 'STUDY_MRP_0001_01'
        ]
        random.shuffle(all_subjects)

        # Set up mocks
        mock_exists.return_value = True
        walk = (self.path, all_subjects, [])
        mock_walk.return_value.next.return_value = walk
        print(next(os.walk(self.path))[1])

        subjects = list(utilities.get_subj(self.path))
        print(subjects)
        print(all_subjects)

        # Subjects must be wrapped in list call because py3 returns a generator
        assert sorted(list(subjects)) == sorted(all_subjects)
    def test_returns_empty_list_if_path_doesnt_exist(self):
        assert not os.path.exists(self.path)

        subjects = utilities.get_subj(self.path)
        assert subjects == []