Exemplo n.º 1
0
    def test_format_date_with_date(self):
        """Test format date with date."""

        processor = PDProcessor('path')
        sdate = dt.datetime(1970, 05, 06).date()
        data = processor.format_date(sdate)
        assert data == dt.datetime(1970, 05, 06).date()
Exemplo n.º 2
0
 def test_validate_path_with_invalid_path(self):
     sfile = 'invalid_path'
     processor = PDProcessor(sfile)
     try:
         processor.validate_path()
     except PDProcessorError as e:
         pass
     assert isinstance(e, PDProcessorError)
     assert e.message == "No file found at 'invalid_path'."
Exemplo n.º 3
0
    def test_init_data_map_with_data_map_none(self):
        """Ensure error occurs when data_map is None."""

        processor = PDProcessor('path')
        try:
            processor.init_data_map()
        except PDProcessorError as e:
            pass
        assert isinstance(e, PDProcessorError)
        assert e.message == "data_map is None."
Exemplo n.º 4
0
    def test_init_data_map_with_no_formatter(self):
        """Esnure error occurs when formatter is not defined."""

        processor = PDProcessor('path')
        processor.data_map = [
            ('final', 'initial', 'format_uppercase'),
            ('final', 'intial', 'no_formatter'),
        ]
        try:
            processor.init_data_map()
        except PDProcessorError as e:
            pass
        assert isinstance(e, PDProcessorError)
        assert e.message == "Formatter 'no_formatter' is not defined."
Exemplo n.º 5
0
 def test_init_data_map(self, data_map):
     sfile = 'test'
     processor = PDProcessor(sfile)
     processor.data_map = data_map
     processor.init_data_map()
     expected = [
         ('string', 'String', processor.format_uppercase),
         ('float', 'Float', processor._format_none),
         ('integer', 'Integer', processor._format_none),
         ('date', 'Date', processor.format_date),
     ]
     assert processor.data_map == expected
     expected = list(set(['String', 'Float', 'Integer', 'Date']))
     assert processor.source_cols == expected
     assert processor.final_cols == ['string', 'float', 'integer', 'date']
Exemplo n.º 6
0
    def test_validate_dateframe_corret2(self, dataframe):
        """Test validate dataframe when dataframe contains more that source_cols."""

        processor = PDProcessor('path')
        processor.source_cols = ['String', 'Float', 'Integer']
        processor.df = dataframe
        processor.validate_dataframe()
Exemplo n.º 7
0
    def test_format_dataframe(self, dataframe, data_map):
        """Test format_dataframe."""

        processor = PDProcessor('path')
        processor.data_map = data_map
        processor.init_data_map()
        processor.df = dataframe
        processor.format_dataframe()
        expected = set(['string', 'date', 'float', 'integer'])
        actual = set(processor.df.columns.tolist())
        assert actual == expected
        expected = ['STRING', 'STRING']
        assert processor.df['string'].tolist() == expected
        expected = [dt.datetime(1970, 05, 06).date(), dt.datetime(2017, 11, 18).date()]
        assert processor.df['date'].tolist() == expected
Exemplo n.º 8
0
    def test_validate_dataframe_incorrect(self, dataframe):
        """Test validate_dataframe with incorrect col in source_cols"""

        processor = PDProcessor('path')
        processor.source_cols = ['String', 'Float', 'Integer', 'Byte']
        processor.df = dataframe
        try:
            processor.validate_dataframe()
        except PDProcessorError as e:
            pass
        expected = "Expected column 'Byte' is not in the source file."
        assert e.message == expected
Exemplo n.º 9
0
    def test_process(self, dataframe, data_map):
        """Test process."""

        sfile = os.path.join(os.path.dirname(__file__), __file__)
        processor = PDProcessor(sfile)
        processor.data_map = data_map
        processor.df = dataframe
        processor.process()
        expected = set(['string', 'date', 'float', 'integer'])
        actual = set(processor.df.columns.tolist())
        assert actual == expected
        expected = ['STRING', 'STRING']
        assert processor.df['string'].tolist() == expected
        expected = [dt.datetime(1970, 05, 06).date(), dt.datetime(2017, 11, 18).date()]
        assert processor.df['date'].tolist() == expected
        expected = [1.47, 0]
        assert processor.df['float'].tolist() == expected
        expected = [1, 2]
        assert processor.df['integer'].tolist() == expected
Exemplo n.º 10
0
 def test_validate_path_with_valid_file(self):
     sfile = os.path.join(os.path.dirname(__file__), __file__)
     processor = PDProcessor(sfile)
     processor.validate_path()
Exemplo n.º 11
0
 def test__init__(self):
     sfile = os.path.join(os.path.dirname(__file__), __file__)
     processor = PDProcessor(sfile)
     assert processor.path == sfile
     assert processor.data_map == None
     assert processor.date_format == '%m/%d/%Y'
Exemplo n.º 12
0
    def test_format_date_with_string(self):
        """Test format_date with string."""

        processor = PDProcessor('path')
        data = processor.format_date('05/06/1970')
        assert data == dt.datetime(1970, 05, 06).date()
Exemplo n.º 13
0
    def test_format_none(self):
        """Test format none."""

        processor = PDProcessor('path')
        data = processor._format_none('string')
        assert data == 'string'
Exemplo n.º 14
0
    def test_format_uppercase(self):
        """Test format none."""

        processor = PDProcessor('path')
        data = processor.format_uppercase('string')
        assert data == 'STRING'
Exemplo n.º 15
0
 def test_validate_dataframe_correct(self, dataframe, data_map):
     processor = PDProcessor('path')
     processor.source_cols = ['String', 'Float', 'Integer', 'Date']
     processor.df = dataframe
     processor.validate_dataframe()