示例#1
0
    def test_alias_constraints(self):
        """ The PatternDataSet should be able to alias Constraints.

        This means when asked to get files for the aliased Constraint, it should
        return files from another Constraints.

        """

        with mock.patch('cwsl.core.pattern_dataset.PatternDataSet.glob_fs'
                        ) as mock_glob:
            mock_glob.return_value = self.mock_file_list

            pattern_ds = PatternDataSet(self.mock_file_pattern)

            # Apply the constraint alias - when asked for hue,
            # it will give you colour.
            pattern_ds.alias_constraint("colour", "hue")

            found_files = pattern_ds.get_files({
                'hue': 'red',
                'animal': 'kangaroo'
            })

            self.assertEqual(1, len(found_files))
            self.assertEqual("/fake/red_kangaroo.txt",
                             found_files[0].full_path)
    def test_getfiles(self):
        """ Ensure that files are correctly returned using 'get_files'. """

        with mock.patch('cwsl.core.pattern_dataset.PatternDataSet.glob_fs') as mock_glob:

            # Add the mock fake glob function.
            mock_glob.return_value = self.mock_file_list
            
            test_patternds = PatternDataSet(self.mock_file_pattern)
            
            found_files = test_patternds.get_files({'colour': 'green',
                                                    'animal': 'echidna'})
            expected_files = [MetaFile('green_echidna.txt', '/fake', {})]

            self.assertEqual(found_files, expected_files)
            mock_glob.assert_called_once_with()
    def test_alias_constraints(self):
        """ The PatternDataSet should be able to alias Constraints.

        This means when asked to get files for the aliased Constraint, it should
        return files from another Constraints.

        """

        with mock.patch('cwsl.core.pattern_dataset.PatternDataSet.glob_fs') as mock_glob:
            mock_glob.return_value = self.mock_file_list

            pattern_ds = PatternDataSet(self.mock_file_pattern)

            # Apply the constraint alias - when asked for hue,
            # it will give you colour.
            pattern_ds.alias_constraint("colour", "hue")

            found_files = pattern_ds.get_files({'hue': 'red',
                                                'animal': 'kangaroo'})

            self.assertEqual(1, len(found_files))
            self.assertEqual("/fake/red_kangaroo.txt",
                             found_files[0].full_path)
示例#4
0
    def test_getfiles(self):
        """ Ensure that files are correctly returned using 'get_files'. """

        with mock.patch('cwsl.core.pattern_dataset.PatternDataSet.glob_fs'
                        ) as mock_glob:

            # Add the mock fake glob function.
            mock_glob.return_value = self.mock_file_list

            test_patternds = PatternDataSet(self.mock_file_pattern)

            found_files = test_patternds.get_files({
                'colour': 'green',
                'animal': 'echidna'
            })
            expected_files = [
                MetaFile('green_echidna.txt', '/fake', {
                    'colour': 'green',
                    'animal': 'echidna'
                })
            ]

            self.assertItemsEqual(found_files, expected_files)
            mock_glob.assert_called_once_with()