Beispiel #1
0
    def setUp(self):
        """Set up local variables"""

        self.jsonl_file = os.path.join(os.path.dirname(__file__),
                                       'sample.jsonl')
        self.txt_file = io_utils.change_extension(self.jsonl_file, 'txt')
        self.copy_txt = io_utils.change_extension(self.jsonl_file, 'copy.txt')

        io_utils.check_file_readable(self.jsonl_file)
Beispiel #2
0
    def setUp(self):
        """Set up local variables"""

        self.arpa = os.path.join(os.path.dirname(__file__), 'sample-model.arpa')
        self.bin = io_utils.change_extension(self.arpa, 'bin')
        self.tmp = io_utils.change_extension(self.arpa, 'tmp.bin')

        io_utils.check_file_readable(self.arpa)
        io_utils.check_file_readable(self.bin)
Beispiel #3
0
    def setUp(self):
        """Set up local variables"""

        self.csv_file = os.path.join(os.path.dirname(__file__), 'sample.csv')
        self.jsonl_file = io_utils.change_extension(self.csv_file, 'jsonl')
        self.ft_model = '/usr/share/ccquery/models/fastText/lid.176.bin'

        io_utils.check_file_readable(self.csv_file)
        io_utils.check_file_readable(self.jsonl_file)
        io_utils.check_file_readable(self.ft_model)

        self.copy_csv = io_utils.change_extension(self.csv_file, 'copy.csv')
        self.copy_jsonl = io_utils.change_extension(self.csv_file,
                                                    'copy.jsonl')
    def test_bad_extension(self):
        """Test wrong file extension"""

        fn = io_utils.change_extension(self.jsonl, 'png')
        with self.assertRaises(Exception) as context:
            QueryAnalysis(fn, token='word', field='noisy')
        self.assertTrue('Unknown file extension' in str(context.exception))
Beispiel #5
0
    def setUp(self):
        """Set up local variables"""

        self.extractor = WikiExtraction()
        self.sample = os.path.join(os.path.dirname(__file__), 'sample.bz2')
        self.data = os.path.join(os.path.dirname(__file__),
                                 'sample-corpus.txt')
        self.vocab = os.path.join(os.path.dirname(__file__),
                                  'sample-vocab.txt')

        io_utils.check_file_readable(self.sample)
        io_utils.check_file_readable(self.data)
        io_utils.check_file_readable(self.vocab)

        # temporary files
        self.files = {
            'dld': os.path.join(os.path.dirname(__file__), 'dld.xml'),
            'xml': io_utils.change_extension(self.sample, 'xml'),
            'jsonl': io_utils.change_extension(self.sample, 'jsonl'),
            'txt': io_utils.change_extension(self.sample, 'txt'),
            'wvoc': io_utils.change_extension(self.sample, 'wvoc.txt'),
            'wplot': io_utils.change_extension(self.sample, 'wvoc.png'),
            'cvoc': io_utils.change_extension(self.sample, 'cvoc.txt'),
            'cplot': io_utils.change_extension(self.sample, 'cvoc.png'),
        }
Beispiel #6
0
    def test_file(self):
        self.assertEqual('__init__.py', io_utils.filename(self.empty_file))
        self.assertEqual('.py', io_utils.extension(self.empty_file))
        self.assertEqual('__init__', io_utils.basename(self.empty_file))
        self.assertEqual('/src/tests/utils',
                         io_utils.dirname('/src/tests/utils/__init__.py'))
        self.assertEqual(
            '/src/tests/utils/__init__',
            io_utils.path_without_ext('/src/tests/utils/__init__.py'))

        self.assertEqual('0.0Bytes', io_utils.filesize(self.empty_file))
        self.assertEqual('11.9KB', io_utils.filesize(self.archive))
        self.assertEqual(0, io_utils.count_lines(self.empty_file))

        self.assertTrue(io_utils.has_extension(self.empty_file, '.py'))
        self.assertFalse(io_utils.has_extension(self.empty_file, '.txt'))

        self.assertEqual(
            '/src/tests/utils/__init__.txt',
            io_utils.change_extension('/src/tests/utils/__init__.py', 'txt'))
        self.assertEqual('', io_utils.change_extension('', 'txt'))